Module: Runger::Testing::Helpers
- Defined in:
- lib/runger/testing/helpers.rb
Instance Method Summary collapse
-
#with_env(data) ⇒ Object
Sets the ENV variables to the provided values and restore outside the block.
Instance Method Details
#with_env(data) ⇒ Object
Sets the ENV variables to the provided values and restore outside the block
Also resets Runger.env before and after calling the block to make sure that the values are not cached.
NOTE: to remove the env value, pass nil as the value
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/runger/testing/helpers.rb', line 11 def with_env(data) was_values = [] data.each do |key, val| was_values << [key, ENV.fetch(key, nil)] next ENV.delete(key) if val.nil? ENV[key] = val end # clear cached env values Runger.env.clear yield ensure was_values.each do |(key, val)| next ENV.delete(key) if val.nil? ENV[key] = val end # clear cache again Runger.env.clear end |