summaryrefslogtreecommitdiff
path: root/spec/support/stub_env.rb
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2018-03-29 11:47:54 +0200
committerRémy Coutable <remy@rymai.me>2018-04-23 12:20:30 +0200
commit023d4f6f2f3d88d0966fe01e6ef921fd03a309fe (patch)
tree6aabb650fe2ba200222c57f1a4ac66ff0a9143e8 /spec/support/stub_env.rb
parenteb1cb7bed6951bdda54abd55e86fd793e6954a56 (diff)
downloadgitlab-ce-023d4f6f2f3d88d0966fe01e6ef921fd03a309fe.tar.gz
Move spec helpers/matchers/shared examples/contexts to their relevant folder
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'spec/support/stub_env.rb')
-rw-r--r--spec/support/stub_env.rb36
1 files changed, 0 insertions, 36 deletions
diff --git a/spec/support/stub_env.rb b/spec/support/stub_env.rb
deleted file mode 100644
index 36b90fc68d6..00000000000
--- a/spec/support/stub_env.rb
+++ /dev/null
@@ -1,36 +0,0 @@
-# Inspired by https://github.com/ljkbennett/stub_env/blob/master/lib/stub_env/helpers.rb
-module StubENV
- 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) }
- else
- add_stubbed_value key_or_hash, value
- end
- end
-
- private
-
- STUBBED_KEY = '__STUBBED__'.freeze
-
- def add_stubbed_value(key, value)
- allow(ENV).to receive(:[]).with(key).and_return(value)
- allow(ENV).to receive(:key?).with(key).and_return(true)
- allow(ENV).to receive(:fetch).with(key).and_return(value)
- allow(ENV).to receive(:fetch).with(key, anything()) do |_, default_val|
- value || default_val
- end
- end
-
- def env_stubbed?
- ENV[STUBBED_KEY]
- end
-
- def init_stub
- allow(ENV).to receive(:[]).and_call_original
- allow(ENV).to receive(:key?).and_call_original
- allow(ENV).to receive(:fetch).and_call_original
- add_stubbed_value(STUBBED_KEY, true)
- end
-end