Last active
August 29, 2015 14:13
-
-
Save arturictus/75052c567379092a3fa2 to your computer and use it in GitHub Desktop.
Set ENV variables for specific tests
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
# 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