Skip to content

Instantly share code, notes, and snippets.

@jordanmaguire
Created June 10, 2011 05:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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
@vraravam
Copy link

Wouldnt it also be better to have an ensure around the 'block.call'?

@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