@@ -9,6 +9,13 @@ def setup
99 @app . options . rakelib = [ ]
1010 end
1111
12+ def setup_command_line ( *options )
13+ ARGV . clear
14+ options . each do |option |
15+ ARGV << option
16+ end
17+ end
18+
1219 def test_display_tasks
1320 @app . options . show_tasks = :tasks
1421 @app . options . show_task_pattern = //
@@ -193,6 +200,7 @@ def test_load_rakefile_doesnt_print_rakefile_directory_from_subdir_if_silent
193200 end
194201
195202 def test_load_rakefile_not_found
203+ ARGV . clear
196204 Dir . chdir @tempdir
197205 ENV [ 'RAKE_SYSTEM' ] = 'not_exist'
198206
@@ -201,8 +209,11 @@ def test_load_rakefile_not_found
201209 options . silent = true
202210 end
203211
212+
204213 ex = assert_raises ( RuntimeError ) do
205- @app . instance_eval do raw_load_rakefile end
214+ @app . instance_eval do
215+ raw_load_rakefile
216+ end
206217 end
207218
208219 assert_match ( /no rakefile found/i , ex . message )
@@ -295,8 +306,7 @@ def test_handle_options_should_strip_options_from_argv
295306 assert !@app . options . trace
296307
297308 valid_option = '--trace'
298- ARGV . clear
299- ARGV << valid_option
309+ setup_command_line ( valid_option )
300310
301311 @app . handle_options
302312
@@ -305,8 +315,7 @@ def test_handle_options_should_strip_options_from_argv
305315 end
306316
307317 def test_handle_options_trace_default_is_stderr
308- ARGV . clear
309- ARGV << "--trace"
318+ setup_command_line ( "--trace" )
310319
311320 @app . handle_options
312321
@@ -315,8 +324,7 @@ def test_handle_options_trace_default_is_stderr
315324 end
316325
317326 def test_handle_options_trace_overrides_to_stdout
318- ARGV . clear
319- ARGV << "--trace=stdout"
327+ setup_command_line ( "--trace=stdout" )
320328
321329 @app . handle_options
322330
@@ -327,8 +335,7 @@ def test_handle_options_trace_overrides_to_stdout
327335 def test_handle_options_trace_does_not_eat_following_task_names
328336 assert !@app . options . trace
329337
330- ARGV . clear
331- ARGV << "--trace" << "sometask"
338+ setup_command_line ( "--trace" , "sometask" )
332339
333340 @app . handle_options
334341 assert ARGV . include? ( "sometask" )
@@ -359,8 +366,7 @@ def test_good_run
359366
360367 def test_display_task_run
361368 ran = false
362- ARGV . clear
363- ARGV << '-f' << '-s' << '--tasks' << '--rakelib=""'
369+ setup_command_line ( '-f' , '-s' , '--tasks' , '--rakelib=""' )
364370 @app . last_description = "COMMENT"
365371 @app . define_task ( Rake ::Task , "default" )
366372 out , = capture_io { @app . run }
@@ -372,8 +378,7 @@ def test_display_task_run
372378
373379 def test_display_prereqs
374380 ran = false
375- ARGV . clear
376- ARGV << '-f' << '-s' << '--prereqs' << '--rakelib=""'
381+ setup_command_line ( '-f' , '-s' , '--prereqs' , '--rakelib=""' )
377382 @app . last_description = "COMMENT"
378383 t = @app . define_task ( Rake ::Task , "default" )
379384 t . enhance ( [ :a , :b ] )
@@ -389,8 +394,7 @@ def test_display_prereqs
389394
390395 def test_bad_run
391396 @app . intern ( Rake ::Task , "default" ) . enhance { fail }
392- ARGV . clear
393- ARGV << '-f' << '-s' << '--rakelib=""'
397+ setup_command_line ( '-f' , '-s' , '--rakelib=""' )
394398 _ , err = capture_io {
395399 assert_raises ( SystemExit ) { @app . run }
396400 }
@@ -401,8 +405,7 @@ def test_bad_run
401405
402406 def test_bad_run_with_trace
403407 @app . intern ( Rake ::Task , "default" ) . enhance { fail }
404- ARGV . clear
405- ARGV << '-f' << '-s' << '-t'
408+ setup_command_line ( '-f' , '-s' , '-t' )
406409 _ , err = capture_io {
407410 assert_raises ( SystemExit ) { @app . run }
408411 }
@@ -413,8 +416,7 @@ def test_bad_run_with_trace
413416
414417 def test_bad_run_with_backtrace
415418 @app . intern ( Rake ::Task , "default" ) . enhance { fail }
416- ARGV . clear
417- ARGV << '-f' << '-s' << '--backtrace'
419+ setup_command_line ( '-f' , '-s' , '--backtrace' )
418420 _ , err = capture_io {
419421 assert_raises ( SystemExit ) {
420422 @app . run
@@ -431,8 +433,7 @@ def test_bad_run_includes_exception_name
431433 @app . intern ( Rake ::Task , "default" ) . enhance {
432434 raise CustomError , "intentional"
433435 }
434- ARGV . clear
435- ARGV << '-f' << '-s'
436+ setup_command_line ( '-f' , '-s' )
436437 _ , err = capture_io {
437438 assert_raises ( SystemExit ) {
438439 @app . run
@@ -445,8 +446,7 @@ def test_rake_error_excludes_exception_name
445446 @app . intern ( Rake ::Task , "default" ) . enhance {
446447 fail "intentional"
447448 }
448- ARGV . clear
449- ARGV << '-f' << '-s'
449+ setup_command_line ( '-f' , '-s' )
450450 _ , err = capture_io {
451451 assert_raises ( SystemExit ) {
452452 @app . run
@@ -470,8 +470,7 @@ def test_printing_original_exception_cause
470470 raise custom_error , "Secondary Error"
471471 end
472472 }
473- ARGV . clear
474- ARGV << '-f' << '-s'
473+ setup_command_line ( '-f' , '-s' )
475474 _ , err = capture_io {
476475 assert_raises ( SystemExit ) {
477476 @app . run
@@ -487,8 +486,7 @@ def test_printing_original_exception_cause
487486
488487 def test_run_with_bad_options
489488 @app . intern ( Rake ::Task , "default" ) . enhance { fail }
490- ARGV . clear
491- ARGV << '-f' << '-s' << '--xyzzy'
489+ setup_command_line ( '-f' , '-s' , '--xyzzy' )
492490 assert_raises ( SystemExit ) {
493491 capture_io { @app . run }
494492 }
0 commit comments