Ruby version: 2.7.0preview1
Rails version: 6.0.1
RSpec version: 3.9
First...
$ rails new foo
# add rspec-rails to Gemfile
$ bundle
$ rails g rspec:install
then...
$ rails g scaffold posts
...
invoke test_unit
create test/controllers/posts_controller_test.rb
create test/system/posts_test.rb
...
$ rails g scaffold posts
...
invoke rspec
create spec/controllers/messages_controller_spec.rb
create spec/views/messages/edit.html.erb_spec.rb
create spec/views/messages/index.html.erb_spec.rb
create spec/views/messages/new.html.erb_spec.rb
create spec/views/messages/show.html.erb_spec.rb
create spec/routing/messages_routing_spec.rb
...
Obviously this is achieved by adding the following line to the Rails application config:
config.generators.test_framework :rspec
but I am curious鈥攄oes the RSpec team consider this too much hand-holding? In my opinion, if it's not going to be provided automatically by the rspec:install generator, then it should at least be in the README.
I believe it's here.
Can you reproduce this with rspec-rails version 4.0.0.beta3?
Wow, that was fast!
It appears that in order to take advantage of this, I need to require 'rspec-rails' in /config/application.rb. Is this the correct approach? Is there another way to do it?
As far as I remember, putting this in Gemfile is sufficient:
group :development, :test do
gem 'rspec-rails', '~> 4.0' # in case of pre-release '4.0.0.beta3'
end
My goodness, you're right. I think when I tried it yesterday, maybe I hadn't run spring stop, so the generators were running based on the outdated application config? Thanks again for your insight.
Okay, one thing I just noticed is that the default generators still create controller specs, even though they are discouraged as of RSpec 3.5.
I ended up adding the following line to my config/application.rb:
generators.test_framework :rspec, controller_specs: false
Is this something that is worthy of fixing? Is a fix already planned for it? I can think of two ways:
rspec-rails.rb file you linked above to use this line instead.Good point. This is something that聽https://github.com/rspec/rspec-rails/pull/2222 is about to address.
Most helpful comment
My goodness, you're right. I think when I tried it yesterday, maybe I hadn't run
spring stop, so the generators were running based on the outdated application config? Thanks again for your insight.