Is there a way to do this from the application.rb?
edit: short answer on top
If you want to do this for every time you run the generators, you do indeed customize it within your application.rb file. Put this code in the file inside the Application class definition.
config.generators do |g|
g.view_specs false
g.helper_specs false
end
You can also accomplish this by passing some options into the generator command. This Railscast goes over the process in more detail, but the basic idea is pretty simple.
Rails generators can take several options. You can see the options for the controller generator by running rails g controller -h
. Assuming you have Rspec set up already, if you look at the output, you notice a section that says "Rspec options". It looks like this:
Rspec options:
[--controller-specs] # Indicates when to generate controller specs
# Default: true
[--view-specs] # Indicates when to generate view specs
# Default: true
To negate these boolean values, just pass them in with a "no" in front of the name. So if you wanted a controller with no specs for your view, you would call it like this:
rails g controller Foobar index show new create --no-view-specs
And you would get a controller with the correct views and actions created for you, but no specs for your views.
The same thing applies if you are using the scaffold
generator. There is a --helper-specs
option, so if you wanted no view or helper specs you would run:
rails g scaffold Foobar name:string --no-helper-specs --no-view-specs