stub_env 1.0.2 → 1.0.3

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: ff78442a66831a3a0a0ca6657bb8489eb3098d38
4
- data.tar.gz: 520c3211c60a8299589ec7b937a4ecc20c08c615
3
+ metadata.gz: bd3dcd59175a3f2f4d8c53e5821bd3048af59c27
4
+ data.tar.gz: 4124553585b236dd096a39a5c3988edfaed3f36a
5
5
  SHA512:
6
- metadata.gz: ce3b7573a796e36e877b95ddce3f6d3d299e6a2b455fb68ea2d4bb2c6ec607ea0746f4fe5474d7d45126e5224f84cf9334337f66529f643bf7127825892dc323
7
- data.tar.gz: cbb46d8543690778085002f489b82b6289294e49785ac8c153c50f36b21e9644092ac3ffe8cf7376c145ee36dd8c115ed7b8e968022cef20cd1390111f664ab5
6
+ metadata.gz: 2cb3a1f829e245317933e557a94eeb1a3b38b221c56c91ad8083c84d577909cdd2f0ca7ad9e4d2f732a8e7b2b4b0c12c91c0f5ddfb271b75dbaa48ebd4d281e0
7
+ data.tar.gz: 01db07cd7c308aa90259c1110efefd7c51d6cb9b3b20a289b4946055774eb37ec0e8aebeab942dbe6dc42bf6f4090f0e7de3613d4390a5c621c1f35a2495e727
data/README.md CHANGED
@@ -10,13 +10,13 @@ This project provides a simple helper method to stub ENV values within RSpec tes
10
10
 
11
11
  To start using it, install the gem in your project in the test group.
12
12
 
13
- ```
13
+ ```ruby
14
14
  gem 'stub_env'
15
15
  ```
16
16
 
17
17
  Then add the following to your rails_config.rb
18
18
 
19
- ```
19
+ ```ruby
20
20
  RSpec.configure do |config|
21
21
  config.include StubEnv::Helpers
22
22
  end
@@ -24,7 +24,7 @@ end
24
24
 
25
25
  There are 2 possible usages. The first is to stub a single value:
26
26
 
27
- ```
27
+ ```ruby
28
28
  stub_env('key', 'value')
29
29
 
30
30
  puts ENV['key'] # => "value"
@@ -32,7 +32,7 @@ There are 2 possible usages. The first is to stub a single value:
32
32
 
33
33
  These will work in series, so you can stub multiple values by making multiple calls:
34
34
 
35
- ```
35
+ ```ruby
36
36
  stub_env('key1', 'value1')
37
37
  stub_env('key2', 'value2')
38
38
 
@@ -42,7 +42,7 @@ These will work in series, so you can stub multiple values by making multiple ca
42
42
 
43
43
  The second method is to stub multiple values using a hash:
44
44
 
45
- ```
45
+ ```ruby
46
46
  stub_env({'key' => 'value', 'key2' => 'value2'})
47
47
 
48
48
  puts ENV['key1'] # => "value1"
@@ -51,7 +51,7 @@ The second method is to stub multiple values using a hash:
51
51
 
52
52
  You can also use this multiple times, and in combination with the other method:
53
53
 
54
- ```
54
+ ```ruby
55
55
  stub_env({'key1' => 'value1', 'key2' => 'value2'})
56
56
  stub_env('key3', 'value3')
57
57
  stub_env({'key4' => 'value4'})
@@ -64,11 +64,11 @@ You can also use this multiple times, and in combination with the other method:
64
64
 
65
65
  All ENV values not stubbed will return their original values.
66
66
 
67
- ```
67
+ ```ruby
68
68
  # Given ENV['unstubbed_key'] = 'unstubbed_value'
69
69
  stub_env('key', 'value')
70
70
 
71
71
  puts ENV['key'] # => "value"
72
72
  puts ENV['unstubbed_key'] # => "unstubbed_value"
73
73
 
74
- ```
74
+ ```
@@ -15,6 +15,7 @@ module StubEnv
15
15
 
16
16
  def add_stubbed_value(key, value)
17
17
  allow(ENV).to receive(:[]).with(key).and_return(value)
18
+ allow(ENV).to receive(:fetch).with(key).and_return(value)
18
19
  end
19
20
 
20
21
  def env_stubbed?
@@ -23,6 +24,7 @@ module StubEnv
23
24
 
24
25
  def init_stub
25
26
  allow(ENV).to receive(:[]).and_call_original
27
+ allow(ENV).to receive(:fetch).and_call_original
26
28
  add_stubbed_value(STUBBED_KEY, true)
27
29
  end
28
30
  end
@@ -9,10 +9,12 @@ shared_examples 'stub_env tests' do
9
9
  end
10
10
  it 'stubs out environment variables' do
11
11
  expect(ENV['TEST']).to eq 'success'
12
+ expect(ENV.fetch 'TEST').to eq 'success'
12
13
  end
13
14
 
14
15
  it 'leaves original environment variables unstubbed' do
15
16
  expect(ENV['UNSTUBBED']).to eq 'unstubbed'
17
+ expect(ENV.fetch 'UNSTUBBED').to eq 'unstubbed'
16
18
  end
17
19
  end
18
20
 
@@ -24,14 +26,17 @@ shared_examples 'stub_env tests' do
24
26
 
25
27
  it 'stubs out the first variable' do
26
28
  expect(ENV['TEST']).to eq 'success'
29
+ expect(ENV.fetch 'TEST').to eq 'success'
27
30
  end
28
31
 
29
32
  it 'stubs out the second variable' do
30
33
  expect(ENV['TEST2']).to eq 'another success'
34
+ expect(ENV.fetch 'TEST2').to eq 'another success'
31
35
  end
32
36
 
33
37
  it 'leaves original environment variables unstubbed' do
34
38
  expect(ENV['UNSTUBBED']).to eq 'unstubbed'
39
+ expect(ENV.fetch 'UNSTUBBED').to eq 'unstubbed'
35
40
  end
36
41
  end
37
42
 
@@ -42,34 +47,40 @@ shared_examples 'stub_env tests' do
42
47
 
43
48
  it 'stubs out the first variable' do
44
49
  expect(ENV['TEST']).to eq 'success'
50
+ expect(ENV.fetch 'TEST').to eq 'success'
45
51
  end
46
52
 
47
53
  it 'stubs out the second variable' do
48
54
  expect(ENV['TEST2']).to eq 'another success'
55
+ expect(ENV.fetch 'TEST2').to eq 'another success'
49
56
  end
50
57
 
51
58
  it 'leaves original environment variables unstubbed' do
52
59
  expect(ENV['UNSTUBBED']).to eq 'unstubbed'
60
+ expect(ENV.fetch 'UNSTUBBED').to eq 'unstubbed'
53
61
  end
54
62
  end
55
63
 
56
- describe 'with existing environment variables' do
64
+ context 'with existing environment variables' do
57
65
  before :each do
58
66
  ENV['TO_OVERWRITE'] = 'to overwrite'
59
67
  end
60
68
 
61
69
  it 'returns the original value' do
62
70
  expect(ENV['TO_OVERWRITE']).to eq 'to overwrite'
71
+ expect(ENV.fetch 'TO_OVERWRITE').to eq 'to overwrite'
63
72
  end
64
73
 
65
74
  it 'allows the original value to be stubbed' do
66
75
  stub_env('TO_OVERWRITE', 'overwritten')
67
76
  expect(ENV['TO_OVERWRITE']).to eq 'overwritten'
77
+ expect(ENV.fetch 'TO_OVERWRITE').to eq 'overwritten'
68
78
  end
69
79
 
70
80
  it 'allows the original value to be stubbed with nil' do
71
81
  stub_env('TO_OVERWRITE', nil)
72
82
  expect(ENV['TO_OVERWRITE']).to be_nil
83
+ expect(ENV.fetch 'TO_OVERWRITE').to be_nil
73
84
  end
74
85
  end
75
86
  end
data/stub_env.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = "stub_env"
5
- gem.version = "1.0.2"
5
+ gem.version = "1.0.3"
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.2
4
+ version: 1.0.3
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-04-15 00:00:00.000000000 Z
11
+ date: 2015-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec