Hello, I followed the Getting started section of the README and cannot get the documentation generated.
Steps I did prior to running the rake task:
rswag gem and ran bundle installrails g rswag:install command which generated initializers and a swagger_helper.rb file inside the spec folder.spec/integration/blogs_spec.rb file with some specsAfter running the rake task for swaggerize, I get the following:
/usr/local/bin/ruby -I/usr/local/bundle/gems/rspec-core-3.9.0/lib:/usr/local/bundle/gems/rspec-support-3.9.0/lib /usr/local/bundle/gems/rspec-core-3.9.0/exe/rspec --pattern spec/requests/\*\*/\*_spec.rb,\ spec/api/\*\*/\*_spec.rb,\ spec/integration/\*\*/\*_spec.rb --format Rswag::Specs::SwaggerFormatter --dry-run --order defined
No examples found.
Traceback (most recent call last):
16: from /usr/local/bundle/gems/rspec-core-3.9.0/exe/rspec:4:in `<main>'
15: from /usr/local/bundle/gems/rspec-core-3.9.0/lib/rspec/core/runner.rb:45:in `invoke'
14: from /usr/local/bundle/gems/rspec-core-3.9.0/lib/rspec/core/runner.rb:71:in `run'
13: from /usr/local/bundle/gems/rspec-core-3.9.0/lib/rspec/core/runner.rb:86:in `run'
12: from /usr/local/bundle/gems/rspec-core-3.9.0/lib/rspec/core/runner.rb:99:in `setup'
11: from /usr/local/bundle/gems/rspec-core-3.9.0/lib/rspec/core/runner.rb:132:in `configure'
10: from /usr/local/bundle/gems/rspec-core-3.9.0/lib/rspec/core/configuration_options.rb:24:in `configure'
9: from /usr/local/bundle/gems/rspec-core-3.9.0/lib/rspec/core/configuration_options.rb:118:in `load_formatters_into'
8: from /usr/local/bundle/gems/rspec-core-3.9.0/lib/rspec/core/configuration_options.rb:118:in `each'
7: from /usr/local/bundle/gems/rspec-core-3.9.0/lib/rspec/core/configuration_options.rb:118:in `block in load_formatters_into'
6: from /usr/local/bundle/gems/rspec-core-3.9.0/lib/rspec/core/configuration.rb:965:in `add_formatter'
5: from /usr/local/bundle/gems/rspec-core-3.9.0/lib/rspec/core/formatters.rb:151:in `add'
4: from /usr/local/bundle/gems/rspec-core-3.9.0/lib/rspec/core/formatters.rb:182:in `find_formatter'
3: from /usr/local/bundle/gems/rspec-core-3.9.0/lib/rspec/core/formatters.rb:232:in `custom_formatter'
2: from /usr/local/bundle/gems/rspec-core-3.9.0/lib/rspec/core/formatters.rb:232:in `inject'
1: from /usr/local/bundle/gems/rspec-core-3.9.0/lib/rspec/core/formatters.rb:232:in `each'
/usr/local/bundle/gems/rspec-core-3.9.0/lib/rspec/core/formatters.rb:232:in `block in custom_formatter': uninitialized constant Rswag (NameError)
19: from /usr/local/bundle/gems/rspec-core-3.9.0/exe/rspec:4:in `<main>'
18: from /usr/local/bundle/gems/rspec-core-3.9.0/lib/rspec/core/runner.rb:45:in `invoke'
17: from /usr/local/bundle/gems/rspec-core-3.9.0/lib/rspec/core/runner.rb:71:in `run'
16: from /usr/local/bundle/gems/rspec-core-3.9.0/lib/rspec/core/runner.rb:86:in `run'
15: from /usr/local/bundle/gems/rspec-core-3.9.0/lib/rspec/core/runner.rb:99:in `setup'
14: from /usr/local/bundle/gems/rspec-core-3.9.0/lib/rspec/core/runner.rb:132:in `configure'
13: from /usr/local/bundle/gems/rspec-core-3.9.0/lib/rspec/core/configuration_options.rb:24:in `configure'
12: from /usr/local/bundle/gems/rspec-core-3.9.0/lib/rspec/core/configuration_options.rb:118:in `load_formatters_into'
11: from /usr/local/bundle/gems/rspec-core-3.9.0/lib/rspec/core/configuration_options.rb:118:in `each'
10: from /usr/local/bundle/gems/rspec-core-3.9.0/lib/rspec/core/configuration_options.rb:118:in `block in load_formatters_into'
9: from /usr/local/bundle/gems/rspec-core-3.9.0/lib/rspec/core/configuration.rb:965:in `add_formatter'
8: from /usr/local/bundle/gems/rspec-core-3.9.0/lib/rspec/core/formatters.rb:151:in `add'
7: from /usr/local/bundle/gems/rspec-core-3.9.0/lib/rspec/core/formatters.rb:182:in `find_formatter'
6: from /usr/local/bundle/gems/rspec-core-3.9.0/lib/rspec/core/formatters.rb:231:in `custom_formatter'
5: from /usr/local/bundle/gems/rspec-core-3.9.0/lib/rspec/core/formatters.rb:234:in `rescue in custom_formatter'
4: from /usr/local/bundle/gems/rspec-core-3.9.0/lib/rspec/core/formatters.rb:234:in `require'
3: from /usr/local/bundle/gems/rswag-specs-2.2.0/lib/rswag/specs/swagger_formatter.rb:2:in `<top (required)>'
2: from /usr/local/bundle/gems/rswag-specs-2.2.0/lib/rswag/specs/swagger_formatter.rb:2:in `require'
1: from /var/www/docker/spec/swagger_helper.rb:1:in `<top (required)>'
/var/www/docker/spec/swagger_helper.rb:1:in `require': cannot load such file -- rails_helper (LoadError)
/usr/local/bin/ruby -I/usr/local/bundle/gems/rspec-core-3.9.0/lib:/usr/local/bundle/gems/rspec-support-3.9.0/lib /usr/local/bundle/gems/rspec-core-3.9.0/exe/rspec --pattern spec/requests/\*\*/\*_spec.rb,\ spec/api/\*\*/\*_spec.rb,\ spec/integration/\*\*/\*_spec.rb --format Rswag::Specs::SwaggerFormatter --dry-run --order defined failed
I noticed the spec_helper.rb file and rails_helper.rb file are included in the test-app of the project but not installed with the rswag command. Copying both files to the spec folder resulted in errors about uninitialized constants rswag and capybara.
Not sure if it'll fix your issue, but on my projects we usually keep the specs on spec/requests instead of integration
I have the same problem, but the error I get is uninitialized constant Rswag::Specs::SwaggerFormatter. Indeed, I have no Rswag::Specs module.
@jonsgold it seems like maybe your project is not importing rswag properly. If you're using rspec perhaps you should try including it into the .rspec file on the root of the project, like this:
--require spec_helper
--require rails_helper
--require swagger_helper
If that does not work, I'd suggest going over the steps again to make sure you didn't miss anything.
In case someone looks for it again and uses Docker or Docker Compose...
In my case I got the same error uninitialized constant Rswag (NameError) when I run swaggerize with Docker, using docker-compose service without test environment.
For example, if you use some service like:
services:
app: &app
...
environment:
RAILS_ENV: ${RAILS_ENV:-development}
...
test: &test
<<: *app
command: rspec
environment:
RAILS_ENV: test
Then you should run swaggerize with:
docker-compose run --rm test rake rswag:specs:swaggerize
not with:
docker-compose run --rm app rake rswag:specs:swaggerize
.
This can also happen if you've never created a test database for the project, which is possible when just beginning to install test gear like rspec or rswag.
$ rails db:test:prepare
Most helpful comment
@jonsgold it seems like maybe your project is not importing rswag properly. If you're using rspec perhaps you should try including it into the
.rspecfile on the root of the project, like this:If that does not work, I'd suggest going over the steps again to make sure you didn't miss anything.