diff options
| author | Misty De Meo | 2017-07-13 17:14:21 -0700 |
|---|---|---|
| committer | Misty De Meo | 2017-07-15 17:39:55 -0700 |
| commit | 30adcab6cfc18c13eae3a2cc7d6486c812162d57 (patch) | |
| tree | 1eeb9209338f0be2d16626a095d25a526b293652 /Library/Homebrew/test/utils_spec.rb | |
| parent | 4ca2efb12dd1399526e0aa845b56ede58daecddd (diff) | |
| download | brew-30adcab6cfc18c13eae3a2cc7d6486c812162d57.tar.bz2 | |
Add `with_env` helper to set temporary ENV vars
Diffstat (limited to 'Library/Homebrew/test/utils_spec.rb')
| -rw-r--r-- | Library/Homebrew/test/utils_spec.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/Library/Homebrew/test/utils_spec.rb b/Library/Homebrew/test/utils_spec.rb index f3bf98486..37bd83c4f 100644 --- a/Library/Homebrew/test/utils_spec.rb +++ b/Library/Homebrew/test/utils_spec.rb @@ -270,4 +270,30 @@ describe "globally-scoped helper methods" do }.to raise_error(MethodDeprecatedError, %r{method.*replacement.*homebrew/homebrew-core.*homebrew/core}m) end end + + describe "#with_env" do + it "sets environment variables within the block" do + expect(ENV["PATH"]).not_to eq("/bin") + with_env "PATH" => "/bin" do + expect(ENV["PATH"]).to eq("/bin") + end + end + + it "restores ENV after the block" do + with_env "PATH" => "/bin" do + expect(ENV["PATH"]).to eq("/bin") + end + expect(ENV["PATH"]).not_to eq("/bin") + end + + it "restores ENV if an exception is raised" do + expect { + with_env "PATH" => "/bin" do + raise StandardError, "boom" + end + }.to raise_error(StandardError) + + expect(ENV["PATH"]).not_to eq("/bin") + end + end end |
