-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Favor request specs over controller specs when generating a controller #2222
Merged
JonRowe
merged 4 commits into
rspec:master
from
klyonrad:controller-default-generated-specs
Dec 20, 2019
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7b337f4
Favor request specs over controller specs for rails g controller
klyonrad b9203c8
Make content of automatic request spec almost empty
klyonrad 8107697
Remove rails version checks for controller generator
klyonrad 5614581
Generate request specs for the provided actions
klyonrad File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe "<%= class_name.pluralize %>", <%= type_metatag(:request) %> do | ||
<% namespaced_path = regular_class_path.join('/') %> | ||
<% for action in actions -%> | ||
describe "GET /<%= action %>" do | ||
it "returns http success" do | ||
get "<%= "/#{namespaced_path}" if namespaced_path != '' %>/<%= file_name %>/<%= action %>" | ||
expect(response).to have_http_status(:success) | ||
end | ||
end | ||
|
||
<% end -%> | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copied over from
lib/generators/rspec/integration/templates/request_spec.rb
I didn't try "very hard" to use the same template file because I am not sure if that is even wished for
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend writing a spec for get name etc that returns success or something similarly basic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, figuring the details for the templates out was/is a bit difficult for me. I am sure, I would figure it out - but can you clarify the specs a bit maybe? I mean, what does the rspec-rails team think should be the convention for request specs that test a controller
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the request spec guide help you? https://relishapp.com/rspec/rspec-rails/docs/request-specs/request-spec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't use generators myself as I find that the similar lines tend to just be the naming only. There isn't that much of a semantic difference between a controller spec and a request spec, its the level of stack integration that differs. Personally I would be happy with:
However finesse wise I think that
name.underscore.pluralize
is wrong here, because it needs to be name spaced (or not) appropriately.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know if you want any more feedback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went with doing the same thing like the existing controller spec templates
If I understand the rails controller generator code correctly
it does note generate any routes unless we gave actions as a parameter. So the
lib/generators/rspec/controller/templates/controller_spec.rb
template makes a very empty controller specSo when the generator is generated without action names it should not have a test. Otherwise that test would not be green