Skip to content

Instantly share code, notes, and snippets.

@arturictus
Last active August 29, 2015 14:13
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 arturictus/75052c567379092a3fa2 to your computer and use it in GitHub Desktop.
Save arturictus/75052c567379092a3fa2 to your computer and use it in GitHub Desktop.
Set ENV variables for specific tests
# spec/support/env_helpers.rb
module EnvHelpers
def with_env_vars(vars)
original = ENV.to_hash
vars.each { |k, v| ENV[k] = v }
begin
yield
ensure
ENV.replace(original)
end
end
end
RSpec.configure do |c|
c.include EnvHelpers
end
#Then in any spec you can use this:
# it 'does something with the FOO environment variable' do
# with_env_vars 'FOO' => 'bar' do
# logic that depends upon ENV['FOO'] goes here
# end
# end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment