Skip to content

Commit

Permalink
Always loop when testing autocorrection
Browse files Browse the repository at this point in the history
For most cops and specs, this won't change anything. The offense is
corrected in one go, and the second iteration doesn't change anything.

For a few specs this will change something. For a few specs, they have
to explicitly pass `loop: false` to test the result of the first round
of autocorrect, and in some specs we need to pass it to avoid exceptions
such as `InfiniteCorrectionLoop`. And that's the real value of using
looped autocorrection in the specs - we will find more errors, earlier.
  • Loading branch information
bquorning authored and bbatsov committed Jun 5, 2020
1 parent f6286b9 commit 64b066d
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion lib/rubocop/rspec/expect_offense.rb
Expand Up @@ -115,7 +115,7 @@ def expect_offense(source, file = nil, **replacements)
expect(actual_annotations.to_s).to eq(expected_annotations.to_s)
end

def expect_correction(correction, loop: false)
def expect_correction(correction, loop: true)
raise '`expect_correction` must follow `expect_offense`' unless @processed_source

iteration = 0
Expand Down
4 changes: 2 additions & 2 deletions spec/rubocop/cop/bundler/ordered_gems_spec.rb
Expand Up @@ -105,7 +105,7 @@
gem "i"
RUBY

expect_correction(<<~RUBY, loop: true)
expect_correction(<<~RUBY)
gem "a"
gem "b"
gem "c"
Expand Down Expand Up @@ -167,7 +167,7 @@
gem 'rspec' # For test
RUBY

expect_correction(<<~RUBY, loop: true)
expect_correction(<<~RUBY)
gem 'pry'
gem 'rspec' # For test
gem 'rubocop' # For code quality
Expand Down
4 changes: 2 additions & 2 deletions spec/rubocop/cop/layout/array_alignment_spec.rb
Expand Up @@ -92,7 +92,7 @@
[:l4]]]]
RUBY

expect_correction(<<~RUBY)
expect_correction(<<~RUBY, loop: false)
[:l1,
[:l2,
[:l3,
Expand Down Expand Up @@ -251,7 +251,7 @@
[:l4]]]]
RUBY

expect_correction(<<~RUBY)
expect_correction(<<~RUBY, loop: false)
[:l1,
[:l2,
[:l3,
Expand Down
2 changes: 1 addition & 1 deletion spec/rubocop/cop/layout/class_structure_spec.rb
Expand Up @@ -107,7 +107,7 @@ class Person
end
RUBY

expect_correction(<<~RUBY, loop: true)
expect_correction(<<~RUBY)
class Person
include AnotherModule
extend SomeModule
Expand Down
2 changes: 1 addition & 1 deletion spec/rubocop/cop/layout/extra_spacing_spec.rb
Expand Up @@ -529,7 +529,7 @@ def batch
end
RUBY

expect_correction(<<~RUBY)
expect_correction(<<~RUBY, loop: false)
def batch
@areas = params[:param].map {
var_1 = 123_456
Expand Down
Expand Up @@ -395,7 +395,7 @@
)
RUBY

expect_correction(<<~RUBY)
expect_correction(<<~RUBY, loop: false)
bar(
foo(123, <<-SQL),
foo
Expand Down Expand Up @@ -503,7 +503,7 @@
^ Put the closing parenthesis for a method call with a HEREDOC parameter on the same line as the HEREDOC opening.
RUBY

expect_correction(<<~RUBY)
expect_correction(<<~RUBY, loop: false)
query.order(Arel.sql(<<-SQL)
foo
SQL
Expand Down
4 changes: 2 additions & 2 deletions spec/rubocop/cop/layout/heredoc_indentation_spec.rb
Expand Up @@ -128,7 +128,7 @@ def foo
RUBY2
RUBY

expect_correction(<<~CORRECTION, loop: true)
expect_correction(<<~CORRECTION)
<<~#{quote}RUBY2#{quote}
foo
RUBY2
Expand Down Expand Up @@ -160,7 +160,7 @@ def foo
RUBY2
RUBY

expect_correction(<<-CORRECTION, loop: true)
expect_correction(<<-CORRECTION)
puts <<~#{quote}RUBY2#{quote}
def foo
bar
Expand Down
Expand Up @@ -359,7 +359,7 @@
^ Space after last block parameter missing.
RUBY

expect_correction(<<~RUBY)
expect_correction(<<~RUBY, loop: false)
{}.each { | x ,| puts x }
RUBY
end
Expand Down
Expand Up @@ -527,7 +527,7 @@ def Vector.[](*array)
^ Do not use space inside array brackets.
RUBY

expect_correction(<<~RUBY)
expect_correction(<<~RUBY, loop: false)
multiline = [ [ 1, 2, 3, 4 ],
[ 3, 4, 5, 6 ]]
RUBY
Expand Down
2 changes: 1 addition & 1 deletion spec/rubocop/cop/lint/useless_access_modifier_spec.rb
Expand Up @@ -634,7 +634,7 @@ def method2
end
RUBY

expect_correction(<<~RUBY)
expect_correction(<<~RUBY, loop: false)
#{keyword} A
private
def method1
Expand Down
Expand Up @@ -64,7 +64,7 @@
it 'autocorrects the inner offense first' do
expect_offense(annotated_source)

expect_correction(<<~RUBY)
expect_correction(<<~RUBY, loop: false)
if var.any?(:prob_a_check)
@errors << 'Problem A'
elsif var.any?(:prob_a_check)
Expand Down Expand Up @@ -2079,7 +2079,7 @@
end
RUBY

expect_correction(<<~RUBY)
expect_correction(<<~RUBY, loop: false)
unless foo
baz = if foobar
1
Expand Down Expand Up @@ -2212,7 +2212,7 @@
it 'does not consider branches of nested ifs' do
expect_offense(annotated_source)

expect_correction(<<~RUBY)
expect_correction(<<~RUBY, loop: false)
if outer
bar = 1
else
Expand Down
2 changes: 1 addition & 1 deletion spec/rubocop/cop/style/rescue_modifier_spec.rb
Expand Up @@ -210,7 +210,7 @@ def foo
^^^^^^^^^^^^^^^^^^^^^^ Avoid using `rescue` in its modifier form.
RUBY

expect_correction(<<~RUBY, loop: true)
expect_correction(<<~RUBY)
begin
begin
blah
Expand Down

0 comments on commit 64b066d

Please sign in to comment.