From 12009a62f51b2ebb055da636a74ffd7c8c351923 Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Wed, 21 Aug 2024 20:36:58 +0200 Subject: [PATCH] Fix a random test failure for `Performance/Sum` 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 --- spec/rubocop/cli/autocorrect_spec.rb | 8 +++++++- spec/rubocop/cop/performance/sum_spec.rb | 16 ---------------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/spec/rubocop/cli/autocorrect_spec.rb b/spec/rubocop/cli/autocorrect_spec.rb index ebe8746cf7..32a5eb66d2 100644 --- a/spec/rubocop/cli/autocorrect_spec.rb +++ b/spec/rubocop/cli/autocorrect_spec.rb @@ -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 diff --git a/spec/rubocop/cop/performance/sum_spec.rb b/spec/rubocop/cop/performance/sum_spec.rb index 951a4f3097..fdbf2b76a8 100644 --- a/spec/rubocop/cop/performance/sum_spec.rb +++ b/spec/rubocop/cop/performance/sum_spec.rb @@ -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 @@ -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 @@ -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 @@ -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