summaryrefslogtreecommitdiff
path: root/spec/support/helpers/stub_env.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support/helpers/stub_env.rb')
-rw-r--r--spec/support/helpers/stub_env.rb18
1 files changed, 16 insertions, 2 deletions
diff --git a/spec/support/helpers/stub_env.rb b/spec/support/helpers/stub_env.rb
index 5f344f8fb52..afa501d6279 100644
--- a/spec/support/helpers/stub_env.rb
+++ b/spec/support/helpers/stub_env.rb
@@ -2,13 +2,23 @@
# Inspired by https://github.com/ljkbennett/stub_env/blob/master/lib/stub_env/helpers.rb
module StubENV
+ # Stub ENV variables
+ #
+ # You can provide either a key and value as separate params or both in a Hash format
+ #
+ # Keys and values will always be converted to String, to comply with how ENV behaves
+ #
+ # @param key_or_hash [String, Hash<String,String>]
+ # @param value [String]
def stub_env(key_or_hash, value = nil)
init_stub unless env_stubbed?
if key_or_hash.is_a? Hash
- key_or_hash.each { |k, v| add_stubbed_value(k, v) }
+ key_or_hash.each do |key, value|
+ add_stubbed_value(key, ensure_env_type(value))
+ end
else
- add_stubbed_value key_or_hash, value
+ add_stubbed_value key_or_hash, ensure_env_type(value)
end
end
@@ -35,4 +45,8 @@ module StubENV
allow(ENV).to receive(:fetch).and_call_original
add_stubbed_value(STUBBED_KEY, true)
end
+
+ def ensure_env_type(value)
+ value.nil? ? value : value.to_s
+ end
end