-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Consistent request spec naming #2356
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,10 @@ | |
|
||
RSpec.describe Rspec::Generators::ControllerGenerator, type: :generator do | ||
setup_default_destination | ||
it_behaves_like "a request spec generator" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am a bit unsure about including this here. What was the goal of it? Because a couple of tests in that shared example are already in It appears to me that originally purpose of the example sharing was that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I see the other discussion now.... Not to crush your spirit here, but may I suggest to split the two behaviour changes (file naming & content of ControllerGenerator? The ControllerGenerator and the Request/Integration Generator are not the same thing. ControllerGenerator executes also the rails generators, while the RequestGenerator only generates the test files (for example to test already existing untested controllers in a codebase) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
My idea here is not make them the same thing, but enforce them to behave as a "request generator". That way, given a certain configuration we can expect them to generate the same request specs.
In the case of the controller generator, there is no inheritance, but they share the same template file. I prefer to use the shared example instead of repeat test, because I like the idea of make sure that this compatibility is maintained in new versions, so the file naming convention becomes a specification for requests generators. |
||
|
||
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 | ||
|
@@ -38,7 +39,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] | ||
|
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.
You've renamed the file so where does the alternate come from? Any differences are also untested which I'd like to see rectified!
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.
The alternate template comes from the integration generator (added on the source_paths on line 7).
It is reusing functionality of requests generator (and integration generator) because it is just re-using the template, but it is actually being tested on the shared example.
Testing with that shared example we make sure that generators that generate request specs does use a consistent format (they all pass the same specs) while differences between specs are being also being tested.
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.
Maybe generate
posts
with a scaffold, and generatebooks
with controller generator?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.
You haven't added a test for the different behaviour, and there is different behaviour now.
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.
@JonRowe I did add a shared example that it's testing just that new behavior. You can check that removing that code and specs will fail with meaningful errors.
The specs for that code are in this support file. I'm just adding one line of test because I'm reusing existing specs.
Does it makes sense?
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.
@JonRowe Runing the tests without the implementation changes gives those rspec failures.