Ruby version: 2.4.1
Rails version: 5.2.2
Rspec version: 3.8
- rspec-core 3.8.0
- rspec-expectations 3.8.2
- rspec-mocks 3.8.0
- rspec-rails 3.8.1
- rspec-support 3.8.0
When generating Rails controller, it will automatically generate corresponding controller spec.
Generate corresponding request spec.
The official recommendation of the Rails team and the RSpec core team is to write request specs instead.
Is it possible for the user to configure RSpec-rails so that it generates request spec by default when generating controller test?
Hello @bekicot and thanks for your request.
It seems to me to be a big shift that needs to be addressed in a major release if we do it even if I think it's a good idea.
I will follow @JonRowe or @samphippen choice to change this behavior.
I'd support a PR that made the behaviour configurable, and changed the default the behaviour of the generator for Rails 5.1, (maybe 5) but older Rails expect controller specs
I think the right thing to do here is to add a configuration option, have
it enabled in new rails helpers on rails greater or equal to 4.2 (which had
request specs), and then turn it on by default for everyone in RSpec rails
4.
And/Or a command line option - which also provides the possibility to generate a feature spec
A project might have decided to write request specs only for API controllers and feature specs for the controllers with views and user facing functionality.
But generally it is not nice that the generated stuff contradicts official recommendations - just leads to discussions everywhere 馃槈
Well given that the next version is a major version, if someone wanted to tackle the default switch over now would be the time.
I don't myself have time to do it, but if either of you @klyonrad or @bekicot, wanted to tackle it please do.
I actually didn't want to nag, just chiming about the idea of file configuration. So sorry for the wording.
Anyway, I got motivated a bit, but have to stop for now because I can't seem to get the configurability to work, at least according to my tests. For the case If I don't get back to it here is my branch: https://github.com/klyonrad/rspec-rails/commits/controller-default-generated-specs
I also started thinking about the scaffolding generators and the suggested cotent for the templates, but well these are maybe different topics.
try this command
rails generate rspec:controller login --controller-specs
For more option use command
rails generate rspec:controller
Hello everyone.
also possible solution to override default settings for rspec options.
in config/application.rb
class Application < Rails::Application
config.generators do |g|
g.test_framework :rspec,
request_specs: false,
view_specs: false,
routing_specs: false,
helper_specs: false,
controller_specs: true
end
end
works for me in rails 6
Most helpful comment
I think the right thing to do here is to add a configuration option, have
it enabled in new rails helpers on rails greater or equal to 4.2 (which had
request specs), and then turn it on by default for everyone in RSpec rails
4.