Usage
You need to tell RuboCop to load the factory_bot extension. There are three ways to do this:
RuboCop configuration file
Put this into your .rubocop.yml
:
require: rubocop-factory_bot
or, if you are using several extensions:
require: - rubocop-factory_bot - rubocop-performance
Now you can run rubocop
and it will automatically load the RuboCop factory_bot
cops together with the standard cops.
Inspecting non-default file paths
By default, rubocop-factory_bot
only inspects code within below:
FactoryBot:
Include:
- "**/spec/factories.rb"
- "**/spec/factories/**/*.rb"
- "**/test/factories.rb"
- "**/test/factories/**/*.rb"
- "**/features/support/factories/**/*.rb"
You can override this setting in your config file by setting Include
:
# Inspect files in `my_factory/` directory
FactoryBot:
Include:
- '**/my_factory/**/*'
# Inspect only files ending with `_my_factory.rb`
FactoryBot:
Include:
- '**/*_my_factory.rb'
Please keep in mind that merge mode for Include is set to override the default settings, so if you intend to add a path while keeping the default paths, you should include the default Include paths in your configuration.
|