Skip to content

Commit

Permalink
Use new expect_offense and expect_correction
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Eres authored and bbatsov committed Dec 24, 2020
1 parent 8a85e4f commit f57312a
Showing 1 changed file with 30 additions and 15 deletions.
45 changes: 30 additions & 15 deletions spec/rubocop/cop/alignment_corrector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,31 @@
context 'simple indentation' do
context 'with a positive column delta' do
it 'indents' do
expect(autocorrect_source(<<~INPUT)).to eq(<<~OUTPUT)
expect_offense(<<~RUBY)
# >> 2
42
INPUT
^^ Indent this node
RUBY

expect_correction(<<~RUBY, loop: false)
# >> 2
42
OUTPUT
RUBY
end
end

context 'with a negative column delta' do
it 'outdents' do
expect(autocorrect_source(<<~INPUT)).to eq(<<~OUTPUT)
expect_offense(<<~RUBY)
# << 3
42
INPUT
^^ Indent this node
RUBY

expect_correction(<<~RUBY, loop: false)
# << 3
42
OUTPUT
RUBY
end
end
end
Expand All @@ -35,23 +41,26 @@
let(:end_heredoc) { /\w+/.match(start_heredoc)[0] }

it 'does not change indentation of here doc bodies and end markers' do
expect(autocorrect_source(<<~INPUT)).to eq(<<~OUTPUT)
expect_offense(<<~RUBY)
# >> #{column_delta}
begin
^^^^^ Indent this node
#{start_heredoc}
a
b
#{end_heredoc}
end
INPUT
RUBY

expect_correction(<<~RUBY, loop: false)
# >> #{column_delta}
#{indentation}begin
#{indentation} #{start_heredoc}
a
b
#{end_heredoc}
#{indentation}end
OUTPUT
RUBY
end
end

Expand All @@ -68,29 +77,33 @@
context 'with single-line here docs' do
it 'does not indent body and end marker' do
indentation = ' '
expect(autocorrect_source(<<~INPUT)).to eq(<<~OUTPUT)
expect_offense(<<~RUBY)
# >> 2
begin
^^^^^ Indent this node
<<DOC
single line
DOC
end
INPUT
RUBY

expect_correction(<<~RUBY, loop: false)
# >> 2
#{indentation}begin
#{indentation} <<DOC
single line
DOC
#{indentation}end
OUTPUT
RUBY
end
end

context 'within string literals' do
it 'does not insert whitespace' do
expect(autocorrect_source(<<~INPUT)).to eq(<<~OUTPUT)
expect_offense(<<~RUBY)
# >> 2
begin
^^^^^ Indent this node
dstr =
'a
b
Expand All @@ -100,7 +113,9 @@
b
c`
end
INPUT
RUBY

expect_correction(<<~RUBY, loop: false)
# >> 2
begin
dstr =
Expand All @@ -112,7 +127,7 @@
b
c`
end
OUTPUT
RUBY
end
end
end
Expand Down

0 comments on commit f57312a

Please sign in to comment.