2
votes

In rails 4.2.0/ rspec 3.2.2/ rspec-rails 3.2.1. I'm trying to disable specs being generated when I generate new models. I'm using a spec folder structure that is different than the rails convention and would like to not have delete/move generated spec files for every new model. I tried to add generator configuration as mentioned in the rails guides and in What is the syntax to skip creating tests, assets & helpers when running `rails generate controller`?

My config/application.rb contains this:

config.generators do |g|
   g.test_framework :rspec
   g.model_specs false
   g.view_specs false
   g.helper_specs false
   g.controller_specs false
   g.model_spec false
   g.helper_specs false
   g.request_specs false
   g.feature_specs false
 end

and I'm still getting:

$rails g model category
  invoke  active_record
  create    db/migrate/20150416174523_create_categories.rb
  create    app/models/category.rb
  invoke    rspec
  create      spec/models/category_spec.rb
  invoke      factory_girl
  create        spec/factories/categories.rb

Even if I explicitly add tags:

 $rails g model category --no-model-specs
  invoke  active_record
  create    db/migrate/20150416174908_create_categories.rb
  create    app/models/category.rb
  invoke    rspec
  create      spec/models/category_spec.rb
  invoke      factory_girl
  create        spec/factories/categories.rb

Anyone solved this before?

1
try bin/rails g instead of just rails g - Mohammad AbuShady
Model specs are not optional, so if you set RSpec as the test framework, those files will show up. You'll need to entirely disable the generator (which it looks like you're trying to do already.) - fny
thanks. this at least removes some of the manual tedium - mmartinson

1 Answers

8
votes

Simply set test_framework to something falsey if you want to disable all generators:

config.generators do |g|
  g.test_framework nil
end

You sadly can't disable model specs from the generators alone. They're not optional.