Markus Reiter cbc9e5dd3b tests: re-use with_environment in using_git_env
Proposed by @reitermarkus in
https://github.com/Homebrew/brew/pull/1890#discussion_r97210285.

I made one slight adjustment of preserving the previous date string in
case anything was relying on it.
2017-01-22 19:53:58 +00:00

34 lines
700 B
Ruby

module Test
module Helper
module Env
def copy_env
ENV.to_hash
end
def restore_env(env)
ENV.replace(env)
end
def with_environment(partial_env)
old = copy_env
ENV.update partial_env
yield
ensure
restore_env old
end
def using_git_env
git_env = ["AUTHOR", "COMMITTER"].each_with_object({}) do |role, env|
env["GIT_#{role}_NAME"] = "brew tests"
env["GIT_#{role}_EMAIL"] = "brew-tests@localhost"
env["GIT_#{role}_DATE"] = "Thu May 21 00:04:11 2009 +0100"
end
with_environment(git_env) do
yield
end
end
end
end
end