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.
This commit is contained in:
Markus Reiter 2017-01-22 11:10:06 +00:00 committed by Alyssa Ross
parent 1e1de8c111
commit cbc9e5dd3b

View File

@ -18,15 +18,15 @@ module Test
end
def using_git_env
initial_env = copy_env
%w[AUTHOR COMMITTER].each do |role|
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"
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
yield
ensure
restore_env initial_env
end
end
end