Skip to content

Commit da37010

Browse files
authored
Merge pull request #734 from rubocop/refactor-correction-specs
Update specs to use the expect_correction helper
2 parents 739cfc6 + 287d657 commit da37010

File tree

2 files changed

+15
-58
lines changed

2 files changed

+15
-58
lines changed

spec/rubocop/cop/rails/active_record_aliases_spec.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,10 @@
1919
book&.update_attributes(author: "Alice")
2020
^^^^^^^^^^^^^^^^^ Use `update` instead of `update_attributes`.
2121
RUBY
22-
end
2322

24-
it 'is autocorrected' do
25-
new_source = autocorrect_source(
26-
'book&.update_attributes(author: "Alice")'
27-
)
28-
expect(new_source).to eq 'book&.update(author: "Alice")'
23+
expect_correction(<<~RUBY)
24+
book&.update(author: "Alice")
25+
RUBY
2926
end
3027
end
3128
end

spec/rubocop/cop/rails/delegate_spec.rb

Lines changed: 12 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ def foo
1515
bar.foo
1616
end
1717
RUBY
18+
19+
expect_correction(<<~RUBY)
20+
delegate :foo, to: :bar
21+
RUBY
1822
end
1923

2024
it 'finds trivial delegate with arguments' do
@@ -24,6 +28,10 @@ def foo(baz)
2428
bar.foo(baz)
2529
end
2630
RUBY
31+
32+
expect_correction(<<~RUBY)
33+
delegate :foo, to: :bar
34+
RUBY
2735
end
2836

2937
it 'finds trivial delegate with prefix' do
@@ -33,6 +41,10 @@ def bar_foo
3341
bar.foo
3442
end
3543
RUBY
44+
45+
expect_correction(<<~RUBY)
46+
delegate :foo, to: :bar, prefix: true
47+
RUBY
3648
end
3749

3850
it 'ignores class methods' do
@@ -181,56 +193,4 @@ def foo
181193
end
182194
RUBY
183195
end
184-
185-
describe '#autocorrect' do
186-
context 'trivial delegation' do
187-
let(:source) do
188-
<<~RUBY
189-
def bar
190-
foo.bar
191-
end
192-
RUBY
193-
end
194-
195-
let(:corrected_source) do
196-
<<~RUBY
197-
delegate :bar, to: :foo
198-
RUBY
199-
end
200-
201-
it 'autocorrects' do
202-
expect(autocorrect_source(source)).to eq(corrected_source)
203-
end
204-
end
205-
206-
context 'trivial delegation with prefix' do
207-
let(:source) do
208-
<<~RUBY
209-
def foo_bar
210-
foo.bar
211-
end
212-
RUBY
213-
end
214-
215-
let(:corrected_source) do
216-
<<~RUBY
217-
delegate :bar, to: :foo, prefix: true
218-
RUBY
219-
end
220-
221-
it 'autocorrects' do
222-
expect(autocorrect_source(source)).to eq(corrected_source)
223-
end
224-
225-
context 'with EnforceForPrefixed: false' do
226-
let(:cop_config) do
227-
{ 'EnforceForPrefixed' => false }
228-
end
229-
230-
it 'does not autocorrect' do
231-
expect(autocorrect_source(source)).to eq(source)
232-
end
233-
end
234-
end
235-
end
236196
end

0 commit comments

Comments
 (0)