Skip to content

Instantly share code, notes, and snippets.

@jazzytomato
jazzytomato / mock_env.rb
Last active August 29, 2024 13:18
Simple method to mock environment variable in ruby with minitest or other testing framework
# in test_helper.rb (for example)
def mock_env(partial_env_hash)
old = ENV.to_hash
ENV.update partial_env_hash
begin
yield
ensure
ENV.replace old
end
end