diff options
| author | Alyssa Ross | 2017-01-21 14:56:58 +0000 |
|---|---|---|
| committer | Alyssa Ross | 2017-01-22 19:52:34 +0000 |
| commit | 6e0f1366b014b285799c9bb9c311c6345bcd666b (patch) | |
| tree | dcb6c2ce7c2845e0576dca9f531d57bca3e0e451 /Library/Homebrew/test/support | |
| parent | 6f305ad3dcd01a21b5c5836339338eeb47a239cf (diff) | |
| download | brew-6e0f1366b014b285799c9bb9c311c6345bcd666b.tar.bz2 | |
tests: extract a common using_git_env method
Diffstat (limited to 'Library/Homebrew/test/support')
| -rw-r--r-- | Library/Homebrew/test/support/helper/env.rb | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/Library/Homebrew/test/support/helper/env.rb b/Library/Homebrew/test/support/helper/env.rb index 904a1d4c7..6c69b335d 100644 --- a/Library/Homebrew/test/support/helper/env.rb +++ b/Library/Homebrew/test/support/helper/env.rb @@ -1,14 +1,32 @@ 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 = ENV.to_hash + old = copy_env ENV.update partial_env - begin - yield - ensure - ENV.replace old + yield + ensure + restore_env old + 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" end + yield + ensure + restore_env initial_env end end end |
