Copying the example blog spec from the readme and installing with Ruby 2.4.1, RSpec 3.6.0 and RSwag 1.3.0 gives me the following error...
$ rake rswag:specs:swaggerize
/Users/nick/.rbenv/versions/2.4.1/bin/ruby -I/Users/nick/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rspec-core-3.6.0/lib:/Users/nick/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rspec-support-3.6.0/lib /Users/nick/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rspec-core-3.6.0/exe/rspec --pattern spec/requests/\*\*/\*_spec.rb,\ spec/api/\*\*/\*_spec.rb,\ spec/integration/\*\*/\*_spec.rb --format Rswag::Specs::SwaggerFormatter --dry-run --order defined
Generating Swagger docs ...
An error occurred while loading ./spec/integration/metadata_api_spec.rb.
Failure/Error:
path '/blogs' do
post 'Creates a blog' do
tags 'Blogs'
consumes 'application/json', 'application/xml'
parameter name: :blog, in: :body, schema: {
type: :object,
properties: {
title: { type: :string },
content: { type: :string }
NoMethodError:
undefined method `path' for RSpec::ExampleGroups::BlogsAPI:Class
# ./spec/integration/metadata_api_spec.rb:5:in `block in <top (required)>'
# ./spec/integration/metadata_api_spec.rb:3:in `<top (required)>'
Swagger doc generated at /Users/nick/Documents/.../swagger.json
The custom methods from RSwag don't seem to be present in my spec's context, even though require 'swagger_helper' is present and the file has been generated.
Our rails_helper has some custom RSpec includes, but nothing which should exclude RSwag...
RSpec.configure do |config|
config.include ....
Anyone seen this behaviour before? Thanks!
As far as I can tell, this is because we have...
RSpec.configure do |config|
# Limits the available syntax to the non-monkey patched syntax that is
# recommended. For more details, see:
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
config.disable_monkey_patching!
end
In our spec_helper.rb as per the recommended rspec-rails starting config.
I seen similar issue, it was resolved with flag type: :request (https://github.com/domaindrivendev/rswag/blob/master/test-app/spec/integration/blogs_spec.rb).
Hmm, adding type: :request makes rake rswag:specs:swaggerize run through (rather than stacktracing as before), but the specific test is missing from the generated .json file. It only shows up with config.disable_monkey_patching! commented out.
Could this ticket be re-opened?
With rspec 3.9.1, rswag 2.3.1, and ruby 2.7.1, integration tests fail with this same error (undefined method 'path') unless type: :request is present in the RSpec.describe call. This is happening either specifying OpenApi 3.0.1 or Swagger 2.0 as the output in swagger_helper.rb.
As @mcoms reported almost three years ago, these tests are ignored by the swaggerize rake task - in my case, I get 'No examples found'. However, I already do not have config.disable_monkey_patching! and there does not seem to be an enable_monkey_patching! config setting.
Did anyone ever figure out why this is happening? In another project I have running ruby 2.7.0 with rspec 3.9.1 and rswag 2.3.1, swaggerize is working fine without any need for the type: :request definition. The rails_helper and spec_helper files seem almost identically configured apart from some app-specific content.
Most helpful comment
I seen similar issue, it was resolved with flag
type: :request(https://github.com/domaindrivendev/rswag/blob/master/test-app/spec/integration/blogs_spec.rb).