Skip to content

Commit c629172

Browse files
committed
Fix infinite loop when expected value is literal
Fixes #1092
1 parent 07ff530 commit c629172

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Master (Unreleased)
44

5+
* Fixed infinite loop in `RSpec/ExpectActual` autocorrection when both expected and actual values are literals. ([@Darhazer][])
6+
57
## 2.0.0 (2020-11-06)
68

79
* Remove deprecated class `::RuboCop::Cop::RSpec::Cop`. ([@bquorning][])

lib/rubocop/cop/rspec/expect_actual.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def on_send(node)
6060
expect_literal(node) do |actual, matcher, expected|
6161
add_offense(actual.source_range) do |corrector|
6262
next unless SUPPORTED_MATCHERS.include?(matcher)
63+
next if literal?(expected)
6364

6465
swap(corrector, actual, expected)
6566
end

spec/rubocop/cop/rspec/expect_actual_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,19 @@
304304
expect_no_corrections
305305
end
306306

307+
it 'flags but does not autocorrect when the actual value is also a literal' do
308+
expect_offense(<<-RUBY)
309+
describe Foo do
310+
it 'uses expect incorrectly' do
311+
expect([1,2,3]).to eq([1, 2, 3])
312+
^^^^^^^ Provide the actual you are testing to `expect(...)`.
313+
end
314+
end
315+
RUBY
316+
317+
expect_no_corrections
318+
end
319+
307320
context 'when inspecting rspec-rails routing specs' do
308321
let(:cop_config) { {} }
309322

0 commit comments

Comments
 (0)