lib/runger/testing/helpers.rb in runger_config-4.0.0 vs lib/runger/testing/helpers.rb in runger_config-5.0.0
- old
+ new
@@ -1,36 +1,34 @@
# frozen_string_literal: true
-module Runger
- module Testing
- module Helpers
- # 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
- def with_env(data)
- was_values = []
+module Runger::Testing::Helpers
+ # 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
+ def with_env(data)
+ was_values = []
- data.each do |key, val|
- was_values << [key, ENV[key]]
- next ENV.delete(key) if val.nil?
- ENV[key] = val
- end
+ data.each do |key, val|
+ was_values << [key, ENV.fetch(key, nil)]
+ next ENV.delete(key) if val.nil?
- # 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
+ ENV[key] = val
+ end
- # clear cache again
- Runger.env.clear
- 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
end