factory_bot-specific analysis for your projects, as an extension to RuboCop.
Just install the rubocop-factory_bot gem
gem install rubocop-factory_botor if you use bundler put this in your Gemfile
gem 'rubocop-factory_bot', require: falseYou need to tell RuboCop to load the factory_bot extension. There are three ways to do this:
Put this into your .rubocop.yml.
plugins: rubocop-factory_botAlternatively, use the following array notation when specifying multiple extensions.
plugins:
- rubocop-other-extension
- rubocop-factory_botNow you can run rubocop and it will automatically load the RuboCop factory_bot
cops together with the standard cops.
Note
The plugin system is supported in RuboCop 1.72+. In earlier versions, use require instead of plugins.
rubocop --plugin rubocop-factory_botRuboCop::RakeTask.new do |task|
task.plugins << 'rubocop-factory_bot'
endYou can read more about RuboCop factory_bot in its official manual.
All cops are located under
lib/rubocop/cop/factory_bot, and contain
examples/documentation.
In your .rubocop.yml, you may treat the factory_bot cops just like any other
cop. For example:
FactoryBot/AttributeDefinedStatically:
Exclude:
- spec/factories/my_factory.rbCheckout the contribution guidelines.
rubocop-factory_bot is MIT licensed. See the accompanying file for
the full text.