rspec-stubbed_env 1.0.1 → 1.0.2

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.
@@ -15,7 +15,51 @@
15
15
  # end
16
16
  # end
17
17
  #
18
+ # Alternative usage:
19
+ #
20
+ # describe 'another stubbed test' do
21
+ # include_context 'with stubbed env', 'FOO' => 'is_bar'
22
+ # it 'also does a thing' do
23
+ # expect(ENV['FOO']).to eq('is bar')
24
+ # end
25
+ # end
26
+ RSpec.shared_context("with stubbed env") do |args|
27
+ include RSpec::StubbedEnv::StubHelpers
28
+
29
+ # TODO: Switch `length > 0` => `any?` after Ruby 1.8 support is dropped
30
+ if args.is_a?(Hash) && args.keys.length > 0
31
+ before { stub_env(args) }
32
+ end
33
+ end
34
+
35
+ #
36
+ # ENV hiding is opt-in, via a shared context, rather than global
37
+ #
38
+ # Usage:
39
+ #
40
+ # describe 'my hidden test' do
41
+ # include_context 'with hidden env'
42
+ # before do
43
+ # hide_env('FOO', 'BAR')
44
+ # end
45
+ # it 'does a thing' do
46
+ # expect(ENV['FOO']).to be_nil
47
+ # end
48
+ # end
49
+ #
50
+ # Alternative usage:
51
+ #
52
+ # describe 'another stubbed test' do
53
+ # include_context 'with stubbed env', 'FOO', 'BAR'
54
+ # it 'also does a thing' do
55
+ # expect(ENV['BAR']).to be_nil
56
+ # end
57
+ # end
58
+ RSpec.shared_context("with hidden env") do |*args|
59
+ include RSpec::StubbedEnv::HideHelpers
18
60
 
19
- RSpec.shared_context("with stubbed env") do
20
- include RSpec::StubbedEnv::TestHelpers
61
+ # TODO: Switch `length > 0` => `any?` after Ruby 1.8 support is dropped
62
+ if args.is_a?(Array) && args.length > 0
63
+ before { hide_env(*args) }
64
+ end
21
65
  end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rspec/stubbed_env/stub_helpers"
4
+
5
+ #
6
+ # ENV hiding is opt-in, via a shared context, rather than global
7
+ #
8
+ # Usage:
9
+ #
10
+ # describe 'my hidden ENV test' do
11
+ # include_context 'with hidden env'
12
+ # before do
13
+ # ENV["FOO"] = "is bar"
14
+ # hide_env('FOO')
15
+ # end
16
+ # it 'is nil' do
17
+ # expect(ENV['FOO']).to be_nil
18
+ # end
19
+ # it 'raises KeyError on fetch' do
20
+ # expect { ENV.fetch('FOO') }.to raise_error(KeyError)
21
+ # end
22
+ # end
23
+
24
+ module RSpec
25
+ module StubbedEnv
26
+ # Helpers to unobtrusively stub ENV
27
+ module HideHelpers
28
+ include StubHelpers
29
+
30
+ # Can be called with an array of ENV keys to hide:
31
+ #
32
+ # hide_env('FOO', 'BAR', 'BAZ') # Preferred
33
+ #
34
+ # Alternatively can be called once per ENV key to hide:
35
+ #
36
+ # stub_env('A') # NOT
37
+ # stub_env('C') # AS
38
+ # stub_env('E') # GOOD (creates redundant stubs on values_at)
39
+ def hide_env(*keys)
40
+ init_stub unless env_stubbed?
41
+ keys.each do |key|
42
+ add_hidden_key(key)
43
+ end
44
+ end
45
+
46
+ private
47
+
48
+ def add_hidden_key(key)
49
+ key = key.to_s # Support symbols by forcing to string
50
+ hide_brackets(key)
51
+ hide_fetch(key)
52
+ hide_values_at
53
+ end
54
+
55
+ def hide_brackets(key)
56
+ allow(ENV).to(receive(:[]).with(key).and_return(nil))
57
+ end
58
+
59
+ def hide_fetch(key)
60
+ allow(ENV).to(receive(:fetch).with(key)) do |_|
61
+ raise KeyError, "key not found: \"#{key}\""
62
+ end
63
+ allow(ENV).to(receive(:fetch).with(key, anything)) do |_, default_val|
64
+ default_val
65
+ end
66
+ end
67
+
68
+ # Rides on the fetch hider!
69
+ def hide_values_at
70
+ allow(ENV).to(receive(:values_at)) do |*args|
71
+ args.map { |arg| ENV.fetch(arg, nil) }
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -27,16 +27,16 @@
27
27
  module RSpec
28
28
  module StubbedEnv
29
29
  # Helpers to unobtrusively stub ENV
30
- module TestHelpers
30
+ module StubHelpers
31
31
  # Can be called with all key value pairs to be stubbed as a hash:
32
32
  #
33
- # stub_env('A' => 'B', 'C' => 'D', 'E' => 'F')
33
+ # stub_env('A' => 'B', 'C' => 'D', 'E' => 'F') # Preferred
34
34
  #
35
35
  # Alternatively can be called one per ENV key-value pair to stub:
36
36
  #
37
- # stub_env('A', 'B')
38
- # stub_env('C', 'D')
39
- # stub_env('E', 'F')
37
+ # stub_env('A', 'B') # NOT
38
+ # stub_env('C', 'D') # AS
39
+ # stub_env('E', 'F') # GOOD (Creates redundant stubs on values_at)
40
40
  def stub_env(key_or_hash, value = nil)
41
41
  init_stub unless env_stubbed?
42
42
  if key_or_hash.is_a?(Hash)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RSpec
4
4
  module StubbedEnv
5
- VERSION = "1.0.1"
5
+ VERSION = "1.0.2"
6
6
  end
7
7
  end
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "rspec/stubbed_env/version"
4
-
5
3
  # This Gem
6
- require "rspec/stubbed_env/test_helpers"
4
+ require "rspec/stubbed_env/version"
5
+ require "rspec/stubbed_env/hide_helpers"
6
+ require "rspec/stubbed_env/stub_helpers"
7
7
  require "rspec/stubbed_env/config"
8
8
 
9
9
  #
@@ -19,6 +19,15 @@ require "rspec/stubbed_env/config"
19
19
  # end
20
20
  # end
21
21
  #
22
+ # describe 'my hidden test' do
23
+ # include_context 'with hidden env'
24
+ # before do
25
+ # hide_env('FOO')
26
+ # end
27
+ # it 'does a thing' do
28
+ # expect(ENV['FOO']).to be_nil
29
+ # end
30
+ # end
22
31
  module RSpec
23
32
  # Gem Namespace
24
33
  module StubbedEnv
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,50 +1,89 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-stubbed_env
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Liam Bennett
8
8
  - Peter Boling
9
- autorequire:
10
9
  bindir: exe
11
10
  cert_chain:
12
11
  - |
13
12
  -----BEGIN CERTIFICATE-----
14
13
  MIIEgDCCAuigAwIBAgIBATANBgkqhkiG9w0BAQsFADBDMRUwEwYDVQQDDAxwZXRl
15
14
  ci5ib2xpbmcxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkW
16
- A2NvbTAeFw0yMjA5MTgyMzEyMzBaFw0yMzA5MTgyMzEyMzBaMEMxFTATBgNVBAMM
15
+ A2NvbTAeFw0yNTA1MDQxNTMzMDlaFw00NTA0MjkxNTMzMDlaMEMxFTATBgNVBAMM
17
16
  DHBldGVyLmJvbGluZzEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPy
18
- LGQBGRYDY29tMIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEA2Dn1GM3W
19
- 8K2/rvN1zz+06bQMcxD16ZKTihVwi7Pb1v3T98rM4Omnxohm3s+CwpDWGeiB9pj6
20
- 0I/CTce0e4e3s8GKJSOrg93veImPSoH2PfsMsRsuB8wtqyiOCjLbF5o6S29x87r0
21
- LA5EawH+Lh4xqrkkPjdffsmLk7TaCig/vlmNvnzxXKBdey/X/aEJZXzzBiWRfVdh
22
- O1fmMbVKyieGv9HK7+pLotIoT08bjDv8NP6V7zZslwQRqW27bQc6cqC2LGIbTYO3
23
- 3jt1kQxfMWmhOictS6SzG9VtKSrXf0L4Neq0Gh7CLBZBvJFWJYZPfb92YNITDbd8
24
- emPOAQlXXNMN4mMXsEqtEhCPZRMnmwO+fOk/cC4AyglKi9lnQugCQoFV1XDMZST/
25
- CYbzdQyadOdPDInTntG6V+Uw51d2QGXZ6PDDfrx9+toc/3sl5h68rCUGgE6Q3jPz
26
- srinqmBsxv2vTpmd4FjmiAtEnwH5/ooLpQYL8UdAjEoeysxS3AwIh+5dAgMBAAGj
27
- fzB9MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA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e/OBvIMBF1IbjC3q5vKPg4rq8+TkNRJNoE86U2gfR+PkW3jYYs9uiy0GloHDCP
33
- k5xgaj0vSL0Uy5mTOPdk3K6a/sUGZyYniWK05zdhIi956ynhfGaFO988FFdVw5Jq
34
- LHtXfIpAU8F7ES04syZSslxOluw7VlcSKyRdVIr737J92ZTduppB4PRGSKRgBsWV
35
- hXTahRE72Kyw53Q7FAuzF3v102WxAAQ7BuMjW+MyCUT75fwPm3W4ELPL8HYkNGE7
36
- 2oA5CPghFitRnvYS3GNrDG+9bNiRMEskeaBYwZ9UgReBQIwGYVj7LZk3UhiAsn44
37
- gwGrEXGQGDZ0NIgBcmvMOqlXjkGQwQvugKycJ024z89+fz2332vdZIKTrSxJrXGk
38
- 4/bR9A==
29
+ ggGBAJbnUwfJQFPkBgH9cL7hoBfRtmWiCvdqdjeTmi04u8zVNCUox0A4gT982DE9
30
+ wmuN12LpdajxZONqbXuzZvc+nb0StFwmFYZG6iDwaf4BPywm2e/Vmq0YG45vZXGR
31
+ L8yMDSK1cQXjmA+ZBKOHKWavxP6Vp7lWvjAhz8RFwqF9GuNIdhv9NpnCAWcMZtpm
32
+ GUPyIWw/Cw/2wZp74QzZj6Npx+LdXoLTF1HMSJXZ7/pkxLCsB8m4EFVdb/IrW/0k
33
+ kNSfjtAfBHO8nLGuqQZVH9IBD1i9K6aSs7pT6TW8itXUIlkIUI2tg5YzW6OFfPzq
34
+ QekSkX3lZfY+HTSp/o+YvKkqWLUV7PQ7xh1ZYDtocpaHwgxe/j3bBqHE+CUPH2vA
35
+ 0V/FwdTRWcwsjVoOJTrYcff8pBZ8r2MvtAc54xfnnhGFzeRHfcltobgFxkAXdE6p
36
+ DVjBtqT23eugOqQ73umLcYDZkc36vnqGxUBSsXrzY9pzV5gGr2I8YUxMqf6ATrZt
37
+ L9nRqA==
39
38
  -----END CERTIFICATE-----
40
- date: 2023-04-01 00:00:00.000000000 Z
41
- dependencies: []
42
- description: |-
43
- Stub environment variables in a scoped context for testing
44
- stub_env(
45
- 'AWS_REGION' => 'us-east-1',
46
- 'REDIS_URL' => 'redis://localhost:6379/'
47
- )
39
+ date: 2025-05-06 00:00:00.000000000 Z
40
+ dependencies:
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.13'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.13'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-block_is_expected
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '13.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '13.0'
83
+ description: |
84
+ Stub or hide environment variables in a scoped context for testing
85
+ stub_env('REDIS_URL' => 'redis://localhost:6379/')
86
+ hide_env('SESSION_SECRET')
48
87
  email:
49
88
  - peter.boling@gmail.com
50
89
  executables: []
@@ -56,23 +95,24 @@ files:
56
95
  - CONTRIBUTING.md
57
96
  - LICENSE.txt
58
97
  - README.md
98
+ - SECURITY.md
59
99
  - lib/rspec/stubbed_env.rb
60
100
  - lib/rspec/stubbed_env/config.rb
61
- - lib/rspec/stubbed_env/test_helpers.rb
101
+ - lib/rspec/stubbed_env/hide_helpers.rb
102
+ - lib/rspec/stubbed_env/stub_helpers.rb
62
103
  - lib/rspec/stubbed_env/version.rb
63
104
  homepage: https://github.com/pboling/rspec-stubbed_env
64
105
  licenses:
65
106
  - MIT
66
107
  metadata:
67
108
  homepage_uri: https://github.com/pboling/rspec-stubbed_env
68
- source_code_uri: https://github.com/pboling/rspec-stubbed_env/tree/v1.0.1
69
- changelog_uri: https://github.com/pboling/rspec-stubbed_env/blob/v1.0.1/CHANGELOG.md
109
+ source_code_uri: https://github.com/pboling/rspec-stubbed_env/tree/v1.0.2
110
+ changelog_uri: https://github.com/pboling/rspec-stubbed_env/blob/v1.0.2/CHANGELOG.md
70
111
  bug_tracker_uri: https://github.com/pboling/rspec-stubbed_env/issues
71
- documentation_uri: https://www.rubydoc.info/gems/rspec-stubbed_env/1.0.1
112
+ documentation_uri: https://www.rubydoc.info/gems/rspec-stubbed_env/1.0.2
72
113
  funding_uri: https://liberapay.com/pboling
73
114
  wiki_uri: https://github.com/pboling/rspec-stubbed_env/wiki
74
115
  rubygems_mfa_required: 'true'
75
- post_install_message:
76
116
  rdoc_options: []
77
117
  require_paths:
78
118
  - lib
@@ -87,8 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
127
  - !ruby/object:Gem::Version
88
128
  version: '0'
89
129
  requirements: []
90
- rubygems_version: 3.4.10
91
- signing_key:
130
+ rubygems_version: 3.6.8
92
131
  specification_version: 4
93
132
  summary: Unobtrusively stub ENV keys and values during testing
94
133
  test_files: []
metadata.gz.sig CHANGED
Binary file