1616 end
1717
1818 shared_examples 'all legacy match methods' do |name , cond , correction |
19- include_examples 'offense' , "#{ name } in if condition" , <<- RUBY , <<- RUBY2
19+ it_behaves_like 'offense' , "#{ name } in if condition" , <<~ RUBY , <<~ RUBY2
2020 if #{ cond }
2121 do_something
2222 end
2626 end
2727 RUBY2
2828
29- include_examples 'offense' , "#{ name } in unless condition" , <<- RUBY , <<- RUBY2
29+ it_behaves_like 'offense' , "#{ name } in unless condition" , <<~ RUBY , <<~ RUBY2
3030 unless #{ cond }
3131 do_something
3232 end
3636 end
3737 RUBY2
3838
39- include_examples 'offense' , "#{ name } in if condition" , <<- RUBY , <<- RUBY2
39+ it_behaves_like 'offense' , "#{ name } in if condition" , <<~ RUBY , <<~ RUBY2
4040 do_something if #{ cond }
4141 RUBY
4242 do_something if #{ correction }
4343 RUBY2
4444
45- include_examples 'offense' , "#{ name } in unless condition" , <<- RUBY , <<- RUBY2
45+ it_behaves_like 'offense' , "#{ name } in unless condition" , <<~ RUBY , <<~ RUBY2
4646 do_something unless #{ cond }
4747 RUBY
4848 do_something unless #{ correction }
4949 RUBY2
5050
51- include_examples 'offense' , "#{ name } in elsif condition" , <<- RUBY , <<- RUBY2
51+ it_behaves_like 'offense' , "#{ name } in elsif condition" , <<~ RUBY , <<~ RUBY2
5252 if cond
5353 do_something
5454 elsif #{ cond }
6262 end
6363 RUBY2
6464
65- include_examples 'offense' , "#{ name } in case condition" , <<- RUBY , <<- RUBY2
65+ it_behaves_like 'offense' , "#{ name } in case condition" , <<~ RUBY , <<~ RUBY2
6666 case
6767 when #{ cond }
6868 do_something
7474 end
7575 RUBY2
7676
77- include_examples 'offense' , "#{ name } in ternary operator" , <<- RUBY , <<- RUBY2
77+ it_behaves_like 'offense' , "#{ name } in ternary operator" , <<~ RUBY , <<~ RUBY2
7878 #{ cond } ? do_something : do_something2
7979 RUBY
8080 #{ correction } ? do_something : do_something2
8181 RUBY2
8282
83- include_examples 'offense' , "#{ name } in method definition" ,
84- <<-RUBY , <<-RUBY2
83+ it_behaves_like 'offense' , "#{ name } in method definition" , <<~RUBY , <<~RUBY2
8584 def foo
8685 if #{ cond }
8786 do_something
@@ -146,9 +145,8 @@ def foo
146145 RUBY
147146 end
148147
149- include_examples 'offense' ,
150- "#{ name } in if guard condition with " \
151- "#{ var } is used in another method" , <<-RUBY , <<-RUBY2
148+ # rubocop:disable Layout/LineLength
149+ it_behaves_like 'offense' , "#{ name } in if guard condition with #{ var } is used in another method" , <<~RUBY , <<~RUBY2
152150 def foo
153151 return if #{ cond }
154152 end
@@ -165,6 +163,7 @@ def bar
165163 do_something(#{ var } )
166164 end
167165 RUBY2
166+ # rubocop:enable Layout/LineLength
168167
169168 it "accepts #{ name } in method with #{ var } in block" do
170169 expect_no_offenses ( <<~RUBY )
@@ -179,8 +178,7 @@ def foo
179178 RUBY
180179 end
181180
182- include_examples 'offense' ,
183- "#{ name } in method before `#{ var } `" , <<-RUBY , <<-RUBY2
181+ it_behaves_like 'offense' , "#{ name } in method before `#{ var } `" , <<~RUBY , <<~RUBY2
184182 def foo
185183 do_something(#{ var } )
186184 if #{ cond }
@@ -196,9 +194,7 @@ def foo
196194 end
197195 RUBY2
198196
199- include_examples 'offense' ,
200- "#{ name } in method, `#{ var } ` is in other method" ,
201- <<-RUBY , <<-RUBY2
197+ it_behaves_like 'offense' , "#{ name } in method, `#{ var } ` is in other method" , <<~RUBY , <<~RUBY2
202198 def foo
203199 if #{ cond }
204200 do_something2
@@ -220,9 +216,7 @@ def bar
220216 end
221217 RUBY2
222218
223- include_examples 'offense' ,
224- "#{ name } in class method, `#{ var } ` is in other method" ,
225- <<-RUBY , <<-RUBY2
219+ it_behaves_like 'offense' , "#{ name } in class method, `#{ var } ` is in other method" , <<~RUBY , <<~RUBY2
226220 def self.foo
227221 if #{ cond }
228222 do_something2
@@ -244,9 +238,7 @@ def self.bar
244238 end
245239 RUBY2
246240
247- include_examples 'offense' ,
248- "#{ name } in class, `#{ var } ` is in method" ,
249- <<-RUBY , <<-RUBY2
241+ it_behaves_like 'offense' , "#{ name } in class, `#{ var } ` is in method" , <<~RUBY , <<~RUBY2
250242 class Foo
251243 if #{ cond }
252244 do_something
@@ -268,9 +260,7 @@ def foo
268260 end
269261 RUBY2
270262
271- include_examples 'offense' ,
272- "#{ name } in module, `#{ var } ` is in method" ,
273- <<-RUBY , <<-RUBY2
263+ it_behaves_like 'offense' , "#{ name } in module, `#{ var } ` is in method" , <<~RUBY , <<~RUBY2
274264 module Foo
275265 if #{ cond }
276266 do_something
@@ -292,8 +282,7 @@ def foo
292282 end
293283 RUBY2
294284
295- include_examples 'offense' , "#{ name } , #{ var } reference is overridden" ,
296- <<-RUBY , <<-RUBY2
285+ it_behaves_like 'offense' , "#{ name } , #{ var } reference is overridden" , <<~RUBY , <<~RUBY2
297286 if #{ cond }
298287 do_something
299288 #{ cond }
@@ -310,20 +299,16 @@ def foo
310299 end
311300
312301 it_behaves_like ( 'all legacy match methods' , 'String#match method call' , '"foo".match(re)' , '"foo".match?(re)' )
313- it_behaves_like ( 'all legacy match methods' ,
314- 'String#match method call with position' ,
302+ it_behaves_like ( 'all legacy match methods' , 'String#match method call with position' ,
315303 '"foo".match(re, 1)' , '"foo".match?(re, 1)' )
316304 it_behaves_like ( 'all legacy match methods' , 'Regexp#match method call' , '/re/.match(foo)' , '/re/.match?(foo)' )
317- it_behaves_like ( 'all legacy match methods' ,
318- 'Regexp#match method call with position' ,
305+ it_behaves_like ( 'all legacy match methods' , 'Regexp#match method call with position' ,
319306 '/re/.match(foo, 1)' , '/re/.match?(foo, 1)' )
320307 it_behaves_like ( 'all legacy match methods' , 'Symbol#match method call' , ':foo.match(re)' , ':foo.match?(re)' )
321- it_behaves_like ( 'all legacy match methods' ,
322- 'Symbol#match method call with position' ,
308+ it_behaves_like ( 'all legacy match methods' , 'Symbol#match method call with position' ,
323309 ':foo.match(re, 1)' , ':foo.match?(re, 1)' )
324310 it_behaves_like ( 'all legacy match methods' , 'match method call for a variable' , 'foo.match(/re/)' , 'foo.match?(/re/)' )
325- it_behaves_like ( 'all legacy match methods' ,
326- 'match method call for a variable with position' ,
311+ it_behaves_like ( 'all legacy match methods' , 'match method call for a variable with position' ,
327312 'foo.match(/re/, 1)' , 'foo.match?(/re/, 1)' )
328313 it_behaves_like ( 'all legacy match methods' , 'matching by =~`' , '/re/ =~ foo' , '/re/.match?(foo)' )
329314 it_behaves_like ( 'all legacy match methods' , 'matching by =~`' , 'foo =~ /re/' , '/re/.match?(foo)' )
0 commit comments