Skip to content

Commit

Permalink
Merge pull request #734 from rubocop/refactor-correction-specs
Browse files Browse the repository at this point in the history
Update specs to use the expect_correction helper
  • Loading branch information
koic committed Jun 27, 2022
2 parents 739cfc6 + 287d657 commit da37010
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 58 deletions.
9 changes: 3 additions & 6 deletions spec/rubocop/cop/rails/active_record_aliases_spec.rb
Expand Up @@ -19,13 +19,10 @@
book&.update_attributes(author: "Alice")
^^^^^^^^^^^^^^^^^ Use `update` instead of `update_attributes`.
RUBY
end

it 'is autocorrected' do
new_source = autocorrect_source(
'book&.update_attributes(author: "Alice")'
)
expect(new_source).to eq 'book&.update(author: "Alice")'
expect_correction(<<~RUBY)
book&.update(author: "Alice")
RUBY
end
end
end
Expand Down
64 changes: 12 additions & 52 deletions spec/rubocop/cop/rails/delegate_spec.rb
Expand Up @@ -15,6 +15,10 @@ def foo
bar.foo
end
RUBY

expect_correction(<<~RUBY)
delegate :foo, to: :bar
RUBY
end

it 'finds trivial delegate with arguments' do
Expand All @@ -24,6 +28,10 @@ def foo(baz)
bar.foo(baz)
end
RUBY

expect_correction(<<~RUBY)
delegate :foo, to: :bar
RUBY
end

it 'finds trivial delegate with prefix' do
Expand All @@ -33,6 +41,10 @@ def bar_foo
bar.foo
end
RUBY

expect_correction(<<~RUBY)
delegate :foo, to: :bar, prefix: true
RUBY
end

it 'ignores class methods' do
Expand Down Expand Up @@ -181,56 +193,4 @@ def foo
end
RUBY
end

describe '#autocorrect' do
context 'trivial delegation' do
let(:source) do
<<~RUBY
def bar
foo.bar
end
RUBY
end

let(:corrected_source) do
<<~RUBY
delegate :bar, to: :foo
RUBY
end

it 'autocorrects' do
expect(autocorrect_source(source)).to eq(corrected_source)
end
end

context 'trivial delegation with prefix' do
let(:source) do
<<~RUBY
def foo_bar
foo.bar
end
RUBY
end

let(:corrected_source) do
<<~RUBY
delegate :bar, to: :foo, prefix: true
RUBY
end

it 'autocorrects' do
expect(autocorrect_source(source)).to eq(corrected_source)
end

context 'with EnforceForPrefixed: false' do
let(:cop_config) do
{ 'EnforceForPrefixed' => false }
end

it 'does not autocorrect' do
expect(autocorrect_source(source)).to eq(source)
end
end
end
end
end

0 comments on commit da37010

Please sign in to comment.