Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
viamin opened this issue Feb 22, 2020 · 2 comments
Open

Comments

@viamin
Copy link

viamin commented Feb 22, 2020

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 #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
Copy link
Author

viamin commented Feb 24, 2020

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

@viamin
Copy link
Author

viamin commented Feb 25, 2020

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'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant