rspec-stubbed_env 1.0.1 → 1.0.3

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.
data/SECURITY.md ADDED
@@ -0,0 +1,21 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ | Version | Supported |
6
+ |----------|-----------|
7
+ | 1.latest | ✅ |
8
+
9
+ ## Security contact information
10
+
11
+ To report a security vulnerability, please use the
12
+ [Tidelift security contact](https://tidelift.com/security).
13
+ Tidelift will coordinate the fix and disclosure.
14
+
15
+ ## Additional Support
16
+
17
+ If you are interested in support for versions older than the latest release,
18
+ please consider sponsoring the project / maintainer @ https://liberapay.com/pboling/donate,
19
+ or find other sponsorship links in the [README].
20
+
21
+ [README]: README.md
@@ -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.3"
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,79 +1,180 @@
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.3
5
5
  platform: ruby
6
6
  authors:
7
- - Liam Bennett
8
7
  - Peter Boling
9
- autorequire:
8
+ - Liam Bennett
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+pLotIoT08bjDv8NP6V7zZslwQRqW27bQ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UIlkIUI2tg5YzW6OFfPzq
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-07-29 00:00:00.000000000 Z
40
+ dependencies:
41
+ - !ruby/object:Gem::Dependency
42
+ name: stone_checksums
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: appraisal2
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.13'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.13'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-block_is_expected
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec_junit_formatter
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.6'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.6'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '13.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '13.0'
125
+ description: |
126
+ Stub or hide environment variables in a scoped context for testing
127
+ stub_env('REDIS_URL' => 'redis://localhost:6379/')
128
+ hide_env('SESSION_SECRET')
48
129
  email:
49
- - peter.boling@gmail.com
130
+ - floss@galtzo.com
50
131
  executables: []
51
132
  extensions: []
52
- extra_rdoc_files: []
133
+ extra_rdoc_files:
134
+ - CHANGELOG.md
135
+ - CODE_OF_CONDUCT.md
136
+ - CONTRIBUTING.md
137
+ - LICENSE.txt
138
+ - README.md
139
+ - SECURITY.md
53
140
  files:
54
141
  - CHANGELOG.md
55
142
  - CODE_OF_CONDUCT.md
56
143
  - CONTRIBUTING.md
57
144
  - LICENSE.txt
58
145
  - README.md
146
+ - SECURITY.md
59
147
  - lib/rspec/stubbed_env.rb
60
148
  - lib/rspec/stubbed_env/config.rb
61
- - lib/rspec/stubbed_env/test_helpers.rb
149
+ - lib/rspec/stubbed_env/hide_helpers.rb
150
+ - lib/rspec/stubbed_env/stub_helpers.rb
62
151
  - lib/rspec/stubbed_env/version.rb
63
152
  homepage: https://github.com/pboling/rspec-stubbed_env
64
153
  licenses:
65
154
  - MIT
66
155
  metadata:
67
- 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
156
+ homepage_uri: https://rspec-stubbed-env.galtzo.com/
157
+ source_code_uri: https://github.com/pboling/rspec-stubbed_env/tree/v1.0.3
158
+ changelog_uri: https://github.com/pboling/rspec-stubbed_env/blob/v1.0.3/CHANGELOG.md
70
159
  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
72
- funding_uri: https://liberapay.com/pboling
160
+ documentation_uri: https://www.rubydoc.info/gems/rspec-stubbed_env/1.0.3
161
+ funding_uri: https://github.com/sponsors/pboling
73
162
  wiki_uri: https://github.com/pboling/rspec-stubbed_env/wiki
163
+ news_uri: https://www.railsbling.com/tags/rspec-stubbed_env
74
164
  rubygems_mfa_required: 'true'
75
- post_install_message:
76
- rdoc_options: []
165
+ rdoc_options:
166
+ - "--title"
167
+ - rspec-stubbed_env - Unobtrusively stub ENV keys and values during testing
168
+ - "--main"
169
+ - CHANGELOG.md
170
+ - CODE_OF_CONDUCT.md
171
+ - CONTRIBUTING.md
172
+ - LICENSE.txt
173
+ - README.md
174
+ - SECURITY.md
175
+ - "--line-numbers"
176
+ - "--inline-source"
177
+ - "--quiet"
77
178
  require_paths:
78
179
  - lib
79
180
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -87,8 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
188
  - !ruby/object:Gem::Version
88
189
  version: '0'
89
190
  requirements: []
90
- rubygems_version: 3.4.10
91
- signing_key:
191
+ rubygems_version: 3.6.9
92
192
  specification_version: 4
93
193
  summary: Unobtrusively stub ENV keys and values during testing
94
194
  test_files: []
metadata.gz.sig CHANGED
Binary file