stub_env 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/stub_env/helpers.rb +7 -9
- data/spec/stub_env/helpers_spec.rb +7 -12
- data/spec/support/helper_tests.rb +25 -1
- 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: ff78442a66831a3a0a0ca6657bb8489eb3098d38
|
4
|
+
data.tar.gz: 520c3211c60a8299589ec7b937a4ecc20c08c615
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce3b7573a796e36e877b95ddce3f6d3d299e6a2b455fb68ea2d4bb2c6ec607ea0746f4fe5474d7d45126e5224f84cf9334337f66529f643bf7127825892dc323
|
7
|
+
data.tar.gz: cbb46d8543690778085002f489b82b6289294e49785ac8c153c50f36b21e9644092ac3ffe8cf7376c145ee36dd8c115ed7b8e968022cef20cd1390111f664ab5
|
data/lib/stub_env/helpers.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
module StubEnv
|
2
2
|
module Helpers
|
3
|
-
|
4
|
-
def stub_env key_or_hash, value=nil
|
3
|
+
def stub_env(key_or_hash, value = nil)
|
5
4
|
init_stub unless env_stubbed?
|
6
|
-
if
|
7
|
-
|
5
|
+
if key_or_hash.is_a? Hash
|
6
|
+
key_or_hash.each { |k, v| add_stubbed_value(k, v) }
|
8
7
|
else
|
9
|
-
|
8
|
+
add_stubbed_value key_or_hash, value
|
10
9
|
end
|
11
10
|
end
|
12
11
|
|
@@ -14,8 +13,8 @@ module StubEnv
|
|
14
13
|
|
15
14
|
STUBBED_KEY = '__STUBBED__'
|
16
15
|
|
17
|
-
def add_stubbed_value
|
18
|
-
allow(ENV).to receive(:[]).with(key).and_return(value)
|
16
|
+
def add_stubbed_value(key, value)
|
17
|
+
allow(ENV).to receive(:[]).with(key).and_return(value)
|
19
18
|
end
|
20
19
|
|
21
20
|
def env_stubbed?
|
@@ -26,6 +25,5 @@ module StubEnv
|
|
26
25
|
allow(ENV).to receive(:[]).and_call_original
|
27
26
|
add_stubbed_value(STUBBED_KEY, true)
|
28
27
|
end
|
29
|
-
|
30
28
|
end
|
31
|
-
end
|
29
|
+
end
|
@@ -1,27 +1,22 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe StubEnv::Helpers do
|
4
4
|
include described_class
|
5
|
-
|
6
|
-
before :each do
|
7
|
-
ENV['UNSTUBBED'] = 'unstubbed'
|
8
|
-
end
|
9
|
-
|
10
|
-
describe "#stub_env" do
|
11
5
|
|
6
|
+
describe '#stub_env' do
|
12
7
|
include_examples 'stub_env tests'
|
13
8
|
|
14
|
-
|
15
|
-
|
16
|
-
|
9
|
+
methods = RSpec::Mocks::Configuration.public_instance_methods
|
10
|
+
if methods.include?(:verify_partial_doubles=)
|
11
|
+
context 'with the verify partial doubles option set' do
|
17
12
|
before :each do
|
18
13
|
RSpec.configuration.mock_with :rspec do |mocks|
|
19
14
|
mocks.verify_partial_doubles = true
|
20
15
|
end
|
21
16
|
end
|
22
17
|
|
23
|
-
include_examples 'stub_env tests'
|
18
|
+
include_examples 'stub_env tests'
|
24
19
|
end
|
25
20
|
end
|
26
21
|
end
|
27
|
-
end
|
22
|
+
end
|
@@ -1,4 +1,8 @@
|
|
1
1
|
shared_examples 'stub_env tests' do
|
2
|
+
before :each do
|
3
|
+
ENV['UNSTUBBED'] = 'unstubbed'
|
4
|
+
end
|
5
|
+
|
2
6
|
context 'with a single stubbed variable' do
|
3
7
|
before :each do
|
4
8
|
stub_env('TEST', 'success')
|
@@ -48,4 +52,24 @@ shared_examples 'stub_env tests' do
|
|
48
52
|
expect(ENV['UNSTUBBED']).to eq 'unstubbed'
|
49
53
|
end
|
50
54
|
end
|
51
|
-
|
55
|
+
|
56
|
+
describe 'with existing environment variables' do
|
57
|
+
before :each do
|
58
|
+
ENV['TO_OVERWRITE'] = 'to overwrite'
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'returns the original value' do
|
62
|
+
expect(ENV['TO_OVERWRITE']).to eq 'to overwrite'
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'allows the original value to be stubbed' do
|
66
|
+
stub_env('TO_OVERWRITE', 'overwritten')
|
67
|
+
expect(ENV['TO_OVERWRITE']).to eq 'overwritten'
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'allows the original value to be stubbed with nil' do
|
71
|
+
stub_env('TO_OVERWRITE', nil)
|
72
|
+
expect(ENV['TO_OVERWRITE']).to be_nil
|
73
|
+
end
|
74
|
+
end
|
75
|
+
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.2
|
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-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|