diff --git a/.rubocop.yml b/.rubocop.yml index 8b5a17f71f..1e307d7184 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,6 +1,7 @@ inherit_from: .rubocop_todo.yml plugins: + - rubocop-performance - rubocop-rake - rubocop-rspec diff --git a/Gemfile b/Gemfile index 36d9253e5f..5ecf555c7f 100644 --- a/Gemfile +++ b/Gemfile @@ -20,6 +20,7 @@ gem "rake" # Linting gem "rubocop", require: false +gem "rubocop-performance", require: false gem "rubocop-rake", require: false gem "rubocop-rspec", require: false diff --git a/spec/money/allocation_spec.rb b/spec/money/allocation_spec.rb index eda4ca54c6..264a27ced0 100644 --- a/spec/money/allocation_spec.rb +++ b/spec/money/allocation_spec.rb @@ -56,7 +56,7 @@ BigDecimal("33.3333333333"), ], ) - expect(parts.inject(0, :+)).to eq(amount) + expect(parts.sum).to eq(amount) end end end @@ -132,7 +132,7 @@ BigDecimal("33.3333333333"), ], ) - expect(parts.inject(0, :+)).to eq(amount) + expect(parts.sum).to eq(amount) end end end @@ -156,7 +156,7 @@ ] result = described_class.generate(amount, allocations) - expect(result.reduce(&:+)).to eq(amount) + expect(result.sum).to eq(amount) expect(result).to eq( [ 61566, @@ -193,7 +193,7 @@ ] result = described_class.generate(amount, allocations) - expect(result.reduce(&:+)).to eq(amount) + expect(result.sum).to eq(amount) expect(result).to eq( [ -61566, @@ -229,7 +229,7 @@ it "allocates with required precision" do result = described_class.generate(amount, allocations, 16) - expect(result.reduce(&:+)).to eq(amount) + expect(result.sum).to eq(amount) expected = %w[ 6.3347130857200688 6.3347130857200689 6.3347130857200688 6.3347130857200688 diff --git a/spec/money/currency_spec.rb b/spec/money/currency_spec.rb index 04da83328d..6252fc2b91 100644 --- a/spec/money/currency_spec.rb +++ b/spec/money/currency_spec.rb @@ -310,7 +310,7 @@ def to_s it "is thread safe" do ids = [] - 2.times.map { Thread.new { ids << described_class.new("USD").object_id } }.each(&:join) + Array.new(2) { Thread.new { ids << described_class.new("USD").object_id } }.each(&:join) expect(ids.uniq.length).to eq(1) end end diff --git a/spec/money/rates_store/memory_spec.rb b/spec/money/rates_store/memory_spec.rb index 3b0b6d98d2..abd98bf902 100644 --- a/spec/money/rates_store/memory_spec.rb +++ b/spec/money/rates_store/memory_spec.rb @@ -42,7 +42,7 @@ end describe "#transaction" do - let(:guard) { store.instance_variable_get("@guard") } + let(:guard) { store.instance_variable_get(:@guard) } before do allow(guard).to receive(:synchronize) diff --git a/spec/money_spec.rb b/spec/money_spec.rb index c079d702e4..02dc61f293 100644 --- a/spec/money_spec.rb +++ b/spec/money_spec.rb @@ -889,7 +889,7 @@ end it "does not round rationals" do - splits = 7.times.map { Rational(950, 6650) } + splits = Array.new(7) { Rational(950, 6650) } moneys = Money.us_dollar(6650).allocate(splits) moneys.each do |money| expect(money.cents).to eq 950 @@ -937,7 +937,7 @@ context "with infinite_precision", :default_infinite_precision_true do it "allows for fractional cents allocation" do moneys = Money.new(100).allocate([1, 1, 1]) - expect(moneys.inject(0, :+)).to eq(Money.new(100)) + expect(moneys.sum).to eq(Money.new(100)) end end end @@ -975,7 +975,7 @@ context "with infinite_precision", :default_infinite_precision_true do it "allows for splitting by fractional cents" do moneys = Money.new(100).split(3) - expect(moneys.inject(0, :+)).to eq(Money.new(100)) + expect(moneys.sum).to eq(Money.new(100)) end end end