Skip to content

Commit b15e789

Browse files
committed
Use expect_correction
Reduce usage of `include_examples 'autocorrect'`.
1 parent 4c6beec commit b15e789

File tree

1 file changed

+42
-16
lines changed

1 file changed

+42
-16
lines changed

spec/rubocop/cop/rspec/hook_argument_spec.rb

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,6 @@
2828
end
2929
end
3030

31-
shared_examples 'hook autocorrect' do |output|
32-
include_examples 'autocorrect', 'before(:each) { }', output
33-
include_examples 'autocorrect', 'before(:example) { }', output
34-
include_examples 'autocorrect', 'before { }', output
35-
36-
include_examples 'autocorrect', 'config.before(:each) { }',
37-
"config.#{output}"
38-
include_examples 'autocorrect', 'config.before(:example) { }',
39-
"config.#{output}"
40-
include_examples 'autocorrect', 'config.before { }',
41-
"config.#{output}"
42-
end
43-
4431
shared_examples 'an example hook' do
4532
include_examples 'ignored hooks'
4633
include_examples 'detects style', 'before(:each) { foo }', 'each'
@@ -62,6 +49,13 @@
6249
config.after(:each) { true }
6350
^^^^^^^^^^^^^^^^^^^ Omit the default `:each` argument for RSpec hooks.
6451
RUBY
52+
53+
expect_correction(<<-RUBY)
54+
before { true }
55+
after { true }
56+
around { true }
57+
config.after { true }
58+
RUBY
6559
end
6660

6761
it 'detects :example for hooks' do
@@ -75,6 +69,13 @@
7569
config.before(:example) { true }
7670
^^^^^^^^^^^^^^^^^^^^^^^ Omit the default `:example` argument for RSpec hooks.
7771
RUBY
72+
73+
expect_correction(<<-RUBY)
74+
before { true }
75+
after { true }
76+
around { true }
77+
config.before { true }
78+
RUBY
7879
end
7980

8081
it 'does not flag hooks without default scopes' do
@@ -87,7 +88,6 @@
8788
end
8889

8990
include_examples 'an example hook'
90-
include_examples 'hook autocorrect', 'before { }'
9191
end
9292

9393
context 'when EnforcedStyle is :each' do
@@ -113,6 +113,13 @@
113113
config.before(:example) { true }
114114
^^^^^^^^^^^^^^^^^^^^^^^ Use `:each` for RSpec hooks.
115115
RUBY
116+
117+
expect_correction(<<-RUBY)
118+
before(:each) { true }
119+
after(:each) { true }
120+
around(:each) { true }
121+
config.before(:each) { true }
122+
RUBY
116123
end
117124

118125
it 'detects hooks without default scopes' do
@@ -126,10 +133,16 @@
126133
config.before { true }
127134
^^^^^^ Use `:each` for RSpec hooks.
128135
RUBY
136+
137+
expect_correction(<<-RUBY)
138+
before(:each) { true }
139+
after(:each) { true }
140+
around(:each) { true }
141+
config.before(:each) { true }
142+
RUBY
129143
end
130144

131145
include_examples 'an example hook'
132-
include_examples 'hook autocorrect', 'before(:each) { }'
133146
end
134147

135148
context 'when EnforcedStyle is :example' do
@@ -155,6 +168,13 @@
155168
config.before(:each) { true }
156169
^^^^^^^^^^^^^^^^^^^^ Use `:example` for RSpec hooks.
157170
RUBY
171+
172+
expect_correction(<<-RUBY)
173+
before(:example) { true }
174+
after(:example) { true }
175+
around(:example) { true }
176+
config.before(:example) { true }
177+
RUBY
158178
end
159179

160180
it 'detects hooks without default scopes' do
@@ -168,9 +188,15 @@
168188
config.before { true }
169189
^^^^^^ Use `:example` for RSpec hooks.
170190
RUBY
191+
192+
expect_correction(<<-RUBY)
193+
before(:example) { true }
194+
after(:example) { true }
195+
around(:example) { true }
196+
config.before(:example) { true }
197+
RUBY
171198
end
172199

173200
include_examples 'an example hook'
174-
include_examples 'hook autocorrect', 'before(:example) { }'
175201
end
176202
end

0 commit comments

Comments
 (0)