Skip to content

Commit

Permalink
Fix a random test failure for Performance/Sum
Browse files Browse the repository at this point in the history
The skipped tests fail with the following command:
`bundle exec rspec ./spec/rubocop/cli/autocorrect_spec.rb[1:1] ./spec/rubocop/cop/performance/sum_spec.rb[1:13] --seed 26805`

This is fine to do in the rubocop main repository but here we inject
additional config values that are not restored.

There are some things going on that I don't entirely understand:
* Why only failures in this one file
* Why did koic not manage to reproduce with the exact same seed
* Why did the failures seemingly disappear and reappear without any changes to the code

But regardless, this is more correct
  • Loading branch information
Earlopain committed Aug 21, 2024
1 parent d92287f commit 12009a6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
8 changes: 7 additions & 1 deletion spec/rubocop/cli/autocorrect_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@

include_context 'mock console output'

before do
# Restore injected config as well
around do |ex|
previous_config = RuboCop::ConfigLoader.default_configuration

RuboCop::ConfigLoader.default_configuration = nil
RuboCop::ConfigLoader.default_configuration.for_all_cops['SuggestExtensions'] = false
RuboCop::ConfigLoader.default_configuration.for_all_cops['NewCops'] = 'disable'
ex.call
ensure
RuboCop::ConfigLoader.default_configuration = previous_config
end

it 'corrects `Performance/ConstantRegexp` with `Performance/RegexpMatch`' do
Expand Down
16 changes: 0 additions & 16 deletions spec/rubocop/cop/performance/sum_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,6 @@
^{method}^^^^^ Use `sum` instead of `#{method}(&:+)`, unless calling `#{method}(&:+)` on an empty array.
RUBY

# FIXME: The following failures in JRuby need to be fixed:
# https://github.com/rubocop/rubocop-performance/actions/runs/7013730884/job/19080337215
skip('Unexpected JRuby autocorrection test failure needs to be fixed.') if RUBY_ENGINE == 'jruby'

expect_correction(<<~RUBY)
array.sum
RUBY
Expand All @@ -286,10 +282,6 @@
^{method}^^^^ Use `sum` instead of `#{method}(:+)`, unless calling `#{method}(:+)` on an empty array.
RUBY

# FIXME: The following failures in JRuby need to be fixed:
# https://github.com/rubocop/rubocop-performance/actions/runs/7013730884/job/19080337215
skip('Unexpected JRuby autocorrection test failure needs to be fixed.') if RUBY_ENGINE == 'jruby'

expect_correction(<<~RUBY)
array.sum
RUBY
Expand All @@ -301,10 +293,6 @@
^{method}^^^ Use `sum` instead of `#{method}(:+)`, unless calling `#{method}(:+)` on an empty array.
RUBY

# FIXME: The following failures in JRuby need to be fixed:
# https://github.com/rubocop/rubocop-performance/actions/runs/7013730884/job/19080337215
skip('Unexpected JRuby autocorrection test failure needs to be fixed.') if RUBY_ENGINE == 'jruby'

expect_correction(<<~RUBY)
array.sum
RUBY
Expand All @@ -316,10 +304,6 @@
^{method}^^^^ Use `sum` instead of `#{method}(:+)`.
RUBY

# FIXME: The following failures in JRuby need to be fixed:
# https://github.com/rubocop/rubocop-performance/actions/runs/7013730884/job/19080337215
skip('Unexpected JRuby autocorrection test failure needs to be fixed.') if RUBY_ENGINE == 'jruby'

expect_correction(<<~RUBY)
[1, 2, 3].sum
RUBY
Expand Down

0 comments on commit 12009a6

Please sign in to comment.