rspec-stubbed_env 1.0.0 → 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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +66 -0
- data/CODE_OF_CONDUCT.md +107 -46
- data/CONTRIBUTING.md +136 -0
- data/{LICENSE → LICENSE.txt} +2 -1
- data/README.md +468 -70
- data/SECURITY.md +21 -0
- data/lib/rspec/stubbed_env/config.rb +46 -2
- data/lib/rspec/stubbed_env/hide_helpers.rb +76 -0
- data/lib/rspec/stubbed_env/stub_helpers.rb +90 -0
- data/lib/rspec/stubbed_env/version.rb +1 -1
- data/lib/rspec/stubbed_env.rb +13 -7
- data.tar.gz.sig +0 -0
- metadata +61 -50
- metadata.gz.sig +0 -0
- data/.gitignore +0 -19
- data/.pryrc +0 -13
- data/.rspec +0 -3
- data/.ruby-version +0 -1
- data/.travis.yml +0 -32
- data/Gemfile +0 -8
- data/Rakefile +0 -8
- data/bin/console +0 -15
- data/bin/setup +0 -8
- data/lib/rspec/stubbed_env/test_helpers.rb +0 -63
- data/rspec-stubbed_env.gemspec +0 -36
@@ -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
|
-
|
20
|
-
|
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
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# ENV stubbing is opt-in, via a shared context, rather than global
|
5
|
+
#
|
6
|
+
# Usage:
|
7
|
+
#
|
8
|
+
# describe 'my stubbed test' do
|
9
|
+
# include_context 'with stubbed env'
|
10
|
+
# before do
|
11
|
+
# stub_env('FOO' => 'is bar')
|
12
|
+
# # or, equivalently:
|
13
|
+
# stub_env(FOO: 'is bar')
|
14
|
+
# # or, equivalently:
|
15
|
+
# stub_env('FOO', 'is bar')
|
16
|
+
# # or, equivalently:
|
17
|
+
# stub_env(FOO: 'is bar')
|
18
|
+
# end
|
19
|
+
# it 'does a thing' do
|
20
|
+
# expect(ENV['FOO']).to eq('is bar')
|
21
|
+
# end
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# NOTE: This file was originally written by Liam Bennet (https://github.com/ljkbennett)
|
25
|
+
# as part of the stub_env library (https://github.com/ljkbennett/stub_env).
|
26
|
+
# It has evolved since then.
|
27
|
+
module RSpec
|
28
|
+
module StubbedEnv
|
29
|
+
# Helpers to unobtrusively stub ENV
|
30
|
+
module StubHelpers
|
31
|
+
# Can be called with all key value pairs to be stubbed as a hash:
|
32
|
+
#
|
33
|
+
# stub_env('A' => 'B', 'C' => 'D', 'E' => 'F') # Preferred
|
34
|
+
#
|
35
|
+
# Alternatively can be called one per ENV key-value pair to stub:
|
36
|
+
#
|
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
|
+
def stub_env(key_or_hash, value = nil)
|
41
|
+
init_stub unless env_stubbed?
|
42
|
+
if key_or_hash.is_a?(Hash)
|
43
|
+
key_or_hash.each { |k, v| add_stubbed_value(k, v) }
|
44
|
+
else
|
45
|
+
add_stubbed_value(key_or_hash, value)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
STUBBED_KEY = "__STUBBED__"
|
52
|
+
|
53
|
+
def add_stubbed_value(key, value)
|
54
|
+
key = key.to_s # Support symbols by forcing to string
|
55
|
+
allow_brackets(key, value)
|
56
|
+
allow_fetch(key, value)
|
57
|
+
allow_values_at
|
58
|
+
end
|
59
|
+
|
60
|
+
def allow_brackets(key, value)
|
61
|
+
allow(ENV).to(receive(:[]).with(key).and_return(value))
|
62
|
+
end
|
63
|
+
|
64
|
+
def allow_fetch(key, value)
|
65
|
+
allow(ENV).to(receive(:fetch).with(key).and_return(value))
|
66
|
+
allow(ENV).to(receive(:fetch).with(key, anything)) do |_, default_val|
|
67
|
+
value || default_val
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# Rides on the fetch stub!
|
72
|
+
def allow_values_at
|
73
|
+
allow(ENV).to(receive(:values_at)) do |*args|
|
74
|
+
args.map { |arg| ENV.fetch(arg, nil) }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def env_stubbed?
|
79
|
+
ENV.fetch(STUBBED_KEY, nil)
|
80
|
+
end
|
81
|
+
|
82
|
+
def init_stub
|
83
|
+
allow(ENV).to(receive(:[]).and_call_original)
|
84
|
+
allow(ENV).to(receive(:fetch).and_call_original)
|
85
|
+
allow(ENV).to(receive(:values_at).and_call_original)
|
86
|
+
add_stubbed_value(STUBBED_KEY, true)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/lib/rspec/stubbed_env.rb
CHANGED
@@ -1,13 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'rspec/stubbed_env/version'
|
4
|
-
|
5
|
-
# External Gems
|
6
|
-
require 'rspec'
|
7
|
-
|
8
3
|
# This Gem
|
9
|
-
require
|
10
|
-
require
|
4
|
+
require "rspec/stubbed_env/version"
|
5
|
+
require "rspec/stubbed_env/hide_helpers"
|
6
|
+
require "rspec/stubbed_env/stub_helpers"
|
7
|
+
require "rspec/stubbed_env/config"
|
11
8
|
|
12
9
|
#
|
13
10
|
# ENV stubbing is opt-in, via a shared context, rather than global
|
@@ -22,6 +19,15 @@ require 'rspec/stubbed_env/config'
|
|
22
19
|
# end
|
23
20
|
# end
|
24
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
|
25
31
|
module RSpec
|
26
32
|
# Gem Namespace
|
27
33
|
module StubbedEnv
|
data.tar.gz.sig
ADDED
Binary file
|
metadata
CHANGED
@@ -1,105 +1,118 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-stubbed_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
|
+
- Liam Bennett
|
7
8
|
- Peter Boling
|
8
|
-
autorequire:
|
9
9
|
bindir: exe
|
10
|
-
cert_chain:
|
11
|
-
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIEgDCCAuigAwIBAgIBATANBgkqhkiG9w0BAQsFADBDMRUwEwYDVQQDDAxwZXRl
|
14
|
+
ci5ib2xpbmcxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkW
|
15
|
+
A2NvbTAeFw0yNTA1MDQxNTMzMDlaFw00NTA0MjkxNTMzMDlaMEMxFTATBgNVBAMM
|
16
|
+
DHBldGVyLmJvbGluZzEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPy
|
17
|
+
LGQBGRYDY29tMIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAruUoo0WA
|
18
|
+
uoNuq6puKWYeRYiZekz/nsDeK5x/0IEirzcCEvaHr3Bmz7rjo1I6On3gGKmiZs61
|
19
|
+
LRmQ3oxy77ydmkGTXBjruJB+pQEn7UfLSgQ0xa1/X3kdBZt6RmabFlBxnHkoaGY5
|
20
|
+
mZuZ5+Z7walmv6sFD9ajhzj+oIgwWfnEHkXYTR8I6VLN7MRRKGMPoZ/yvOmxb2DN
|
21
|
+
coEEHWKO9CvgYpW7asIihl/9GMpKiRkcYPm9dGQzZc6uTwom1COfW0+ZOFrDVBuV
|
22
|
+
FMQRPswZcY4Wlq0uEBLPU7hxnCL9nKK6Y9IhdDcz1mY6HZ91WImNslOSI0S8hRpj
|
23
|
+
yGOWxQIhBT3fqCBlRIqFQBudrnD9jSNpSGsFvbEijd5ns7Z9ZMehXkXDycpGAUj1
|
24
|
+
to/5cuTWWw1JqUWrKJYoifnVhtE1o1DZ+LkPtWxHtz5kjDG/zR3MG0Ula0UOavlD
|
25
|
+
qbnbcXPBnwXtTFeZ3C+yrWpE4pGnl3yGkZj9SMTlo9qnTMiPmuWKQDatAgMBAAGj
|
26
|
+
fzB9MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQWBBQE8uWvNbPVNRXZ
|
27
|
+
HlgPbc2PCzC4bjAhBgNVHREEGjAYgRZwZXRlci5ib2xpbmdAZ21haWwuY29tMCEG
|
28
|
+
A1UdEgQaMBiBFnBldGVyLmJvbGluZ0BnbWFpbC5jb20wDQYJKoZIhvcNAQELBQAD
|
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==
|
38
|
+
-----END CERTIFICATE-----
|
39
|
+
date: 2025-05-06 00:00:00.000000000 Z
|
12
40
|
dependencies:
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: rspec
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '3.0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '3.0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
47
|
+
version: '3.13'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
54
|
+
version: '3.13'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
56
|
+
name: rspec-block_is_expected
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - "~>"
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
61
|
+
version: '1.0'
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
66
|
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
68
|
+
version: '1.0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: rake
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - "~>"
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0
|
75
|
+
version: '13.0'
|
62
76
|
type: :development
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0
|
69
|
-
description:
|
70
|
-
Stub environment variables in a scoped context for testing
|
71
|
-
stub_env(
|
72
|
-
|
73
|
-
'REDIS_URL' => 'redis://localhost:6379/'
|
74
|
-
)
|
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')
|
75
87
|
email:
|
76
88
|
- peter.boling@gmail.com
|
77
89
|
executables: []
|
78
90
|
extensions: []
|
79
91
|
extra_rdoc_files: []
|
80
92
|
files:
|
81
|
-
-
|
82
|
-
- ".pryrc"
|
83
|
-
- ".rspec"
|
84
|
-
- ".ruby-version"
|
85
|
-
- ".travis.yml"
|
93
|
+
- CHANGELOG.md
|
86
94
|
- CODE_OF_CONDUCT.md
|
87
|
-
-
|
88
|
-
- LICENSE
|
95
|
+
- CONTRIBUTING.md
|
96
|
+
- LICENSE.txt
|
89
97
|
- README.md
|
90
|
-
-
|
91
|
-
- bin/console
|
92
|
-
- bin/setup
|
98
|
+
- SECURITY.md
|
93
99
|
- lib/rspec/stubbed_env.rb
|
94
100
|
- lib/rspec/stubbed_env/config.rb
|
95
|
-
- lib/rspec/stubbed_env/
|
101
|
+
- lib/rspec/stubbed_env/hide_helpers.rb
|
102
|
+
- lib/rspec/stubbed_env/stub_helpers.rb
|
96
103
|
- lib/rspec/stubbed_env/version.rb
|
97
|
-
- rspec-stubbed_env.gemspec
|
98
104
|
homepage: https://github.com/pboling/rspec-stubbed_env
|
99
105
|
licenses:
|
100
106
|
- MIT
|
101
|
-
metadata:
|
102
|
-
|
107
|
+
metadata:
|
108
|
+
homepage_uri: https://github.com/pboling/rspec-stubbed_env
|
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
|
111
|
+
bug_tracker_uri: https://github.com/pboling/rspec-stubbed_env/issues
|
112
|
+
documentation_uri: https://www.rubydoc.info/gems/rspec-stubbed_env/1.0.2
|
113
|
+
funding_uri: https://liberapay.com/pboling
|
114
|
+
wiki_uri: https://github.com/pboling/rspec-stubbed_env/wiki
|
115
|
+
rubygems_mfa_required: 'true'
|
103
116
|
rdoc_options: []
|
104
117
|
require_paths:
|
105
118
|
- lib
|
@@ -107,16 +120,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
107
120
|
requirements:
|
108
121
|
- - ">="
|
109
122
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
123
|
+
version: 1.8.7
|
111
124
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
125
|
requirements:
|
113
126
|
- - ">="
|
114
127
|
- !ruby/object:Gem::Version
|
115
128
|
version: '0'
|
116
129
|
requirements: []
|
117
|
-
|
118
|
-
rubygems_version: 2.7.7
|
119
|
-
signing_key:
|
130
|
+
rubygems_version: 3.6.8
|
120
131
|
specification_version: 4
|
121
132
|
summary: Unobtrusively stub ENV keys and values during testing
|
122
133
|
test_files: []
|
metadata.gz.sig
ADDED
Binary file
|
data/.gitignore
DELETED
data/.pryrc
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
if defined?(PryByebug)
|
4
|
-
Pry.commands.alias_command 'c', 'continue'
|
5
|
-
Pry.commands.alias_command 's', 'step'
|
6
|
-
Pry.commands.alias_command 'n', 'next'
|
7
|
-
Pry.commands.alias_command 'trace', 'backtrace'
|
8
|
-
end
|
9
|
-
|
10
|
-
# Hit Enter to repeat last command
|
11
|
-
Pry::Commands.command /^$/, 'repeat last command' do
|
12
|
-
_pry_.run_command Pry.history.to_a.last
|
13
|
-
end
|
data/.rspec
DELETED
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
ruby-2.5.1
|
data/.travis.yml
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
---
|
2
|
-
env:
|
3
|
-
global:
|
4
|
-
- JRUBY_OPTS="-Xcli.debug=true --debug"
|
5
|
-
- CC_TEST_REPORTER_ID=3ed1c79841ccc5d053b995c63c0ead562427a77dba728601b8d19f02b16ac0f2
|
6
|
-
|
7
|
-
before_script:
|
8
|
-
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
9
|
-
- chmod +x ./cc-test-reporter
|
10
|
-
- ./cc-test-reporter before-build
|
11
|
-
|
12
|
-
script:
|
13
|
-
- bundle exec rake
|
14
|
-
|
15
|
-
after_script:
|
16
|
-
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
17
|
-
|
18
|
-
before_install:
|
19
|
-
- gem update --system
|
20
|
-
- gem install bundler -v 1.16.5
|
21
|
-
|
22
|
-
install:
|
23
|
-
- bundle install
|
24
|
-
|
25
|
-
bundler_args: --no-deployment --jobs 3 --retry 3
|
26
|
-
|
27
|
-
language: ruby
|
28
|
-
cache: bundler
|
29
|
-
rvm:
|
30
|
-
- 2.3.7
|
31
|
-
- 2.4.4
|
32
|
-
- 2.5.1
|
data/Gemfile
DELETED
data/Rakefile
DELETED
data/bin/console
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require 'bundler/setup'
|
5
|
-
require 'rspec/stubbed_env'
|
6
|
-
|
7
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
-
# with your gem easier. You can also use a different console, if you like.
|
9
|
-
|
10
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
-
# require "pry"
|
12
|
-
# Pry.start
|
13
|
-
|
14
|
-
require 'irb'
|
15
|
-
IRB.start(__FILE__)
|
data/bin/setup
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
#
|
4
|
-
# ENV stubbing is opt-in, via a shared context, rather than global
|
5
|
-
#
|
6
|
-
# Usage:
|
7
|
-
#
|
8
|
-
# describe 'my stubbed test' do
|
9
|
-
# include_context 'with stubbed env'
|
10
|
-
# before do
|
11
|
-
# stub_env('FOO' => 'is bar')
|
12
|
-
# end
|
13
|
-
# it 'does a thing' do
|
14
|
-
# expect(ENV['FOO']).to eq('is bar')
|
15
|
-
# end
|
16
|
-
# end
|
17
|
-
#
|
18
|
-
module RSpec
|
19
|
-
module StubbedEnv
|
20
|
-
# Helpers to unobtrusively stub ENV
|
21
|
-
module TestHelpers
|
22
|
-
# Can be called with all key value pairs to be stubbed as a hash:
|
23
|
-
#
|
24
|
-
# stub_env('A' => 'B', 'C' => 'D', 'E' => 'F')
|
25
|
-
#
|
26
|
-
# Alternatively can be called one per ENV key-value pair to stub:
|
27
|
-
#
|
28
|
-
# stub_env('A', 'B')
|
29
|
-
# stub_env('C', 'D')
|
30
|
-
# stub_env('E', 'F')
|
31
|
-
def stub_env(key_or_hash, value = nil)
|
32
|
-
init_stub unless env_stubbed?
|
33
|
-
if key_or_hash.is_a? Hash
|
34
|
-
key_or_hash.each { |k, v| add_stubbed_value(k, v) }
|
35
|
-
else
|
36
|
-
add_stubbed_value key_or_hash, value
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
STUBBED_KEY = '__STUBBED__'
|
43
|
-
|
44
|
-
def add_stubbed_value(key, value)
|
45
|
-
allow(ENV).to receive(:[]).with(key).and_return(value)
|
46
|
-
allow(ENV).to receive(:fetch).with(key).and_return(value)
|
47
|
-
allow(ENV).to receive(:fetch).with(key, anything) do |_, default_val|
|
48
|
-
value || default_val
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def env_stubbed?
|
53
|
-
ENV[STUBBED_KEY]
|
54
|
-
end
|
55
|
-
|
56
|
-
def init_stub
|
57
|
-
allow(ENV).to receive(:[]).and_call_original
|
58
|
-
allow(ENV).to receive(:fetch).and_call_original
|
59
|
-
add_stubbed_value(STUBBED_KEY, true)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
data/rspec-stubbed_env.gemspec
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
lib = File.expand_path('lib', __dir__)
|
4
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require 'rspec/stubbed_env/version'
|
6
|
-
|
7
|
-
Gem::Specification.new do |spec|
|
8
|
-
spec.name = 'rspec-stubbed_env'
|
9
|
-
spec.version = RSpec::StubbedEnv::VERSION
|
10
|
-
spec.authors = ['Peter Boling']
|
11
|
-
spec.email = ['peter.boling@gmail.com']
|
12
|
-
|
13
|
-
spec.summary = 'Unobtrusively stub ENV keys and values during testing'
|
14
|
-
spec.description = %[Stub environment variables in a scoped context for testing
|
15
|
-
stub_env(
|
16
|
-
'AWS_REGION' => 'us-east-1',
|
17
|
-
'REDIS_URL' => 'redis://localhost:6379/'
|
18
|
-
)]
|
19
|
-
spec.homepage = 'https://github.com/pboling/rspec-stubbed_env'
|
20
|
-
spec.license = 'MIT'
|
21
|
-
|
22
|
-
# Specify which files should be added to the gem when it is released.
|
23
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
-
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
25
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
-
end
|
27
|
-
spec.bindir = 'exe'
|
28
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
-
spec.require_paths = ['lib']
|
30
|
-
|
31
|
-
spec.add_runtime_dependency 'rspec', '>= 3.0'
|
32
|
-
|
33
|
-
spec.add_development_dependency 'bundler', '~> 1.16'
|
34
|
-
spec.add_development_dependency 'rake', '~> 12.3'
|
35
|
-
spec.add_development_dependency 'simplecov', '~> 0.16'
|
36
|
-
end
|