stub_env 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bd3dcd59175a3f2f4d8c53e5821bd3048af59c27
4
- data.tar.gz: 4124553585b236dd096a39a5c3988edfaed3f36a
3
+ metadata.gz: f7631a18685d83296a76f248cba5e0c54fbf4280
4
+ data.tar.gz: 9da6ae5cdac5e23158035a9615016e4dc6d0fb2d
5
5
  SHA512:
6
- metadata.gz: 2cb3a1f829e245317933e557a94eeb1a3b38b221c56c91ad8083c84d577909cdd2f0ca7ad9e4d2f732a8e7b2b4b0c12c91c0f5ddfb271b75dbaa48ebd4d281e0
7
- data.tar.gz: 01db07cd7c308aa90259c1110efefd7c51d6cb9b3b20a289b4946055774eb37ec0e8aebeab942dbe6dc42bf6f4090f0e7de3613d4390a5c621c1f35a2495e727
6
+ metadata.gz: 00efbe5bb2161f8e39ef05f45b84bb3e030ef75fd28515f3200d3812034a12aaabda187d2cb0b204a646a98844b119adf6e516eb19cfbc313d270bdc88f59ab9
7
+ data.tar.gz: d65e5bd27089d1fa764ba0d8df7e81d636c1968f7e0168afb27e5176dcf9f481307cce31e908b78142b63a69ec3f7281dfbb407431f872d78121374f839a78b2
@@ -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
- context 'with a single stubbed variable' do
7
- before :each do
8
- stub_env('TEST', 'success')
9
- end
10
- it 'stubs out environment variables' do
11
- expect(ENV['TEST']).to eq 'success'
12
- expect(ENV.fetch 'TEST').to eq 'success'
13
- end
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
- it 'leaves original environment variables unstubbed' do
16
- expect(ENV['UNSTUBBED']).to eq 'unstubbed'
17
- expect(ENV.fetch 'UNSTUBBED').to eq 'unstubbed'
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
- context 'with multiple stubbed variables' do
22
- before :each do
23
- stub_env('TEST', 'success')
24
- stub_env('TEST2', 'another success')
25
- end
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
- it 'stubs out the first variable' do
28
- expect(ENV['TEST']).to eq 'success'
29
- expect(ENV.fetch 'TEST').to eq 'success'
30
- end
26
+ it 'stubs out the first variable' do
27
+ expect(ENV['TEST']).to eq 'success'
28
+ end
31
29
 
32
- it 'stubs out the second variable' do
33
- expect(ENV['TEST2']).to eq 'another success'
34
- expect(ENV.fetch 'TEST2').to eq 'another success'
35
- end
30
+ it 'stubs out the second variable' do
31
+ expect(ENV['TEST2']).to eq 'another success'
32
+ end
36
33
 
37
- it 'leaves original environment variables unstubbed' do
38
- expect(ENV['UNSTUBBED']).to eq 'unstubbed'
39
- expect(ENV.fetch 'UNSTUBBED').to eq 'unstubbed'
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
- context 'with multiple stubbed variables in a hash' do
44
- before :each do
45
- stub_env({'TEST' => 'success', 'TEST2' => 'another success'})
46
- end
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
- it 'stubs out the first variable' do
49
- expect(ENV['TEST']).to eq 'success'
50
- expect(ENV.fetch 'TEST').to eq 'success'
51
- end
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
- it 'stubs out the second variable' do
54
- expect(ENV['TEST2']).to eq 'another success'
55
- expect(ENV.fetch 'TEST2').to eq 'another success'
52
+ it 'leaves original environment variables unstubbed' do
53
+ expect(ENV['UNSTUBBED']).to eq 'unstubbed'
54
+ end
56
55
  end
57
56
 
58
- it 'leaves original environment variables unstubbed' do
59
- expect(ENV['UNSTUBBED']).to eq 'unstubbed'
60
- expect(ENV.fetch 'UNSTUBBED').to eq 'unstubbed'
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
- context 'with existing environment variables' do
65
- before :each do
66
- ENV['TO_OVERWRITE'] = 'to overwrite'
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
- it 'returns the original value' do
70
- expect(ENV['TO_OVERWRITE']).to eq 'to overwrite'
71
- expect(ENV.fetch 'TO_OVERWRITE').to eq 'to overwrite'
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
- it 'allows the original value to be stubbed' do
75
- stub_env('TO_OVERWRITE', 'overwritten')
76
- expect(ENV['TO_OVERWRITE']).to eq 'overwritten'
77
- expect(ENV.fetch 'TO_OVERWRITE').to eq 'overwritten'
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
- it 'allows the original value to be stubbed with nil' do
81
- stub_env('TO_OVERWRITE', nil)
82
- expect(ENV['TO_OVERWRITE']).to be_nil
83
- expect(ENV.fetch 'TO_OVERWRITE').to be_nil
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = "stub_env"
5
- gem.version = "1.0.3"
5
+ gem.version = "1.0.4"
6
6
 
7
7
  gem.authors = ["Liam Bennett"]
8
8
  gem.email = ["liam@littleowllabs.com"]
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.3
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-06-29 00:00:00.000000000 Z
11
+ date: 2015-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec