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
Favor request specs over controller specs when generating a controller #2222
Conversation
@@ -0,0 +1,10 @@ | |||
require 'rails_helper' | |||
|
|||
RSpec.describe "<%= class_name.pluralize %>", <%= type_metatag(:request) %> do |
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 mean, what does the rspec-rails team think should be the convention for request specs that test a controller
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:
describe "GET /<%= name.underscore.pluralize %>" do
it "works! (now write some real specs)" do
get "/<%= name.underscore.pluralize %>"
expect(response).to be_success
end
end
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 spec
require 'rails_helper'
RSpec.describe Admin::CustomersController, type: :controller do
end
So when the generator is generated without action names it should not have a test. Otherwise that test would not be green
31b3054
to
e322e49
Compare
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.
Not sure if you wanted feedback on a draft but this is a good start!
@@ -0,0 +1,10 @@ | |||
require 'rails_helper' | |||
|
|||
RSpec.describe "<%= class_name.pluralize %>", <%= type_metatag(:request) %> do |
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.
Up for discussion, should we omit generation of controller specs altogether? Brought up here. generators.test_framework :rspec, controller_specs: false |
No changing the default is sufficient |
5c0ce51
to
764de75
Compare
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.
- branch is rebased
- rails version checks are removed
- I tried to make the template similar to the controller spec templates
travis is also failing on the master branch. Do not understand why. I tried to use the method that the deprecation warning in the sanity check recommends (See klyonrad@cfcbd27) but this then breaks in another way
Therefore consider this not a draft anymore, when the sanity check thing is fixed, I will rebase and maybe squash the commits
@@ -0,0 +1,10 @@ | |||
require 'rails_helper' | |||
|
|||
RSpec.describe "<%= class_name.pluralize %>", <%= type_metatag(:request) %> do |
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 spec
require 'rails_helper'
RSpec.describe Admin::CustomersController, type: :controller do
end
So when the generator is generated without action names it should not have a test. Otherwise that test would not be green
For the issue on master branch. I will try to fix it with. #2231 |
349719a
to
5614581
Compare
Thanks for your patience here! |
…pecs Favor request specs over controller specs when generating a controller
Closes #2056
Open questions in my mind (and why I consider this a work in progress):
EDIT:
Regarding 2: Yes, they should
Regarding 1: I created a separate issue for this. See #2230