This is no longer true, and you can set the generator to create RSpec spec files when generating new parts of your rails application, as well as creating spec files for existing sections of the app.
The main feature lies in the application's generator configuration which is enabled when running the rspec-rails rspec:install task, but if you want to specify specific spec files to include/exclude, you may want this:
config/environments/development.rb // or any env you want
Rails.application.configure do
...
config.generators do |g|
g.test_framework :rspec
g.fixture_replacement :factory_bot
g.factory_bot dir: 'spec/factories'
g.controller_specs false
g.request_specs true
g.helper_specs false
g.feature_specs true
g.mailer_specs true
g.model_specs true
g.observer_specs false
g.routing_specs false
g.view_specs false
end
end
Generator Settings
The 'test_framework' option allows the rails to know exactly what test framework to create test files for, and generate new files based on your settings.
With the 'fixture_replacement', we can keep rails from generating fixtures by default, and instead create factories with each model created.
Lastly are the 'factory_bot' options, where you can change the factory folder default if needed, but will default to this directory on install. You can find more options in the Factory Girl/Bot Instructions.
Now when we generate something new, like a model:
> rails g model settings
invoke active_record
create db/migrate/20170915173537_create_settings.rb
create app/models/setting.rb
invoke rspec
create spec/models/setting_spec.rb
invoke factory_girl
create spec/factories/settings.rb
Generating Spec Files For Pre-Generated Sections of the App
Similar to generating rails files, you can generate spec files through Rspec's own task:
> rails g rspec:model old_settings
create spec/models/old_settings_spec.rb
invoke factory_girl
create spec/factories/old_settings.rb
This command uses the same conventions as the rails' generate command to create spec files, including scaffold, so you can create spec files for an entire namespace.