projects, as an extension to RuboCop. Project Goals • Enforce the guidelines and best practices outlined in the community RSpec style guide • Simplify the process of adopting new RSpec functionality
FactoryBot. # .rubocop.yml RSpec: Enabled: false RSpec/FactoryBot: Enabled: true 🤔 Should rubocop-rspec really be included in the Gem fi le for a project that is not using RSpec?
just like RuboCop, so breaking changes cannot be introduced until the next major version update. Performing the extraction all at once in the next major version update carries high risk ⚠ 👉 So we decided to proceed steadily, step by step, while maintaining backward compatibility.
module FactoryBot # @!parse # # Use string value when setting the class attribute explicitly. # # # # @example # # # bad # # factory :foo, class: Foo do # # end # # # # # good # # factory :foo, class: 'Foo' do # # end # # # class FactoryClassName < :: RuboCop :: Cop :: Base; end FactoryClassName = :: RuboCop :: Cop :: FactoryBot : : FactoryClassName end : 3. Create local copies of these cops
guration settings for the old cop name of rubocop- rspec # conf i g/default.yml RSpec/FactoryBot/AttributeDef i nedStatically: Description: Always declare attribute values as blocks. Enabled: true Include: - spec/factories.rb - spec/factories/**/*.rb - features/support/factories/**/*.rb VersionAdded: '1.28' VersionChanged: '2.0'
warn users about the new cop's name ❯ bundle exec rubocop -A .rubocop.yml: RSpec/Capybara/MatchStyle has the wrong namespace - should be Capybara .rubocop.yml: RSpec/FactoryBot/ConsistentParenthesesStyle has the wrong namespace - should be FactoryBot Inspecting 274 f i les ........................................................................ ........................................................................ ........................................................................ .......................................................... 274 f i les inspected, no offenses detected
from RuboCop RSpec, there may be cops that do not work properly with test frameworks other than RSpec ⚠ We have not yet been able to address. So, we welcome any contributions :-)