Skip to content

Instantly share code, notes, and snippets.

@jordanmaguire
Created June 10, 2011 05:43
Show Gist options
  • Save jordanmaguire/1018290 to your computer and use it in GitHub Desktop.
Save jordanmaguire/1018290 to your computer and use it in GitHub Desktop.
Function for stubbing out the Rails.env calls
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
@diedthreetimes
Copy link

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