aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/generators/actions_test.rb
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-12-06 10:05:45 -0200
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-12-06 10:47:14 -0200
commit5a8f25f003f022ebc6986b20b0c10329e9553dc3 (patch)
treea97409f83f716d822cfea2aaa5a33f4286ee7d71 /railties/test/generators/actions_test.rb
parent8942035f428c1d89219aa7569869b53a42d9a610 (diff)
downloadrails-5a8f25f003f022ebc6986b20b0c10329e9553dc3.tar.gz
rails-5a8f25f003f022ebc6986b20b0c10329e9553dc3.tar.bz2
rails-5a8f25f003f022ebc6986b20b0c10329e9553dc3.zip
Refactor tests that switch RAILS_ENV and RACK_ENV
This cleanup aims to fix a build failure: https://travis-ci.org/rails/rails/jobs/3515951/#L482 Since travis always have both ENV vars set to "test", a test is failing where it's expected to output the default env "development", but "test" is the result due to RACK_ENV being set when we expect it to not be. By cleaning this duplication we ensure that changing any of these env variables will pick the right expected value.
Diffstat (limited to 'railties/test/generators/actions_test.rb')
-rw-r--r--railties/test/generators/actions_test.rb31
1 files changed, 15 insertions, 16 deletions
diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb
index 8af92479c3..54734ed260 100644
--- a/railties/test/generators/actions_test.rb
+++ b/railties/test/generators/actions_test.rb
@@ -1,8 +1,11 @@
require 'generators/generators_test_helper'
require 'rails/generators/rails/app/app_generator'
+require 'env_helpers'
class ActionsTest < Rails::Generators::TestCase
include GeneratorsTestHelper
+ include EnvHelpers
+
tests Rails::Generators::AppGenerator
arguments [destination_root]
@@ -154,10 +157,9 @@ class ActionsTest < Rails::Generators::TestCase
def test_rake_should_run_rake_command_with_default_env
generator.expects(:run).once.with("rake log:clear RAILS_ENV=development", verbose: false)
- old_env, ENV['RAILS_ENV'] = ENV["RAILS_ENV"], nil
- action :rake, 'log:clear'
- ensure
- ENV["RAILS_ENV"] = old_env
+ with_rails_env nil do
+ action :rake, 'log:clear'
+ end
end
def test_rake_with_env_option_should_run_rake_command_in_env
@@ -167,26 +169,23 @@ class ActionsTest < Rails::Generators::TestCase
def test_rake_with_rails_env_variable_should_run_rake_command_in_env
generator.expects(:run).once.with('rake log:clear RAILS_ENV=production', verbose: false)
- old_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "production"
- action :rake, 'log:clear'
- ensure
- ENV["RAILS_ENV"] = old_env
+ with_rails_env "production" do
+ action :rake, 'log:clear'
+ end
end
def test_env_option_should_win_over_rails_env_variable_when_running_rake
generator.expects(:run).once.with('rake log:clear RAILS_ENV=production', verbose: false)
- old_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "staging"
- action :rake, 'log:clear', env: 'production'
- ensure
- ENV["RAILS_ENV"] = old_env
+ with_rails_env "staging" do
+ action :rake, 'log:clear', env: 'production'
+ end
end
def test_rake_with_sudo_option_should_run_rake_command_with_sudo
generator.expects(:run).once.with("sudo rake log:clear RAILS_ENV=development", verbose: false)
- old_env, ENV['RAILS_ENV'] = ENV["RAILS_ENV"], nil
- action :rake, 'log:clear', sudo: true
- ensure
- ENV["RAILS_ENV"] = old_env
+ with_rails_env nil do
+ action :rake, 'log:clear', sudo: true
+ end
end
def test_capify_should_run_the_capify_command