minitest-substitute 0.2.0 → 0.2.1
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 +4 -0
- data/README.md +34 -4
- data/lib/minitest/substitute/spec.rb +3 -3
- data/lib/minitest/substitute/substitutor.rb +7 -2
- data/lib/minitest/substitute/version.rb +1 -1
- data/lib/minitest/substitute/with.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +2 -2
- 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: ada3a9ae885b2050d30579935751f6f6d6d3a668b299def79602098549897ff6
|
4
|
+
data.tar.gz: 2892e09363f655605a9c7f19da56cc40f2229d44cb332e4b583d50f193c18cef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3222b3c80b2cf6aee7451d14f602b6aa154367a4ef95b873bc1917d2c76ab240df9183a2322c917507737059eb7a83b3d17f5952c8363f23874c04e4eaa81eda
|
7
|
+
data.tar.gz: d85e9ea4fb25448a7065c0d0c32a0aa28b00df47cc03495d72b2f8df8134c43fb7aadb920dda4c1b71792012a0bf048f1ac7f0e863bf55b4b30d4a6b780449bb
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -131,15 +131,45 @@ describe Config do
|
|
131
131
|
end
|
132
132
|
```
|
133
133
|
|
134
|
-
|
134
|
+
:warning: The target `on` is set explicitly in this case. If you omit this argument, `:subject` will be used as target by default which refers to the subject defined by the `subject {}` helper.
|
135
|
+
|
136
|
+
Alternatively, you can pass the substitution value as a block. This block will be evaluated once in the context of the test, in other words, you can use assignments done with `let` inside the block:
|
135
137
|
|
136
138
|
```ruby
|
137
|
-
|
138
|
-
|
139
|
+
class Config
|
140
|
+
def initialize
|
141
|
+
@version = 1
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
describe Config do
|
146
|
+
subject do
|
147
|
+
Config.new
|
148
|
+
end
|
149
|
+
|
150
|
+
let :version do
|
151
|
+
2
|
152
|
+
end
|
153
|
+
|
154
|
+
describe 'original version' do
|
155
|
+
it "returns the original version" do
|
156
|
+
_(subject.instance_variable_get('@version')).must_equal 1
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe 'sustituted version' do
|
161
|
+
with '@version', on: Config do
|
162
|
+
version # set using "let" above
|
163
|
+
end
|
164
|
+
|
165
|
+
it "returns the substituted version" do
|
166
|
+
_(subject.instance_variable_get('@version')).must_equal 2
|
167
|
+
end
|
168
|
+
end
|
139
169
|
end
|
140
170
|
```
|
141
171
|
|
142
|
-
|
172
|
+
If both a substitution value and a substitution block are present, the latter takes precedence.
|
143
173
|
|
144
174
|
It's safe to use multiple `with` statements within one `describe` block.
|
145
175
|
|
@@ -11,10 +11,10 @@ Minitest::Spec::DSL.class_eval do
|
|
11
11
|
# @param on [Object, Symbol, nil] substitute in the context of this object
|
12
12
|
# or in the context of the declared subject if +:subject+ is set
|
13
13
|
# @yield temporary substitution value (takes precedence over +substitute+ param)
|
14
|
-
def with(variable, substitute=nil, on: :subject)
|
15
|
-
|
16
|
-
substitutor = Minitest::Substitute::Substitutor.new(variable, substitute, on: on)
|
14
|
+
def with(variable, substitute=nil, on: :subject, &block)
|
15
|
+
substitutor = Minitest::Substitute::Substitutor.new(variable, on: on)
|
17
16
|
before do
|
17
|
+
substitutor.substitute(block ? instance_eval(&block) : substitute)
|
18
18
|
substitutor.on = subject if on == :subject && respond_to?(:subject)
|
19
19
|
substitutor.commit
|
20
20
|
end
|
@@ -8,8 +8,13 @@ module Minitest
|
|
8
8
|
|
9
9
|
attr_writer :on
|
10
10
|
|
11
|
-
def initialize(variable,
|
12
|
-
@variable, @
|
11
|
+
def initialize(variable, on:)
|
12
|
+
@variable, @on = variable, on
|
13
|
+
end
|
14
|
+
|
15
|
+
def substitute(value)
|
16
|
+
@substitute = value unless instance_variable_defined? :@substitute
|
17
|
+
self
|
13
18
|
end
|
14
19
|
|
15
20
|
def commit
|
@@ -12,7 +12,7 @@ module Minitest
|
|
12
12
|
# @yield block during which the substitution is made
|
13
13
|
# @return [Object] return value of the yielded block
|
14
14
|
def with(variable, substitute, on: self)
|
15
|
-
substitutor = Minitest::Substitute::Substitutor.new(variable,
|
15
|
+
substitutor = Minitest::Substitute::Substitutor.new(variable, on: on).substitute(substitute)
|
16
16
|
substitutor.commit
|
17
17
|
yield.tap do
|
18
18
|
substitutor.rollback
|
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.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sven Schwyn
|
@@ -29,7 +29,7 @@ cert_chain:
|
|
29
29
|
kAyiRqgxF4dJviwtqI7mZIomWL63+kXLgjOjMe1SHxfIPo/0ji6+r1p4KYa7o41v
|
30
30
|
fwIwU1MKlFBdsjkd
|
31
31
|
-----END CERTIFICATE-----
|
32
|
-
date: 2023-
|
32
|
+
date: 2023-09-06 00:00:00.000000000 Z
|
33
33
|
dependencies:
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
35
|
name: minitest
|
metadata.gz.sig
CHANGED
Binary file
|