rspec_api_documentation icon indicating copy to clipboard operation
rspec_api_documentation copied to clipboard

undefined method `route' for RSpec::Core::Example when using callbacks

Open viamin opened this issue 5 years ago • 2 comments

I'm getting an undefined method exception when trying to generate docs for callbacks

  resource 'Webhook Callback' do
    let(:webhook) { Webhook.new(url: callback_url) }

    callback '/webhook' do
      let(:callback_url) { 'https://example.com/webhook' }
      let(:payload) do
        {
          name: name,
          email: email,
        }.as_json
      end

      trigger_callback do
        webhook.call(payload)
      end

      example 'Receiving a callback' do
        do_callback
        expect(request_method).to eq('POST')
        expect(request_headers['Content-Type']).to eq('application/json')
        expect(JSON.parse(request_body)).to eq(payload)
      end
    end
  end

The specs pass when I just run them as part of the full RSpec suite, but when I run them using rake docs:generate I get:

/Users/viamin/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rspec_api_documentation-6.1.0/lib/rspec_api_documentation/example.rb:14:in `method_missing': undefined method `route' for #<RSpec::Core::Example:0x00007fba4643a500> (NoMethodError)

I see in https://github.com/zipmark/rspec_api_documentation/issues/222 there's mention of needing a get/post block, but it's not clear if/how that's needed for callbacks. (The relish docs look more like my example above)

viamin avatar Feb 22 '20 02:02 viamin

So I fixed this by adding route: '<my callbackurl>', method: :post, and extended_parameters: {} to my failing example metadata.

viamin avatar Feb 24 '20 20:02 viamin

This creates invalid OpenAPI docs, since there's a missing response code. Not sure how that's expected to be set - expect(status).to eq(200) after a do_callback raises an error: undefined local variable or method 'status'

viamin avatar Feb 25 '20 01:02 viamin