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

Generate request spec by default when generating controller #2056

Closed
bekicot opened this issue Dec 26, 2018 · 9 comments · Fixed by #2222
Closed

Generate request spec by default when generating controller #2056

bekicot opened this issue Dec 26, 2018 · 9 comments · Fixed by #2222

Comments

@bekicot
Copy link

bekicot commented Dec 26, 2018

What Ruby, Rails and RSpec versions are you using?

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

Observed behavior

When generating Rails controller, it will automatically generate corresponding controller spec.

Expected behavior

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?

@benoittgt
Copy link
Member

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.

@JonRowe
Copy link
Member

JonRowe commented Dec 30, 2018

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

@fables-tales
Copy link
Member

fables-tales commented Dec 30, 2018 via email

@klyonrad
Copy link
Contributor

klyonrad commented Dec 5, 2019

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 😉

@JonRowe
Copy link
Member

JonRowe commented Dec 5, 2019

Well given that the next version is a major version, if someone wanted to tackle the default switch over now would be the time.

@JonRowe
Copy link
Member

JonRowe commented Dec 5, 2019

I don't myself have time to do it, but if either of you @klyonrad or @bekicot, wanted to tackle it please do.

@klyonrad
Copy link
Contributor

klyonrad commented Dec 7, 2019

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.

@uzrnem
Copy link

uzrnem commented Apr 16, 2020

try this command
rails generate rspec:controller login --controller-specs
For more option use command
rails generate rspec:controller

@ilukashin
Copy link

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

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

Successfully merging a pull request may close this issue.

7 participants