forked from rails/rails
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
8942035
commit 5a8f25f
Showing
6 changed files
with
63 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ | |
require 'fileutils' | ||
|
||
require 'active_support' | ||
|
||
require 'action_controller' | ||
require 'rails/all' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module EnvHelpers | ||
private | ||
|
||
def with_rails_env(env) | ||
switch_env 'RAILS_ENV', env do | ||
switch_env 'RACK_ENV', nil do | ||
yield | ||
end | ||
end | ||
end | ||
|
||
def with_rack_env(env) | ||
switch_env 'RACK_ENV', env do | ||
switch_env 'RAILS_ENV', nil do | ||
yield | ||
end | ||
end | ||
end | ||
|
||
def switch_env(key, value) | ||
old, ENV[key] = ENV[key], value | ||
yield | ||
ensure | ||
ENV[key] = old | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters