rubocop / rubocop-performance

An extension of RuboCop focused on code performance checks.
https://docs.rubocop.org/rubocop-performance
MIT License
682 stars 80 forks source link

Fix a random test failure for `Performance/Sum` #458

Closed Earlopain closed 2 months ago

Earlopain commented 2 months ago

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 (or maybe not, there is something extra going on I don't understand)

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:

But regardless, this is more correct. Removing the JRuby skips is a bit of a guess on my side but I don't see what else should prevent them from passing. Let's see how it goes.

Bit of extra context starting at https://github.com/rubocop/rubocop-performance/pull/398#issuecomment-2301743107

koic commented 2 months ago

Why did koic not manage to reproduce with the exact same seed

When I ran it again, the following error occurred:

$ bundle exec rspec './spec/rubocop/cli/autocorrect_spec.rb[1:1]' './spec/rubocop/cop/performance/sum_spec.rb[1:13]' --seed 26805
Run options: include {:ids=>{"./spec/rubocop/cli/autocorrect_spec.rb"=>["1:1"], "./spec/rubocop/cop/performance/sum_spec.rb"=>["1:13"]}}

Randomized with seed 26805
.F

Failures:

  1) RuboCop::Cop::Performance::Sum autocorrects `&:+` when initial value is not provided
     Failure/Error:
       expect_correction(<<~RUBY)
         array.sum
       RUBY

     RuntimeError:
       Expected correction but no corrections were made
     # ./spec/rubocop/cop/performance/sum_spec.rb:278:in 'block (3 levels) in <top (required)>'

Finished in 0.39425 seconds (files took 2.33 seconds to load)
2 examples, 1 failure

Failed examples:

rspec './spec/rubocop/cop/performance/sum_spec.rb[1:13]' # RuboCop::Cop::Performance::Sum autocorrects `&:+` when initial value is not provided

Randomized with seed 26805
Earlopain commented 2 months ago

Ah, right. Yeah, that is what I was getting as well. Still, I would expect this to come up all the for other cops as well and I don't know why Sum is special here.