Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Extracting from rubocop-rspec

ydah
March 13, 2024

Extracting from rubocop-rspec

Kyobashi.rb Offline #2 『Extracting from rubocop-rspec』のスライド
https://kyobashirb.connpass.com/event/312137/

ydah

March 13, 2024
Tweet

More Decks by ydah

Other Decks in Technology

Transcript

  1. ɾ Name: Yudai Takada ɾ GitHub: @ydah / X: @ydah_

    ɾ Software Engineer at ANDPAD, Inc. ɾ Co-Founder of Kyobashi.rb ɾ Member of RuboCop RSpec team ɾ Contributor of Lrama self.inspect
  2. 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
  3. Department of RuboCop RSpec We have several departments: • RSpec

    • Rails (for rspec-rails) • FactoryBot (for factory_bot) • Capybara (for capybara)
  4. 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
  5. Motivation for splitting gems The Rails department is not required

    for non- Rails products. For example: • Web applications using Sinatra • Not a web application.
  6. Destination and Status Department Extract to Status RSpec/Capybara rubocop-capybara Extracted

    in v2.18.0 RSpec/FactoryBot rubocop-factory_bot Extracted in v2.22.0 RSpec/Rails rubocop-rspec_rails Next version?
  7. After major version upgrade If there is a point where

    `Enabled: false` is set in .rubocop.yml at the time of major upgrade, it must be deleted. # .rubocop.yml RSpec/Capybara: Enabled: false RSpec/FactoryBot: Enabled: false RSpec/Rails: Enabled: false
  8. Three Steps for Migration 1. Add the destination gem to

    the Gem fi le 2. Add settings to .rubocop.yml 3. Replace the cop name with the new name in .rubocop.yml or .rubocop_todo.yml
  9. Add destination gem to Gemfile We currently rely on the

    extracted gems for backwards compatibility, but this will be removed in the next major version update. # Gemf i le gem 'rubocop - capybara', require: false gem 'rubocop - factory_bot', require: false gem ‘rubocop - rspec_rails’, require: false
  10. Add settings to .rubocop.yml You can't enable the RuboCop extension

    cop just by adding it to the Gemfile. You need to add a setting to .rubocop.yml to load the extension into RuboCop, like this: # .rubocop.yml require: - rubocop - capybara - rubocop - factory_bot - rubocop - rspec_rails
  11. Replace the cop name We need to replace it with

    a new department. If we need to replace it, we get a warning like this: $ 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 :
  12. Replace the cop name Using the cop of the FactoryBot

    department as an example, you can change the cop name as follows: -RSpec/FactoryBot/AttributeDef i nedStatically -RSpec/FactoryBot/ConsistentParenthesesStyle -RSpec/FactoryBot/CreateList +FactoryBot/ConsistentParenthesesStyle +FactoryBot/AttributeDef i nedStatically +FactoryBot/CreateList
  13. Replace the cop name .rubocop_todo.yml can be regenerated with the

    following command: $ bundle exec rubocop - - regenerate - todo
  14. end