stub_env 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/stub_env/helpers.rb +3 -0
- data/spec/support/helper_tests.rb +136 -57
- data/stub_env.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7631a18685d83296a76f248cba5e0c54fbf4280
|
4
|
+
data.tar.gz: 9da6ae5cdac5e23158035a9615016e4dc6d0fb2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00efbe5bb2161f8e39ef05f45b84bb3e030ef75fd28515f3200d3812034a12aaabda187d2cb0b204a646a98844b119adf6e516eb19cfbc313d270bdc88f59ab9
|
7
|
+
data.tar.gz: d65e5bd27089d1fa764ba0d8df7e81d636c1968f7e0168afb27e5176dcf9f481307cce31e908b78142b63a69ec3f7281dfbb407431f872d78121374f839a78b2
|
data/lib/stub_env/helpers.rb
CHANGED
@@ -16,6 +16,9 @@ module StubEnv
|
|
16
16
|
def add_stubbed_value(key, value)
|
17
17
|
allow(ENV).to receive(:[]).with(key).and_return(value)
|
18
18
|
allow(ENV).to receive(:fetch).with(key).and_return(value)
|
19
|
+
allow(ENV).to receive(:fetch).with(key, anything()) do |overridden, default_val|
|
20
|
+
value || default_val
|
21
|
+
end
|
19
22
|
end
|
20
23
|
|
21
24
|
def env_stubbed?
|
@@ -3,84 +3,163 @@ shared_examples 'stub_env tests' do
|
|
3
3
|
ENV['UNSTUBBED'] = 'unstubbed'
|
4
4
|
end
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
describe '#[]' do
|
7
|
+
context 'with a single stubbed variable' do
|
8
|
+
before :each do
|
9
|
+
stub_env('TEST', 'success')
|
10
|
+
end
|
11
|
+
it 'stubs out environment variables' do
|
12
|
+
expect(ENV['TEST']).to eq 'success'
|
13
|
+
end
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
it 'leaves original environment variables unstubbed' do
|
16
|
+
expect(ENV['UNSTUBBED']).to eq 'unstubbed'
|
17
|
+
end
|
18
18
|
end
|
19
|
-
end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
20
|
+
context 'with multiple stubbed variables' do
|
21
|
+
before :each do
|
22
|
+
stub_env('TEST', 'success')
|
23
|
+
stub_env('TEST2', 'another success')
|
24
|
+
end
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
26
|
+
it 'stubs out the first variable' do
|
27
|
+
expect(ENV['TEST']).to eq 'success'
|
28
|
+
end
|
31
29
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end
|
30
|
+
it 'stubs out the second variable' do
|
31
|
+
expect(ENV['TEST2']).to eq 'another success'
|
32
|
+
end
|
36
33
|
|
37
|
-
|
38
|
-
|
39
|
-
|
34
|
+
it 'leaves original environment variables unstubbed' do
|
35
|
+
expect(ENV['UNSTUBBED']).to eq 'unstubbed'
|
36
|
+
end
|
40
37
|
end
|
41
|
-
end
|
42
38
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
39
|
+
context 'with multiple stubbed variables in a hash' do
|
40
|
+
before :each do
|
41
|
+
stub_env({'TEST' => 'success', 'TEST2' => 'another success'})
|
42
|
+
end
|
47
43
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
44
|
+
it 'stubs out the first variable' do
|
45
|
+
expect(ENV['TEST']).to eq 'success'
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'stubs out the second variable' do
|
49
|
+
expect(ENV['TEST2']).to eq 'another success'
|
50
|
+
end
|
52
51
|
|
53
|
-
|
54
|
-
|
55
|
-
|
52
|
+
it 'leaves original environment variables unstubbed' do
|
53
|
+
expect(ENV['UNSTUBBED']).to eq 'unstubbed'
|
54
|
+
end
|
56
55
|
end
|
57
56
|
|
58
|
-
|
59
|
-
|
60
|
-
|
57
|
+
context 'with existing environment variables' do
|
58
|
+
before :each do
|
59
|
+
ENV['TO_OVERWRITE'] = 'to overwrite'
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'returns the original value' do
|
63
|
+
expect(ENV['TO_OVERWRITE']).to eq 'to overwrite'
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'allows the original value to be stubbed' do
|
67
|
+
stub_env('TO_OVERWRITE', 'overwritten')
|
68
|
+
expect(ENV['TO_OVERWRITE']).to eq 'overwritten'
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'allows the original value to be stubbed with nil' do
|
72
|
+
stub_env('TO_OVERWRITE', nil)
|
73
|
+
expect(ENV['TO_OVERWRITE']).to be_nil
|
74
|
+
end
|
61
75
|
end
|
62
76
|
end
|
63
77
|
|
64
|
-
|
65
|
-
|
66
|
-
|
78
|
+
describe '#fetch' do
|
79
|
+
context 'with a single stubbed variable' do
|
80
|
+
before :each do
|
81
|
+
stub_env('TEST', 'success')
|
82
|
+
end
|
83
|
+
it 'stubs out environment variables' do
|
84
|
+
expect(ENV.fetch('TEST')).to eq 'success'
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'leaves original environment variables unstubbed' do
|
88
|
+
expect(ENV.fetch('UNSTUBBED')).to eq 'unstubbed'
|
89
|
+
end
|
67
90
|
end
|
68
91
|
|
69
|
-
|
70
|
-
|
71
|
-
|
92
|
+
context 'with multiple stubbed variables' do
|
93
|
+
before :each do
|
94
|
+
stub_env('TEST', 'success')
|
95
|
+
stub_env('TEST2', 'another success')
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'stubs out the first variable' do
|
99
|
+
expect(ENV.fetch('TEST')).to eq 'success'
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'stubs out the second variable' do
|
103
|
+
expect(ENV.fetch('TEST2')).to eq 'another success'
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'leaves original environment variables unstubbed' do
|
107
|
+
expect(ENV.fetch('UNSTUBBED')).to eq 'unstubbed'
|
108
|
+
end
|
72
109
|
end
|
73
110
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
111
|
+
context 'with multiple stubbed variables in a hash' do
|
112
|
+
before :each do
|
113
|
+
stub_env({'TEST' => 'success', 'TEST2' => 'another success'})
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'stubs out the first variable' do
|
117
|
+
expect(ENV.fetch('TEST')).to eq 'success'
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'stubs out the second variable' do
|
121
|
+
expect(ENV.fetch('TEST2')).to eq 'another success'
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'leaves original environment variables unstubbed' do
|
125
|
+
expect(ENV.fetch('UNSTUBBED')).to eq 'unstubbed'
|
126
|
+
end
|
78
127
|
end
|
79
128
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
129
|
+
context 'with existing environment variables' do
|
130
|
+
before :each do
|
131
|
+
ENV['TO_OVERWRITE'] = 'to overwrite'
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'returns the original value' do
|
135
|
+
expect(ENV.fetch('TO_OVERWRITE')).to eq 'to overwrite'
|
136
|
+
end
|
137
|
+
|
138
|
+
context 'stubbed with a value' do
|
139
|
+
it 'allows the original value to be stubbed' do
|
140
|
+
stub_env('TO_OVERWRITE', 'overwritten')
|
141
|
+
expect(ENV.fetch('TO_OVERWRITE')).to eq 'overwritten'
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'returns the stubbed value even if a default is specified' do
|
145
|
+
stub_env('TO_OVERWRITE', 'overwritten')
|
146
|
+
expect(ENV.fetch('TO_OVERWRITE', 'DEFAULT')).to eq 'overwritten'
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
context 'stubbed with nil' do
|
151
|
+
before :each do
|
152
|
+
stub_env('TO_OVERWRITE', nil)
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'returns nil' do
|
156
|
+
expect(ENV.fetch('TO_OVERWRITE')).to be_nil
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'returns the default if specified' do
|
160
|
+
expect(ENV.fetch('TO_OVERWRITE', 'DEFAULT')).to eq 'DEFAULT'
|
161
|
+
end
|
162
|
+
end
|
84
163
|
end
|
85
164
|
end
|
86
165
|
end
|
data/stub_env.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stub_env
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Liam Bennett
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|