@@ -307,13 +307,13 @@ def test_environment_should_include_block_contents_with_multiline_data_in_enviro
307
307
end
308
308
309
309
def test_git_with_symbol_should_run_command_using_git_scm
310
- assert_called_with ( generator , :run , [ "git init" ] ) do
310
+ assert_runs "git init" , nil do
311
311
action :git , :init
312
312
end
313
313
end
314
314
315
315
def test_git_with_hash_should_run_each_command_using_git_scm
316
- assert_called_with ( generator , :run , [ [ "git rm README" ] , [ "git add ." ] ] ) do
316
+ assert_runs [ "git rm README" , "git add ." ] , nil do
317
317
action :git , rm : "README" , add : "."
318
318
end
319
319
end
@@ -396,98 +396,88 @@ def test_generate_aborts_when_subprocess_fails_if_requested
396
396
assert_no_file "app/models/my_model.rb"
397
397
end
398
398
399
- def test_generate_should_run_command_without_env
400
- assert_called_with ( generator , :run , [ "rails generate model MyModel name:string" , verbose : false ] ) do
401
- action :generate , "model" , "MyModel" , "name:string"
402
- end
403
- end
404
-
405
- def test_rake_should_run_rake_command_with_default_env
406
- assert_called_with ( generator , :run , [ "rake log:clear RAILS_ENV=development" , verbose : false ] ) do
399
+ test "rake should run rake with the default environment" do
400
+ assert_runs "rake log:clear" , env : { "RAILS_ENV" => "development" } do
407
401
with_rails_env nil do
408
402
action :rake , "log:clear"
409
403
end
410
404
end
411
405
end
412
406
413
- def test_rake_with_env_option_should_run_rake_command_in_env
414
- assert_called_with ( generator , :run , [ "rake log:clear RAILS_ENV= production" , verbose : false ] ) do
407
+ test "rake with env option should run rake with the env environment" do
408
+ assert_runs "rake log:clear" , env : { " RAILS_ENV" => " production" } do
415
409
action :rake , "log:clear" , env : "production"
416
410
end
417
411
end
418
412
419
- test "rake with RAILS_ENV variable should run rake command in env " do
420
- assert_called_with ( generator , :run , [ "rake log:clear RAILS_ENV= production" , verbose : false ] ) do
413
+ test "rake with RAILS_ENV set should run rake with the RAILS_ENV environment " do
414
+ assert_runs "rake log:clear" , env : { " RAILS_ENV" => " production" } do
421
415
with_rails_env "production" do
422
416
action :rake , "log:clear"
423
417
end
424
418
end
425
419
end
426
420
427
- test "env option should win over RAILS_ENV variable when running rake" do
428
- assert_called_with ( generator , :run , [ "rake log:clear RAILS_ENV= production" , verbose : false ] ) do
421
+ test "rake with env option and RAILS_ENV set should run rake with the env environment " do
422
+ assert_runs "rake log:clear" , env : { " RAILS_ENV" => " production" } do
429
423
with_rails_env "staging" do
430
424
action :rake , "log:clear" , env : "production"
431
425
end
432
426
end
433
427
end
434
428
435
- test "rake with sudo option should run rake command with sudo" do
436
- assert_called_with ( generator , :run , [ "sudo rake log:clear RAILS_ENV=development" , verbose : false ] ) do
437
- with_rails_env nil do
438
- action :rake , "log:clear" , sudo : true
439
- end
429
+ test "rake with sudo option should run rake with sudo" do
430
+ assert_runs "sudo rake log:clear" do
431
+ action :rake , "log:clear" , sudo : true
440
432
end
441
433
end
442
434
443
- test "rake command with capture option should run rake command with capture" do
444
- assert_called_with ( generator , :run , [ "rake log:clear RAILS_ENV=development" , verbose : false , capture : true ] ) do
445
- with_rails_env nil do
446
- action :rake , "log:clear" , capture : true
447
- end
435
+ test "rake with capture option should run rake with capture" do
436
+ assert_runs "rake log:clear" , capture : true do
437
+ action :rake , "log:clear" , capture : true
448
438
end
449
439
end
450
440
451
- test "rails command should run rails_command with default env " do
452
- assert_called_with ( generator , :run , [ "rails log:clear RAILS_ENV= development" , verbose : false ] ) do
441
+ test "rails_command should run rails with the default environment " do
442
+ assert_runs "rails log:clear" , env : { " RAILS_ENV" => " development" } do
453
443
with_rails_env nil do
454
444
action :rails_command , "log:clear"
455
445
end
456
446
end
457
447
end
458
448
459
- test "rails command with env option should run rails_command with same env" do
460
- assert_called_with ( generator , :run , [ "rails log:clear RAILS_ENV= production" , verbose : false ] ) do
449
+ test "rails_command with env option should run rails with the env environment " do
450
+ assert_runs "rails log:clear" , env : { " RAILS_ENV" => " production" } do
461
451
action :rails_command , "log:clear" , env : "production"
462
452
end
463
453
end
464
454
465
- test "rails command with RAILS_ENV variable should run rails_command in env " do
466
- assert_called_with ( generator , :run , [ "rails log:clear RAILS_ENV= production" , verbose : false ] ) do
455
+ test "rails_command with RAILS_ENV set should run rails with the RAILS_ENV environment " do
456
+ assert_runs "rails log:clear" , env : { " RAILS_ENV" => " production" } do
467
457
with_rails_env "production" do
468
458
action :rails_command , "log:clear"
469
459
end
470
460
end
471
461
end
472
462
473
- def test_env_option_should_win_over_rails_env_variable_when_running_rails
474
- assert_called_with ( generator , :run , [ "rails log:clear RAILS_ENV= production" , verbose : false ] ) do
463
+ test "rails_command with env option and RAILS_ENV set should run rails with the env environment" do
464
+ assert_runs "rails log:clear" , env : { " RAILS_ENV" => " production" } do
475
465
with_rails_env "staging" do
476
466
action :rails_command , "log:clear" , env : "production"
477
467
end
478
468
end
479
469
end
480
470
481
- test "rails command with sudo option should run rails_command with sudo" do
482
- assert_called_with ( generator , :run , [ "sudo rails log:clear RAILS_ENV=development" , verbose : false ] ) do
471
+ test "rails_command with sudo option should run rails with sudo" do
472
+ assert_runs "sudo rails log:clear" do
483
473
with_rails_env nil do
484
474
action :rails_command , "log:clear" , sudo : true
485
475
end
486
476
end
487
477
end
488
478
489
- test "rails command with capture option should run rails_command with capture" do
490
- assert_called_with ( generator , :run , [ "rails log:clear RAILS_ENV=development " , verbose : false , capture : true ] ) do
479
+ test "rails_command with capture option should run rails with capture" do
480
+ assert_runs "rails log:clear" , capture : true do
491
481
with_rails_env nil do
492
482
action :rails_command , "log:clear" , capture : true
493
483
end
@@ -587,6 +577,17 @@ def action(*args, &block)
587
577
capture ( :stdout ) { generator . send ( *args , &block ) }
588
578
end
589
579
580
+ def assert_runs ( commands , config = { } , &block )
581
+ config_matcher = -> ( actual_config ) do
582
+ assert_equal config , actual_config . slice ( *config . keys )
583
+ end if config
584
+ args = Array ( commands ) . map { |command | [ command , *config_matcher ] }
585
+
586
+ assert_called_with ( generator , :run , args ) do
587
+ block . call
588
+ end
589
+ end
590
+
590
591
def assert_routes ( *route_commands )
591
592
route_regexps = route_commands . flatten . map do |route_command |
592
593
%r{
0 commit comments