Skip to content

Commit

Permalink
Refactor with_env method
Browse files Browse the repository at this point in the history
  • Loading branch information
shinokaro committed Aug 4, 2024
1 parent cfb6d22 commit 6d7710f
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions test/test_ocra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,12 @@ def with_fixture(name, target_path = nil)
# block. When the block exits, the environment variables are set
# back to their original values.
def with_env(hash)
old = {}
hash.each do |k,v|
old[k] = ENV[k]
ENV[k] = v
end
old = ENV.except(hash.keys)
ENV.update(hash)
begin
yield
ensure
hash.each do |k,v|
ENV[k] = old[k]
end
ENV.update(old)
end
end

Expand Down

0 comments on commit 6d7710f

Please sign in to comment.