minitest-substitute 0.2.1 → 1.0.0
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 +13 -1
- data/README.md +65 -10
- data/lib/minitest/substitute/spec.rb +5 -5
- data/lib/minitest/substitute/{with.rb → substitute.rb} +2 -2
- data/lib/minitest/substitute/substitutor.rb +24 -10
- data/lib/minitest/substitute/version.rb +1 -1
- data/lib/minitest/substitute.rb +2 -2
- data.tar.gz.sig +0 -0
- metadata +17 -17
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f8802ed1f575511d0d40b4c9c6aa83ac9e0438a4e516a3e9d371d64cbeec44c
|
4
|
+
data.tar.gz: 94dab332d69b4340512030e332d20b68975a80b0860f7e8cdb72334c25cfd076
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ebd589721d0d15745712e3b280cf395bce7d185ccdbe9fc728213c87a7991d7b8ba442e853ce7932e673bc6693e98b6712b3bf75878ce240b6eeb7298ae0a97
|
7
|
+
data.tar.gz: fc1cb86a0d3f3123afcde191b906c154044975f4fe95eb8b0f9af0639aa27c822da7377f36e0213fcc380d2b776ed00c5db5bace1a46c6945e994ca61928f7a2
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
@@ -2,9 +2,21 @@
|
|
2
2
|
|
3
3
|
Nothing so far
|
4
4
|
|
5
|
+
## 1.0.0
|
6
|
+
|
7
|
+
#### Breaking Changes
|
8
|
+
* Switch from `with` to `substitute` because Rails 7 pollutes `Object` for
|
9
|
+
everybody by introducing `Object#with`. 💣
|
10
|
+
|
11
|
+
## 0.3.0
|
12
|
+
|
13
|
+
#### Additions
|
14
|
+
* Substition of constants
|
15
|
+
|
5
16
|
## 0.2.1
|
6
17
|
|
7
|
-
|
18
|
+
#### Changes
|
19
|
+
* Defer evaluation of the substitution value block for specs
|
8
20
|
|
9
21
|
## 0.2.0
|
10
22
|
|
data/README.md
CHANGED
@@ -18,7 +18,7 @@ This comes in very handy when you have to derive from default configuration in o
|
|
18
18
|
This gem is [cryptographically signed](https://guides.rubygems.org/security/#using-gems) in order to assure it hasn't been tampered with. Unless already done, please add the author's public key as a trusted certificate now:
|
19
19
|
|
20
20
|
```
|
21
|
-
gem cert --add <(curl -Ls https://
|
21
|
+
gem cert --add <(curl -Ls https://bitcetera.com/downloads/gem-public_cert.pem)
|
22
22
|
```
|
23
23
|
|
24
24
|
Add the following to the <tt>Gemfile</tt> or <tt>gems.rb</tt> of your [Bundler](https://bundler.io) powered Ruby project:
|
@@ -39,6 +39,24 @@ Finally, require this gem in your `test_helper.rb` or `spec_helper.rb`:
|
|
39
39
|
require 'minitest/substitute'
|
40
40
|
```
|
41
41
|
|
42
|
+
## Update from 0.x.x to 1.x.x
|
43
|
+
|
44
|
+
Rails 7 has polluted `Object` for everybody by introducing `Object#with`. To prevent collisions, Minitest::Substitute has switched from `with` to `substitute` as of version 1.0.0.
|
45
|
+
|
46
|
+
After having updated this gem, you'll have to adapt all your tests accordingly:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
# Version 0.x.x
|
50
|
+
with '@version', 2, on: config do
|
51
|
+
config.instance_variable_get('@version') # => 2
|
52
|
+
end
|
53
|
+
|
54
|
+
# Version 1.x.x
|
55
|
+
substitute '@version', 2, on: config do
|
56
|
+
config.instance_variable_get('@version') # => 2
|
57
|
+
end
|
58
|
+
```
|
59
|
+
|
42
60
|
## Usage
|
43
61
|
|
44
62
|
### Block
|
@@ -55,7 +73,7 @@ end
|
|
55
73
|
config = Config.new
|
56
74
|
|
57
75
|
config.instance_variable_get('@version') # => 1
|
58
|
-
|
76
|
+
substitute '@version', 2, on: config do
|
59
77
|
config.instance_variable_get('@version') # => 2
|
60
78
|
end
|
61
79
|
config.instance_variable_get('@version') # => 1
|
@@ -71,7 +89,7 @@ class Config
|
|
71
89
|
end
|
72
90
|
|
73
91
|
Config.class_variable_get('@@counter') # => 0
|
74
|
-
|
92
|
+
substitute '@@counter', 42, on: Config do
|
75
93
|
Config.class_variable_get('@@counter') # => 42
|
76
94
|
end
|
77
95
|
Config.class_variable_get('@@counter') # => 0
|
@@ -81,23 +99,60 @@ Same goes for global variables:
|
|
81
99
|
|
82
100
|
```ruby
|
83
101
|
$verbose = false # => false
|
84
|
-
|
102
|
+
substitute '$verbose', true do
|
85
103
|
$verbose # => true
|
86
104
|
end
|
87
105
|
$verbose # => false
|
88
106
|
```
|
89
107
|
|
90
|
-
And it works for
|
108
|
+
And it works for globals like `ENV` as well which comes in handy when you have to temporarily override the value of an environment variable:
|
91
109
|
|
92
110
|
```ruby
|
93
111
|
ENV['EDITOR'] # => 'vi'
|
94
|
-
|
112
|
+
substitute "ENV['EDITOR']", 'nano' do
|
95
113
|
ENV['EDITOR'] # => 'nano'
|
96
114
|
end
|
97
115
|
ENV['EDITOR'] # => 'vi'
|
98
116
|
```
|
99
117
|
|
100
|
-
|
118
|
+
You can even substitute constants, however, you have to use their absolute name starting with `::`:
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
module Animals
|
122
|
+
DOG_MAKES = 'woof'
|
123
|
+
CAT_MAKES = 'meow'
|
124
|
+
end
|
125
|
+
|
126
|
+
Animals::DOG_MAKES # => 'woof'
|
127
|
+
substitute '::Animals::DOG_MAKES', Animals::CAT_MAKES do
|
128
|
+
Animals::DOG_MAKES # => 'meow'
|
129
|
+
end
|
130
|
+
Animals::DOG_MAKES # => 'woof'
|
131
|
+
```
|
132
|
+
|
133
|
+
Remember that class declarations are assigned to constants as well:
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
class Dog
|
137
|
+
self.makes
|
138
|
+
'woof'
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
class Cat
|
143
|
+
self.makes
|
144
|
+
'meow'
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
Dog.makes # => 'woof'
|
149
|
+
substitute '::Dog', Cat do
|
150
|
+
Dog.makes # => 'meow'
|
151
|
+
end
|
152
|
+
Dog.makes # => 'woof'
|
153
|
+
```
|
154
|
+
|
155
|
+
It's safe to nest multiple `substitute` statements.
|
101
156
|
|
102
157
|
### Group of Tests
|
103
158
|
|
@@ -122,7 +177,7 @@ describe Config do
|
|
122
177
|
end
|
123
178
|
|
124
179
|
describe 'sustituted version' do
|
125
|
-
|
180
|
+
substitute '@version', 2, on: Config
|
126
181
|
|
127
182
|
it "returns the substituted version" do
|
128
183
|
_(subject.instance_variable_get('@version')).must_equal 2
|
@@ -158,7 +213,7 @@ describe Config do
|
|
158
213
|
end
|
159
214
|
|
160
215
|
describe 'sustituted version' do
|
161
|
-
|
216
|
+
substitute '@version', on: Config do
|
162
217
|
version # set using "let" above
|
163
218
|
end
|
164
219
|
|
@@ -171,7 +226,7 @@ end
|
|
171
226
|
|
172
227
|
If both a substitution value and a substitution block are present, the latter takes precedence.
|
173
228
|
|
174
|
-
It's safe to use multiple `
|
229
|
+
It's safe to use multiple `substitute` statements within one `describe` block.
|
175
230
|
|
176
231
|
(The spec integration is borrowed from [minitest-around](https://rubygems.org/gems/minitest-around) for elegance and compatibility.)
|
177
232
|
|
@@ -9,13 +9,13 @@ Minitest::Spec::DSL.class_eval do
|
|
9
9
|
# @param variable [String] instance or global variable name
|
10
10
|
# @param substitute [Object] temporary substitution value
|
11
11
|
# @param on [Object, Symbol, nil] substitute in the context of this object
|
12
|
-
# or in the context of the declared subject if
|
12
|
+
# or in the context of the declared subject if +nil+
|
13
13
|
# @yield temporary substitution value (takes precedence over +substitute+ param)
|
14
|
-
def
|
14
|
+
def substitute(variable, substitute=nil, on: nil, &block)
|
15
15
|
substitutor = Minitest::Substitute::Substitutor.new(variable, on: on)
|
16
16
|
before do
|
17
17
|
substitutor.substitute(block ? instance_eval(&block) : substitute)
|
18
|
-
substitutor.on = subject if on
|
18
|
+
substitutor.on = subject if on.nil? && respond_to?(:subject)
|
19
19
|
substitutor.commit
|
20
20
|
end
|
21
21
|
after do
|
@@ -29,7 +29,7 @@ Minitest::Spec::DSL.class_eval do
|
|
29
29
|
include(Module.new do
|
30
30
|
define_method(:setup) do
|
31
31
|
super()
|
32
|
-
instance_eval
|
32
|
+
instance_eval(&block)
|
33
33
|
end
|
34
34
|
end) # .then &:include
|
35
35
|
end
|
@@ -38,7 +38,7 @@ Minitest::Spec::DSL.class_eval do
|
|
38
38
|
def after(_type=nil, &block)
|
39
39
|
include(Module.new do
|
40
40
|
define_method(:teardown) do
|
41
|
-
instance_eval
|
41
|
+
instance_eval(&block)
|
42
42
|
ensure
|
43
43
|
super()
|
44
44
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Minitest
|
4
4
|
module Substitute
|
5
|
-
module
|
5
|
+
module Substitute
|
6
6
|
|
7
7
|
# Substitute the variable value for the duration of the given block
|
8
8
|
#
|
@@ -11,7 +11,7 @@ module Minitest
|
|
11
11
|
# @param on [Object, nil] substitute in the context of this object
|
12
12
|
# @yield block during which the substitution is made
|
13
13
|
# @return [Object] return value of the yielded block
|
14
|
-
def
|
14
|
+
def substitute(variable, substitute, on: self)
|
15
15
|
substitutor = Minitest::Substitute::Substitutor.new(variable, on: on).substitute(substitute)
|
16
16
|
substitutor.commit
|
17
17
|
yield.tap do
|
@@ -4,12 +4,10 @@ module Minitest
|
|
4
4
|
module Substitute
|
5
5
|
class Substitutor
|
6
6
|
|
7
|
-
EVAL_METHODS = [:instance_eval, :instance_eval, :class_eval].freeze
|
8
|
-
|
9
7
|
attr_writer :on
|
10
8
|
|
11
|
-
def initialize(
|
12
|
-
@
|
9
|
+
def initialize(target, on:)
|
10
|
+
@target, @on = target, on
|
13
11
|
end
|
14
12
|
|
15
13
|
def substitute(value)
|
@@ -28,16 +26,32 @@ module Minitest
|
|
28
26
|
|
29
27
|
private
|
30
28
|
|
31
|
-
def eval_method
|
32
|
-
EVAL_METHODS[@variable.count('@')]
|
33
|
-
end
|
34
|
-
|
35
29
|
def get
|
36
|
-
|
30
|
+
case @target
|
31
|
+
when /^@@/ # class variable
|
32
|
+
@on.class_eval @target.to_s
|
33
|
+
else # constant, instance or global variable
|
34
|
+
@on.instance_eval @target.to_s
|
35
|
+
end
|
37
36
|
end
|
38
37
|
|
39
38
|
def set(value)
|
40
|
-
|
39
|
+
case @target
|
40
|
+
when /^::/
|
41
|
+
remove_const @target
|
42
|
+
eval "#{@target} = value"
|
43
|
+
when /^@@/ # class variable
|
44
|
+
@on.class_eval "#{@target} = value"
|
45
|
+
else # instance or global variable
|
46
|
+
@on.instance_eval "#{@target} = value"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Remove constant without warning
|
51
|
+
def remove_const(const)
|
52
|
+
namespace, _, name = const.rpartition('::')
|
53
|
+
receiver = namespace == '' ? Object : Object.const_get(namespace)
|
54
|
+
receiver.send(:remove_const, name)
|
41
55
|
end
|
42
56
|
|
43
57
|
end
|
data/lib/minitest/substitute.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
require_relative 'substitute/version'
|
4
4
|
|
5
5
|
require_relative 'substitute/substitutor'
|
6
|
-
require_relative 'substitute/
|
6
|
+
require_relative 'substitute/substitute'
|
7
7
|
require_relative 'substitute/spec'
|
8
8
|
|
9
|
-
include Minitest::Substitute::
|
9
|
+
include Minitest::Substitute::Substitute
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minitest-substitute
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sven Schwyn
|
@@ -10,26 +10,24 @@ bindir: bin
|
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qh1yIqXyTA9PGR1w5O6O+WS1FvF+sHCwh8fFjCuStg2L8V2RSeo
|
25
|
+
aDtfZ5s80sL8wRFxg3kek69cBuI6ozU+rf9DaXlMES4i8+zASsdv9Y4a2BsbhEdE
|
26
|
+
9AtuMcWn5a45TOO0S4Q8OuV0v705V38Ow15J2RDRvkFRySt+//8/Vd57XAJxPXU0
|
27
|
+
k/QvZU05f6HMYBrPogJgIzHC/C5N/yeE4BVEuBDn+10Zb1iu3aDk8sd0uMgukCY8
|
28
|
+
TUmlP5A6NeGdeDJIoLgromAKs+nvI7TWzhQq9ODs51XhxgUFRCvBqUTpjTQigw==
|
31
29
|
-----END CERTIFICATE-----
|
32
|
-
date:
|
30
|
+
date: 2024-03-07 00:00:00.000000000 Z
|
33
31
|
dependencies:
|
34
32
|
- !ruby/object:Gem::Dependency
|
35
33
|
name: minitest
|
@@ -176,9 +174,9 @@ files:
|
|
176
174
|
- README.md
|
177
175
|
- lib/minitest/substitute.rb
|
178
176
|
- lib/minitest/substitute/spec.rb
|
177
|
+
- lib/minitest/substitute/substitute.rb
|
179
178
|
- lib/minitest/substitute/substitutor.rb
|
180
179
|
- lib/minitest/substitute/version.rb
|
181
|
-
- lib/minitest/substitute/with.rb
|
182
180
|
homepage: https://github.com/svoop/minitest-substitute
|
183
181
|
licenses:
|
184
182
|
- MIT
|
@@ -188,7 +186,9 @@ metadata:
|
|
188
186
|
source_code_uri: https://github.com/svoop/minitest-substitute
|
189
187
|
documentation_uri: https://www.rubydoc.info/gems/minitest-substitute
|
190
188
|
bug_tracker_uri: https://github.com/svoop/minitest-substitute/issues
|
191
|
-
post_install_message:
|
189
|
+
post_install_message: '⚠️ Breaking change: minitest-substitute >= 1.0.0 switched from
|
190
|
+
"with" to "substitute" to prevent conflicts with Rails 7. Please read the update
|
191
|
+
section in the README.'
|
192
192
|
rdoc_options:
|
193
193
|
- "--title"
|
194
194
|
- Minitest::Substitute
|
@@ -210,7 +210,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
210
210
|
- !ruby/object:Gem::Version
|
211
211
|
version: '0'
|
212
212
|
requirements: []
|
213
|
-
rubygems_version: 3.
|
213
|
+
rubygems_version: 3.5.6
|
214
214
|
signing_key:
|
215
215
|
specification_version: 4
|
216
216
|
summary: Substitute values for the duration of a block or a group of tests
|
metadata.gz.sig
CHANGED
Binary file
|