From 0eb2d6079ad3deead60e52a9cdfb5668af201a95 Mon Sep 17 00:00:00 2001 From: bogdanvlviv Date: Thu, 14 Sep 2017 12:28:57 +0300 Subject: Invoke rails command inside the railties' test app with TestHelpers::Generation#rails See #30520 --- railties/test/application/loading_test.rb | 4 ++-- railties/test/application/rake_test.rb | 22 +++++++++------------- railties/test/application/server_test.rb | 2 +- 3 files changed, 12 insertions(+), 16 deletions(-) (limited to 'railties') diff --git a/railties/test/application/loading_test.rb b/railties/test/application/loading_test.rb index 11c886e991..de1e240fd3 100644 --- a/railties/test/application/loading_test.rb +++ b/railties/test/application/loading_test.rb @@ -300,7 +300,7 @@ class LoadingTest < ActiveSupport::TestCase end MIGRATION - Dir.chdir(app_path) { `rake db:migrate` } + rails("db:migrate") require "#{rails_root}/config/environment" get "/title" @@ -314,7 +314,7 @@ class LoadingTest < ActiveSupport::TestCase end MIGRATION - Dir.chdir(app_path) { `rake db:migrate` } + rails("db:migrate") get "/body" assert_equal "BODY", last_response.body diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index 918566073d..002774c2e5 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -101,6 +101,7 @@ module ApplicationTests add_to_config <<-RUBY rake_tasks do task do_nothing: :environment do + puts 'There is nothing' end end RUBY @@ -113,10 +114,8 @@ module ApplicationTests raise 'should not be pre-required for rake even eager_load=true' RUBY - Dir.chdir(app_path) do - assert system("bin/rails do_nothing RAILS_ENV=production"), - "should not be pre-required for rake even eager_load=true" - end + output = rails("do_nothing", "RAILS_ENV=production") + assert_match "There is nothing", output end def test_code_statistics_sanity @@ -294,9 +293,8 @@ module ApplicationTests def test_scaffold_tests_pass_by_default rails "generate", "scaffold", "user", "username:string", "password:string" - output = Dir.chdir(app_path) do - `RAILS_ENV=test bin/rails db:migrate test` - end + with_rails_env("test") { rails("db:migrate") } + output = rails("test") assert_match(/7 runs, 9 assertions, 0 failures, 0 errors/, output) assert_no_match(/Errors running/, output) @@ -313,9 +311,8 @@ module ApplicationTests RUBY rails "generate", "scaffold", "user", "username:string", "password:string" - output = Dir.chdir(app_path) do - `RAILS_ENV=test bin/rails db:migrate test` - end + with_rails_env("test") { rails("db:migrate") } + output = rails("test") assert_match(/5 runs, 7 assertions, 0 failures, 0 errors/, output) assert_no_match(/Errors running/, output) @@ -325,9 +322,8 @@ module ApplicationTests rails "generate", "model", "Product" rails "generate", "model", "Cart" rails "generate", "scaffold", "LineItems", "product:references", "cart:belongs_to" - output = Dir.chdir(app_path) do - `RAILS_ENV=test bin/rails db:migrate test` - end + with_rails_env("test") { rails("db:migrate") } + output = rails("test") assert_match(/7 runs, 9 assertions, 0 failures, 0 errors/, output) assert_no_match(/Errors running/, output) diff --git a/railties/test/application/server_test.rb b/railties/test/application/server_test.rb index 6db9a3b9e8..2238f4f63a 100644 --- a/railties/test/application/server_test.rb +++ b/railties/test/application/server_test.rb @@ -42,7 +42,7 @@ module ApplicationTests pid = Process.spawn("#{app_path}/bin/rails server -P tmp/dummy.pid", in: slave, out: slave, err: slave) assert_output("Listening", master) - Dir.chdir(app_path) { system("bin/rails restart") } + rails("restart") assert_output("Restarting", master) assert_output("Inherited", master) -- cgit v1.2.3