Skip to content

Commit

Permalink
Fix environment variable handling during tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mvandervoord committed May 8, 2024
1 parent 5e4c533 commit 86fbf4b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions spec/spec_system_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,7 @@ def with_context
############################################################
# Functions for manipulating environment settings during tests:
def backup_env
# Force a deep clone. Hacktacular, but works.

yaml_wrapper = YamlWrapper.new
@_env = yaml_wrapper.load_string(ENV.to_hash.to_yaml)
@_env = ENV.to_hash
end

def reduce_env(destroy_keys=[])
Expand All @@ -123,6 +120,10 @@ def constrain_env

def restore_env
if @_env
# delete environment variables we've added since we started
ENV.to_hash.each_pair {|k,v| ENV.delete(k) unless @_env.include?(k) }

# restore environment variables we've modified since we started
@_env.each_pair {|k,v| ENV[k] = v}
else
raise InvalidBackupEnv.new
Expand Down

0 comments on commit 86fbf4b

Please sign in to comment.