Slide 1

Slide 1 text

Dividing and Managing: The Cops Squad of RuboCop RSpec Dept. Yudai Takada RubyKaigi 2023 2023.05.11 (Thu)

Slide 2

Slide 2 text

ɾ Name: Yudai Takada ɾ GitHub: @ydah ɾ Twitter: @ydah_ ɾ Member of RuboCop RSpec core team ɾ Software Engineer at ANDPAD, Inc. self.inspect

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

What is RuboCop RSpec? RSpec-speci fi c analysis for your 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

Slide 5

Slide 5 text

Why do we extract it as a gem?

Slide 6

Slide 6 text

RSpec RSpec/FactoryBot RSpec/Rails RSpec/Capybara Department of RuboCop RSpec

Slide 7

Slide 7 text

“Code style checking for RSpec files” “RSpec-specific analysis for your projects”

Slide 8

Slide 8 text

RSpec RSpec/FactoryBot RSpec/Rails RSpec/Capybara Department of RuboCop RSpec

Slide 9

Slide 9 text

Motivation for splitting gems Capybara and factory_bot cops are not limited to RSpec and can also be used with other test frameworks. For example: • Test::Unit • Cucumber • Minitest • Minitest::Spec

Slide 10

Slide 10 text

If you are not using RSpec but you are using 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?

Slide 11

Slide 11 text

rubocop-rspec#1523 RSpec/FactoryBot/FactoryNameStyle false positive on rails generators

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

Points to note when extracting to a gem

Slide 14

Slide 14 text

Points to note when proceeding RuboCop RSpec follows semantic versioning, 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.

Slide 15

Slide 15 text

How did we extract them into gems?

Slide 16

Slide 16 text

The steps to extract rubocop-rspec rubocop- capybara rubocop- factory_bot 1. Extract cops from each department for rubocop-capybara and rubocop- factory_bot RSpec/ Capybara RSpec/ FactoryBot

Slide 17

Slide 17 text

The steps to extract 2. Add dependency on the extracted gem to rubocop-rspec # rubocop - rspec/lib/rubocop - rspec.rb : 6 require 'rubocop' 7 require 'rubocop - capybara' 8 require 'rubocop - factory_bot'

Slide 18

Slide 18 text

The steps to extract module RuboCop module Cop module RSpec 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

Slide 19

Slide 19 text

The steps to extract 4. Keep the default con fi 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'

Slide 20

Slide 20 text

The steps to extract 5. Add a deprecation setting to 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

Slide 21

Slide 21 text

Release plan v2.x rubocop-rspec rubocop- capybara rubocop- factory_bot v2.18.0 v2.22.0 Dependent on each gem.

Slide 22

Slide 22 text

Release plan v3.x rubocop-rspec rubocop- capybara rubocop- factory_bot Remove these dependencies and notify to install and con fi gure them separately.

Slide 23

Slide 23 text

Regarding the outstanding issues

Slide 24

Slide 24 text

Regarding the outstanding issues Since we only extracted the department 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 :-)

Slide 25

Slide 25 text

end