Skip to content
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

rails g rspec:install doesn't add config.generators.test_framework setting #2220

Closed
rlue opened this issue Dec 5, 2019 · 6 comments
Closed

Comments

@rlue
Copy link
Contributor

rlue commented Dec 5, 2019

What Ruby, Rails and RSpec versions are you using?

Ruby version: 2.7.0preview1
Rails version: 6.0.1
RSpec version: 3.9

Observed behaviour

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
      ...

Expected behaviour

$ 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—does 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.

@pirj
Copy link
Member

pirj commented Dec 5, 2019

I believe it's here.

Can you reproduce this with rspec-rails version 4.0.0.beta3?

@rlue
Copy link
Contributor Author

rlue commented Dec 5, 2019

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?

@rlue rlue closed this as completed Dec 5, 2019
@pirj
Copy link
Member

pirj commented Dec 5, 2019

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

@rlue
Copy link
Contributor Author

rlue commented Dec 6, 2019

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.

@rlue
Copy link
Contributor Author

rlue commented Dec 8, 2019

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:

  1. disable controller specs from the generator by default; or
  2. modify the rspec-rails.rb file you linked above to use this line instead.

@pirj
Copy link
Member

pirj commented Dec 8, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants