stub_env 1.0.0 → 1.0.1

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: 1ad5f1af2fe9363c6302afaf0e30c7ab56eae7c3
4
- data.tar.gz: b21a53e9b11bc30d6ad7141f9bb3dfc28e3ec7bd
3
+ metadata.gz: f9493b28321043cf428d39b2fb18174a3ef55ca3
4
+ data.tar.gz: b5ae5362f9789aaffa0041d35f51f2ace1e005fc
5
5
  SHA512:
6
- metadata.gz: 032e44c16aae9a2ab047b62d128115938d852747ab20b969e3e4d91afb14257c7ff1c0ec1057fecd0d3af367c7c9e433ebd27b49e982321a45953005a1ca3b87
7
- data.tar.gz: faec12e2fd6a424df41f2b5a07e4bbfbb3ef7f9897ade218bc5aa48b0c19ae66cceeb1b2e348d9925c1ddfc6c779681d1209fd0c9785fca8960c21729c221be2
6
+ metadata.gz: 8bb53b9d0444e2325d2d190cf249d0a9ea4d0d17e3b11fb696f445e8d43f92492ae5636fae0ce4f645dc2ef81e6bc5e4179c0fc3ac6c804bea91cd860a6a0be4
7
+ data.tar.gz: f54bbf229683cdf288daab6673fd0507148e2cb6975d087188f651e96f1dd38f541db703983e4ac1cb832fbdd09ed1bf5298c3fb4d8f53955509b425691a0015
@@ -12,17 +12,19 @@ module StubEnv
12
12
 
13
13
  private
14
14
 
15
+ STUBBED_KEY = '__STUBBED__'
16
+
15
17
  def add_stubbed_value key, value
16
18
  allow(ENV).to receive(:[]).with(key).and_return(value)
17
19
  end
18
20
 
19
21
  def env_stubbed?
20
- ENV.respond_to?(:stubbed?) && ENV.stubbed?
22
+ ENV[STUBBED_KEY]
21
23
  end
22
24
 
23
25
  def init_stub
24
- allow(ENV).to receive(:stubbed?).and_return(true)
25
26
  allow(ENV).to receive(:[]).and_call_original
27
+ add_stubbed_value(STUBBED_KEY, true)
26
28
  end
27
29
 
28
30
  end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,3 @@
1
1
  require 'stub_env'
2
2
 
3
- RSpec.configure do |config|
4
-
5
- end
3
+ Dir[("./spec/support/**/*.rb")].each { |f| require f }
@@ -9,53 +9,18 @@ describe StubEnv::Helpers do
9
9
 
10
10
  describe "#stub_env" do
11
11
 
12
- context "with a single stubbed variable" do
13
- before :each do
14
- stub_env('TEST', 'success')
15
- end
16
- it "stubs out environment variables" do
17
- expect(ENV['TEST']).to eq 'success'
18
- end
19
-
20
- it "leaves original environment variables unstubbed" do
21
- expect(ENV['UNSTUBBED']).to eq 'unstubbed'
22
- end
23
- end
24
-
25
- context "with multiple stubbed variables" do
26
- before :each do
27
- stub_env('TEST', 'success')
28
- stub_env('TEST2', 'another success')
29
- end
30
-
31
- it "stubs out the first variable" do
32
- expect(ENV['TEST']).to eq 'success'
33
- end
12
+ include_examples 'stub_env tests'
34
13
 
35
- it "stubs out the second variable" do
36
- expect(ENV['TEST2']).to eq 'another success'
37
- end
14
+ if RSpec::Mocks::Configuration.public_instance_methods.include? :verify_partial_doubles=
15
+ context "with the verify partial doubles option set" do
38
16
 
39
- it "leaves original environment variables unstubbed" do
40
- expect(ENV['UNSTUBBED']).to eq 'unstubbed'
41
- end
42
- end
43
-
44
- context "with multiple stubbed variables in a hash" do
45
- before :each do
46
- stub_env({'TEST' => 'success', 'TEST2' => 'another success'})
47
- end
48
-
49
- it "stubs out the first variable" do
50
- expect(ENV['TEST']).to eq 'success'
51
- end
52
-
53
- it "stubs out the second variable" do
54
- expect(ENV['TEST2']).to eq 'another success'
55
- end
17
+ before :each do
18
+ RSpec.configuration.mock_with :rspec do |mocks|
19
+ mocks.verify_partial_doubles = true
20
+ end
21
+ end
56
22
 
57
- it "leaves original environment variables unstubbed" do
58
- expect(ENV['UNSTUBBED']).to eq 'unstubbed'
23
+ include_examples 'stub_env tests'
59
24
  end
60
25
  end
61
26
  end
@@ -0,0 +1,51 @@
1
+ shared_examples 'stub_env tests' do
2
+ context 'with a single stubbed variable' do
3
+ before :each do
4
+ stub_env('TEST', 'success')
5
+ end
6
+ it 'stubs out environment variables' do
7
+ expect(ENV['TEST']).to eq 'success'
8
+ end
9
+
10
+ it 'leaves original environment variables unstubbed' do
11
+ expect(ENV['UNSTUBBED']).to eq 'unstubbed'
12
+ end
13
+ end
14
+
15
+ context 'with multiple stubbed variables' do
16
+ before :each do
17
+ stub_env('TEST', 'success')
18
+ stub_env('TEST2', 'another success')
19
+ end
20
+
21
+ it 'stubs out the first variable' do
22
+ expect(ENV['TEST']).to eq 'success'
23
+ end
24
+
25
+ it 'stubs out the second variable' do
26
+ expect(ENV['TEST2']).to eq 'another success'
27
+ end
28
+
29
+ it 'leaves original environment variables unstubbed' do
30
+ expect(ENV['UNSTUBBED']).to eq 'unstubbed'
31
+ end
32
+ end
33
+
34
+ context 'with multiple stubbed variables in a hash' do
35
+ before :each do
36
+ stub_env({'TEST' => 'success', 'TEST2' => 'another success'})
37
+ end
38
+
39
+ it 'stubs out the first variable' do
40
+ expect(ENV['TEST']).to eq 'success'
41
+ end
42
+
43
+ it 'stubs out the second variable' do
44
+ expect(ENV['TEST2']).to eq 'another success'
45
+ end
46
+
47
+ it 'leaves original environment variables unstubbed' do
48
+ expect(ENV['UNSTUBBED']).to eq 'unstubbed'
49
+ end
50
+ end
51
+ 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.0"
5
+ gem.version = "1.0.1"
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.0
4
+ version: 1.0.1
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-02-04 00:00:00.000000000 Z
11
+ date: 2015-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -77,6 +77,7 @@ files:
77
77
  - lib/stub_env/helpers.rb
78
78
  - spec/spec_helper.rb
79
79
  - spec/stub_env/helpers_spec.rb
80
+ - spec/support/helper_tests.rb
80
81
  - stub_env.gemspec
81
82
  homepage: https://github.com/littleowllabs/stub_env
82
83
  licenses:
@@ -98,10 +99,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
99
  version: '0'
99
100
  requirements: []
100
101
  rubyforge_project:
101
- rubygems_version: 2.4.2
102
+ rubygems_version: 2.4.3
102
103
  signing_key:
103
104
  specification_version: 4
104
105
  summary: Stub ENV values in RSpec tests
105
106
  test_files:
106
107
  - spec/spec_helper.rb
107
108
  - spec/stub_env/helpers_spec.rb
109
+ - spec/support/helper_tests.rb