Created
June 10, 2011 05:43
-
-
Save jordanmaguire/1018290 to your computer and use it in GitHub Desktop.
Function for stubbing out the Rails.env calls
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 stub_env(new_env, &block) | |
original_env = Rails.env | |
Rails.instance_variable_set("@_env", ActiveSupport::StringInquirer.new(new_env)) | |
block.call | |
ensure | |
Rails.instance_variable_set("@_env", ActiveSupport::StringInquirer.new(original_env)) | |
end |
Whats wrong with Rails.env= ? It seems cleaner than Rails.instance_variable_set("@_env"). And you get the ActiveSupport::StringInquirer wrapper for free :P
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wouldnt it also be better to have an ensure around the 'block.call'?