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

Consistent request spec naming #2378

Merged
merged 3 commits into from Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions Changelog.md
Expand Up @@ -5,6 +5,8 @@ Enhancements:

* Issue a warning when using job matchers with `#at` mis-match on `usec` precision.
(Jon Rowe, #2350)
* Generated request specs now have a bare `_spec` suffix instead of `request_spec`.
(Eloy Espinaco, Luka Lüdicke, #2355, #2356, #2378)

Bug Fixes:

Expand Down
5 changes: 4 additions & 1 deletion example_app_generator/generate_stuff.rb
Expand Up @@ -85,7 +85,10 @@ def using_source_path(path)
generate('rspec:install')
generate('controller wombats index') # plural
generate('controller welcome index') # singular
generate('rspec:request wombats')

# request specs are now the default
generate('rspec:controller wombats --no-request-specs --controller-specs --no-view-specs')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Funny, I didn't know that about this generator. But to be honest I don't understand the purpose of this line 🤔

One more testing of controller specs? I thought the whole issue was about request specs

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rspec: bit means just the rspec generator, not the rails generator, so its the same as invoking controller wombats ... only it does't produce a controller.

One more testing of controller specs? I thought the whole issue was about request specs

This is fixing an issue the rename raised, this lines original purpose was to complete the coverage of the generators.

At the time the lines above generated controller specs for wombats, so we added a request spec to complete the mix. When the default became request specs this should have changed to a controller spec to restore the coverage.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the rename showed a duplicate spec being generated, which resolving the original coverage issue solves.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, now I see what you were reading into those lines... I was interpreting them in a very different way.

I thought that

generate('rspec:request wombats')
generate('integration_test widgets')

were just for testing the RequestSpecGenerator or to have test coverage of request specs in general.


The rspec: bit means just the rspec generator, not the rails generator, so its the same as invoking controller wombats ... only it does't produce a controller.

But couldn't this be also achieved (and be more explicit) by changing line 87 to generate('controller wombats index --controller-specs')?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yep I guess that'd also work


generate('integration_test widgets')
generate('mailer Notifications signup')

Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rspec/controller/controller_generator.rb
Expand Up @@ -16,7 +16,7 @@ def generate_request_spec
return unless options[:request_specs]

template 'request_spec.rb',
File.join('spec/requests', class_path, "#{file_name}_request_spec.rb")
File.join('spec/requests', class_path, "#{file_name}_spec.rb")
end

def generate_controller_spec
Expand Down
4 changes: 2 additions & 2 deletions spec/generators/rspec/controller/controller_generator_spec.rb
Expand Up @@ -6,7 +6,7 @@
setup_default_destination

describe 'request specs' do
subject { file('spec/requests/posts_request_spec.rb') }
subject { file('spec/requests/posts_spec.rb') }

describe 'generated by default' do
before do
Expand Down Expand Up @@ -38,7 +38,7 @@
end

describe 'with namespace and actions' do
subject { file('spec/requests/admin/external/users_request_spec.rb') }
subject { file('spec/requests/admin/external/users_spec.rb') }

before do
run_generator %w[admin::external::users index custom_action]
Expand Down