Created
March 29, 2013 10:47
-
-
Save kabturek/5270159 to your computer and use it in GitHub Desktop.
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
def setup_env(env, environments) | |
Rails.stub(:env).and_return(env) | |
Rails.env.stub("#{env}?".to_sym).and_return(true) | |
environments.map { |e| Rails.env.stub("#{e}?".to_sym).and_return(false) } | |
end | |
def stub_env(new_environment, environments = ["test", "development", "staging", "production"], &block) | |
original_environment = Rails.env | |
environments.delete(new_environment) | |
setup_env(new_environment, environments) | |
block.call | |
ensure | |
environments.delete(original_environment) | |
environments += [new_environment] | |
setup_env(original_environment, environments) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment