-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Generate request specs when scaffold generator is used #2262
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
Conversation
With shallow empty file. Will be filled in later commits with content
5d0249b
to
df467bd
Compare
df467bd
to
353967d
Compare
# sticking to rails and rspec-rails APIs to keep things simple and stable. | ||
|
||
<% module_namespacing do -%> | ||
RSpec.describe <%= controller_class_name %>Controller, <%= 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.
@JonRowe In an older PR comment You disliked using the word controller in the description title, is that still the case?
Because I would tend to disagree. The specs are describing that specified controller. What else should it be named?
It could also help editor features like "jump to test file", although I didn't see it working in RubyMine (yet)
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.
Request specs don't test controllers, they test specific requests. They route to a certain path and something happens, it could be the controller you intend, it might not. It could be terminated in a rack middleware, it could be routed to a different controller.
Ping, how are you getting on with this? |
Still have in this in the back on my mind, but didn't have time for it this week |
14bf90f
to
bd018e3
Compare
To make it more consistent
Running rake spec::controllers is removed from smoke tests because they are not generated anymore by default
bd018e3
to
611ff9b
Compare
@JonRowe Tests should be green now, the API request spec template is still missing but please have a look already, since I will copy a lot from the current template from the draft now |
# Remove skips so we can test controller specs work | ||
gsub_file 'spec/controllers/gadgets_controller_spec.rb', | ||
# Remove skips so we can test that request specs work | ||
gsub_file 'spec/requests/gadgets_request_spec.rb', |
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.
Could you explain why we have to change that?
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 file that was attempted to edit does not exist anymore. That's what I meant with my question in the PR body about Integration / smoke test coverage
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 need to ensure that the smoke coverage covers both scenarios.
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.
Done.
Also added generation with using the --api
flag
@@ -7,7 +7,6 @@ | |||
run('bin/rake --backtrace spec:requests') || abort | |||
run('bin/rake --backtrace spec:models') || abort | |||
run('bin/rake --backtrace spec:views') || abort | |||
run('bin/rake --backtrace spec:controllers') || abort |
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.
Could you explain why we have to change that?
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 suspected that the smoke app does not generate controller specs anymore because the default of the ScaffoldGenerator changed
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.
Rather than removing these, you need to add a command to generate some controller tests for this to run.
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.
Done.
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.
answering the questions
@@ -7,7 +7,6 @@ | |||
run('bin/rake --backtrace spec:requests') || abort | |||
run('bin/rake --backtrace spec:models') || abort | |||
run('bin/rake --backtrace spec:views') || abort | |||
run('bin/rake --backtrace spec:controllers') || abort |
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.
Rather than removing these, you need to add a command to generate some controller tests for this to run.
# Remove skips so we can test controller specs work | ||
gsub_file 'spec/controllers/gadgets_controller_spec.rb', | ||
# Remove skips so we can test that request specs work | ||
gsub_file 'spec/requests/gadgets_request_spec.rb', |
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 need to ensure that the smoke coverage covers both scenarios.
Exclude: | ||
# Splitting the Generator classes would make matters more confusing | ||
# than them being too big | ||
- lib/generators/rspec/**/* |
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.
Add the relevant magic comment to the generator that fails rather than doing this, or add the specific files, its possible to extract things without class splitting.
Executing fails though because there is request spec generated that tries requesting html format
Fixes the problem that ScaffoldsGenerator creates the separate request specs through the IntegrationGenerator class. Naming of example resources in generate_stuff task is changed because I suspect that using the integration generator before scaffolding (with the same name) produced the following error ``` NameError: undefined local variable or method `widgets_index_path' for #<RSpec::ExampleGroups::Widgets::GETWidgets:0x00007f881832e338> # ./spec/requests/widgets_spec.rb:6:in `block (3 levels) in <top (required)>' ``` Since this kind of usage does not make sense anyway I changed the used scaffolding name to product
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.
Cannot get the test suite to green 😿
# Remove skips so we can test controller specs work | ||
gsub_file 'spec/controllers/gadgets_controller_spec.rb', | ||
# Remove skips so we can test that request specs work | ||
gsub_file 'spec/requests/gadgets_request_spec.rb', |
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.
Done.
Also added generation with using the --api
flag
@@ -7,7 +7,6 @@ | |||
run('bin/rake --backtrace spec:requests') || abort | |||
run('bin/rake --backtrace spec:models') || abort | |||
run('bin/rake --backtrace spec:views') || abort | |||
run('bin/rake --backtrace spec:controllers') || abort |
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.
Done.
@@ -89,10 +89,12 @@ def using_source_path(path) | |||
|
|||
generate('model thing name:string') | |||
generate('helper things') | |||
generate('scaffold widget name:string category:string instock:boolean foo_id:integer bar_id:integer --force') | |||
generate('scaffold product name:string category:string instock:boolean foo_id:integer bar_id:integer --force') |
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.
At this point the project stops being fun 😠
Apparently there other tests assumed that the Widget
constant is created and I cannot figure how to make the testing of IntegrationGenerator and RequestGenerator work, sometimes the <%= index_helper %>_path
works, sometimes or the _url
helper.
I still think that generated request specs is important and very useful but for working on this as a lone wolf I am out. So please help, take over oder schedule chatting/pair programming (personally; I am more available in February).
Log of the smoke tests:
Failures:
1) Using rspec-mocks with models supports stubbing attribute methods on models
Failure/Error: a_widget = Widget.new
NameError:
uninitialized constant Widget
# ./spec/features/model_mocks_integration_spec.rb:10:in `block (2 levels) in <top (required)>'
2) Using rspec-mocks with models supports stubbing class methods on models
Failure/Error: allow(Widget).to receive(:all).and_return(:any_stub)
NameError:
uninitialized constant Widget
# ./spec/features/model_mocks_integration_spec.rb:5:in `block (2 levels) in <top (required)>'
3) Widgets GET /widgets works! (now write some real specs)
Failure/Error: get widgets_index_path
NameError:
undefined local variable or method `widgets_index_path' for #<RSpec::ExampleGroups::Widgets::GETWidgets:0x00007ff1f27043d8>
# ./spec/requests/widgets_spec.rb:6:in `block (3 levels) in <top (required)>'
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.
Have you had a chance to take another look? I can lend a hand.
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, I'll write you an email to chat up or something
@@ -60,8 +78,6 @@ def generate_routing_spec | |||
template 'routing_spec.rb', template_file | |||
end | |||
|
|||
hook_for :integration_tool, as: :integration |
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.
(Check also my commit message on this change)
I had to dig extremely dig into the git history of the project, tried to figure the purpose and the consequences of this setting (the generator from railties
does not have this). But I don't understand it. But is the thing that causes the IntegrationGenerator
to run and also generate a request_spec
file (figured that out through debugging and lookig at the backtrace).
Changing this seems to cause something, at least that's what the test suite is telling me
See also 98b886b
Closes #2230
Ouf, this is quite some work... 😁
TODO
show
and/edit
action--api
flagOpen questions
Integration / smoke test coverage
As far as I understand the smoke tests were testing the controller specs because they were generated by default. So making them not the default reduces the test coverage a bit. Should we take a go at explicitly generating the controller specs in the smoke app too?
Title of the generated request spec
Top title of the generated specs is debatable (See also Comment)
References
Valid_session
The controller specs generated a
:valid_session
method. I don't know what the equivalent for request specs should be called. The same thing?valid_headers
Should I take a go at fixing the issue from #2043 for scaffolding?
Naming of the describe blocks
The controller scaffold specs were grouped with
PATCH #update
etc. The current draft hasPATCH /update
. This does not fit so well for request specs anymore. Method documentation style#update
does not fit because we use actual urls and don't call methods,/update
does not fit because that is not really the URL.We could write
PATCH /index_url
andGET /resource_name/:id
. This fits as long as users stick to the simple rails conventionsAppendix
TODO
Normal
Namespaced
With api flag