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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 288e4fc7e4e20c4b649237471762f8723ce333f2886d4244048033ea281c4ab2
4
- data.tar.gz: ee23d391142761ea6be22ecb306944313e612fc697c4849ab4f70c7a6ce8e844
3
+ metadata.gz: ada3a9ae885b2050d30579935751f6f6d6d3a668b299def79602098549897ff6
4
+ data.tar.gz: 2892e09363f655605a9c7f19da56cc40f2229d44cb332e4b583d50f193c18cef
5
5
  SHA512:
6
- metadata.gz: 6d2abd17135f9a750c2e7efb89e1fbc4d2b1ce30a7767e60ad368715059de575435e36856128e5e911c495cfc407169ef68baf9176721ee11eb28f55197fb13f
7
- data.tar.gz: ba8d78a68880474bd1051887ad5435e0efdda86aa78c643ddad004bdf606e725ee688385da114abdc4dfb110ad5eb42e5c1a7de146de380e49372296ae6ec9de
6
+ metadata.gz: 3222b3c80b2cf6aee7451d14f602b6aa154367a4ef95b873bc1917d2c76ab240df9183a2322c917507737059eb7a83b3d17f5952c8363f23874c04e4eaa81eda
7
+ data.tar.gz: d85e9ea4fb25448a7065c0d0c32a0aa28b00df47cc03495d72b2f8df8134c43fb7aadb920dda4c1b71792012a0bf048f1ac7f0e863bf55b4b30d4a6b780449bb
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  Nothing so far
4
4
 
5
+ ## 0.2.1
6
+
7
+ Nothing so far
8
+
5
9
  ## 0.2.0
6
10
 
7
11
  #### Additions
data/README.md CHANGED
@@ -131,15 +131,45 @@ describe Config do
131
131
  end
132
132
  ```
133
133
 
134
- For consistency with other Minitest helpers, the following alternative does exactly the same:
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
- with '@version', on: Config do
138
- 2
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
- :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.
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
- substitute = yield if block_given?
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, substitute, on:)
12
- @variable, @substitute, @on = variable, substitute, on
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Minitest
4
4
  module Substitute
5
- VERSION = '0.2.0'
5
+ VERSION = '0.2.1'
6
6
  end
7
7
  end
@@ -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, substitute, on: on)
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.0
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-08-25 00:00:00.000000000 Z
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