Last active
October 27, 2021 16:32
-
-
Save odlp/40f83c8d1e394d97b558dde606d4bbb7 to your computer and use it in GitHub Desktop.
Modifying the test environment temporarily
This file contains hidden or 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
module EnvironmentHelper | |
def with_environment(replacement_env) | |
original_env = ENV.to_hash | |
ENV.update(replacement_env) | |
yield | |
ensure | |
ENV.replace(original_env) | |
end | |
end |
This file contains hidden or 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
include EnvironmentHelper | |
puts "Before: #{ENV.fetch("FOO")}" | |
with_environment("FOO" => "baz") do | |
puts "During: #{ENV.fetch("FOO")}" | |
end | |
puts "After: #{ENV.fetch("FOO")}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment