diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2017-12-08 13:42:01 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2017-12-08 14:50:27 -0800 |
commit | a50b8ea3503f5642330c1e6b94320115796b4bab (patch) | |
tree | 1fab4db91d54af009c513f2958d90e0d03e797cf | |
parent | cd0283ef29eaa4a8eb9c90d6c2efaccb20012a20 (diff) | |
download | rails-a50b8ea3503f5642330c1e6b94320115796b4bab.tar.gz rails-a50b8ea3503f5642330c1e6b94320115796b4bab.tar.bz2 rails-a50b8ea3503f5642330c1e6b94320115796b4bab.zip |
Set the Rails environment from an environment variable
Option parsing happens too late to have any impact on the Rails
environment. Rails accesses the environment name and memoizes it too
early in the boot process for a commandline option to have any impact on
the database connection, so we'll change this test to set the
environment from an environment variable (and ensure it still works when
running tests with `ruby`)
-rw-r--r-- | railties/lib/rails/test_unit/runner.rb | 5 | ||||
-rw-r--r-- | railties/test/application/test_runner_test.rb | 2 |
2 files changed, 2 insertions, 5 deletions
diff --git a/railties/lib/rails/test_unit/runner.rb b/railties/lib/rails/test_unit/runner.rb index 45e8472f6a..de5744c662 100644 --- a/railties/lib/rails/test_unit/runner.rb +++ b/railties/lib/rails/test_unit/runner.rb @@ -12,11 +12,8 @@ module Rails class << self def attach_before_load_options(opts) - ENV["RAILS_ENV"] = "test" opts.on("--warnings", "-w", "Run with Ruby warnings enabled") {} - opts.on("-e", "--environment ENV", "Run tests in the ENV environment") { |e| - ENV["RAILS_ENV"] = e - } + opts.on("-e", "--environment ENV", "Run tests in the ENV environment") {} end def parse_options(argv) diff --git a/railties/test/application/test_runner_test.rb b/railties/test/application/test_runner_test.rb index 17333b6ac9..a01325fdb8 100644 --- a/railties/test/application/test_runner_test.rb +++ b/railties/test/application/test_runner_test.rb @@ -593,7 +593,7 @@ module ApplicationTests file = create_test_for_env("development") results = Dir.chdir(app_path) { - `ruby -Ilib:test #{file} -e development`.each_line.map { |line| JSON.parse line } + `RAILS_ENV=development ruby -Ilib:test #{file}`.each_line.map { |line| JSON.parse line } } assert_equal 1, results.length failures = results.first["failures"] |