From 287d6571f505889db300f5e94d518b23f6ad645e Mon Sep 17 00:00:00 2001 From: Maxim Krizhanovski Date: Mon, 27 Jun 2022 14:51:55 +0100 Subject: [PATCH] Update specs to use the expect_correction helper --- .../cop/rails/active_record_aliases_spec.rb | 9 +-- spec/rubocop/cop/rails/delegate_spec.rb | 64 ++++--------------- 2 files changed, 15 insertions(+), 58 deletions(-) diff --git a/spec/rubocop/cop/rails/active_record_aliases_spec.rb b/spec/rubocop/cop/rails/active_record_aliases_spec.rb index 2461116294..3a00320572 100644 --- a/spec/rubocop/cop/rails/active_record_aliases_spec.rb +++ b/spec/rubocop/cop/rails/active_record_aliases_spec.rb @@ -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 diff --git a/spec/rubocop/cop/rails/delegate_spec.rb b/spec/rubocop/cop/rails/delegate_spec.rb index 024c80b81e..268804b6d0 100644 --- a/spec/rubocop/cop/rails/delegate_spec.rb +++ b/spec/rubocop/cop/rails/delegate_spec.rb @@ -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 @@ -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 @@ -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 @@ -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