rubocop / rubocop-rspec

Code style checking for RSpec files.
https://docs.rubocop.org/rubocop-rspec
MIT License
792 stars 272 forks source link

`Autocorrect: contextual` causing error #1916

Closed gavindidrichsen closed 3 weeks ago

gavindidrichsen commented 3 weeks ago

The latest versions of rubocop-factory_bot and rubocop-respec_rails are causing rubocop-rspec to break with something like the following:

➜  dependency_checker git:(main) bundle exec rubocop
Error: Property AutoCorrect of cop FactoryBot/CreateList is supposed to be a boolean and contextual is not.
➜  dependency_checker git:(main) 

Manually correcting the above gems fixes the issue, e.g.,

➜  gems git:(main) ✗ git diff
diff --git a/rubocop-factory_bot-2.26.0/config/default.yml b/rubocop-factory_bot-2.26.0/config/default.yml
index 24d5ebb..60827e7 100644
--- a/rubocop-factory_bot-2.26.0/config/default.yml
+++ b/rubocop-factory_bot-2.26.0/config/default.yml
@@ -49,7 +49,7 @@ FactoryBot/ConsistentParenthesesStyle:
 FactoryBot/CreateList:
   Description: Checks for create_list usage.
   Enabled: true
-  AutoCorrect: contextual
+  AutoCorrect: false
   Include:
     - "**/*_spec.rb"
     - "**/spec/**/*"
diff --git a/rubocop-rspec_rails-2.29.0/config/default.yml b/rubocop-rspec_rails-2.29.0/config/default.yml
index 51ec888..a39bd20 100644
--- a/rubocop-rspec_rails-2.29.0/config/default.yml
+++ b/rubocop-rspec_rails-2.29.0/config/default.yml
@@ -66,7 +66,7 @@ RSpecRails/MinitestAssertions:

 RSpecRails/NegationBeValid:
   Description: Enforces use of `be_invalid` or `not_to` for negated be_valid.
-  AutoCorrect: contextual
+  AutoCorrect: false
   Safe: false
   EnforcedStyle: not_to
   SupportedStyles:
➜  gems git:(main) ✗ pwd
/Users/gavin.didrichsen/@REFERENCES/github/app/development/tools/puppet/@products/devx_tools/repos/dependency_checker/.direnv/ruby/gems/ruby/3.3.0/gems
➜  gems git:(main) ✗ 

Given this repository as an example, puppetlabs/dependency_checker, I can see from the Gemspec.lock the rubocop-rspec seems to be pulling the above dependencies in.

    rubocop-rspec (2.30.0)
      rubocop (~> 1.40)
      rubocop-capybara (~> 2.17)
      rubocop-factory_bot (~> 2.22)
      rubocop-rspec_rails (~> 2.28)

Excluding the lates versions as below fixes the issue:

gem 'rubocop-factory_bot', '!= 2.26.0', require: false
gem 'rubocop-rspec_rails', '!= 2.29.0', require: false
pirj commented 3 weeks ago

A workaround would be to update rubocop to a bersion that supports “contextual”.

Do we need to bump the dependency like we planned to here? https://github.com/rubocop/rubocop-rspec/pull/1901

Wondering why https://github.com/rubocop/rubocop-rspec/pull/1882 didn’t work? Wondering why ‘bundle install’ output is so dry https://github.com/rubocop/rubocop-rspec/actions/runs/9148652715/job/25151426029

bquorning commented 3 weeks ago

Wondering why #1882 didn’t work? Wondering why ‘bundle install’ output is so dry https://github.com/rubocop/rubocop-rspec/actions/runs/9148652715/job/25151426029

Confirming that CI testing with the oldest RuboCop version does indeed work; see #1920.

The problem must be elsewhere.

ydah commented 3 weeks ago

I ran the following on local: https://github.com/puppetlabs/dependency_checker

Revert to hacks for rubocop-factory_bot and rubocop-rspec_rails

diff --git a/Gemfile b/Gemfile
index 5985c04..18d0b4a 100644
--- a/Gemfile
+++ b/Gemfile
@@ -15,6 +15,4 @@ group :test do
   gem 'rubocop', '~> 1.50.0', require: false
   gem 'rubocop-performance', '~> 1.16', require: false
   gem 'rubocop-rspec', '~> 2.19', require: false
-  gem 'rubocop-factory_bot', '!= 2.26.0', require: false
-  gem 'rubocop-rspec_rails', '!= 2.29.0', require: false
 end
❯ bundle exec rubocop -V
/ydah/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/rubocop-1.50.2/lib/rubocop/formatter/html_formatter.rb:3: warning: base64 was loaded from the standard library, but will no longer be part of the default gems since Ruby 3.4.0. Add base64 to your Gemfile or gemspec. Also contact author of rubocop-1.50.2 to add base64 into its gemspec.
Error: Property AutoCorrect of cop FactoryBot/CreateList is supposed to be a boolean and contextual is not.

Change to gem 'rubocop', '~> 1.61.0', require: false

diff --git a/Gemfile b/Gemfile
index 5985c04..2a75e86 100644
--- a/Gemfile
+++ b/Gemfile
@@ -12,9 +12,7 @@ group :test do
   gem 'simplecov', require: false
   gem 'simplecov-console', require: false
   gem 'rspec', '~> 3.0', require: false
-  gem 'rubocop', '~> 1.50.0', require: false
+  gem 'rubocop', '~> 1.61.0', require: false
   gem 'rubocop-performance', '~> 1.16', require: false
   gem 'rubocop-rspec', '~> 2.19', require: false
-  gem 'rubocop-factory_bot', '!= 2.26.0', require: false
-  gem 'rubocop-rspec_rails', '!= 2.29.0', require: false
 end
❯ bundle exec rubocop -V
1.61.0 (using Parser 3.3.2.0, rubocop-ast 1.31.3, running on ruby 3.3.0) [arm64-darwin23]
  - rubocop-performance 1.21.0
  - rubocop-rspec 2.31.0
ydah commented 3 weeks ago

I have not yet figured out why this happens but at least v1.61 or higher seems to solve it.

jminterwebs commented 3 weeks ago

Having the same issue setting to 1.61 does not fix the issue.

bquorning commented 3 weeks ago

Can the problem solved by upgrading to rubocop-rspec v3.0.1?

jminterwebs commented 3 weeks ago

v3.0.1 appears to have fixed it all.

ydah commented 3 weeks ago

I checked it, and it seems fixed 👍🏻