minitest 5.12.0 → 5.22.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/History.rdoc +262 -5
- data/Manifest.txt +3 -0
- data/README.rdoc +90 -17
- data/Rakefile +5 -16
- data/lib/hoe/minitest.rb +0 -4
- data/lib/minitest/assertions.rb +171 -37
- data/lib/minitest/benchmark.rb +7 -7
- data/lib/minitest/compress.rb +94 -0
- data/lib/minitest/expectations.rb +72 -35
- data/lib/minitest/mock.rb +123 -34
- data/lib/minitest/pride_plugin.rb +1 -1
- data/lib/minitest/spec.rb +24 -10
- data/lib/minitest/test.rb +44 -16
- data/lib/minitest/test_task.rb +301 -0
- data/lib/minitest/unit.rb +5 -8
- data/lib/minitest.rb +245 -70
- data/test/minitest/metametameta.rb +45 -11
- data/test/minitest/test_minitest_assertions.rb +357 -29
- data/test/minitest/test_minitest_benchmark.rb +2 -2
- data/test/minitest/test_minitest_mock.rb +287 -15
- data/test/minitest/test_minitest_reporter.rb +158 -17
- data/test/minitest/test_minitest_spec.rb +184 -59
- data/test/minitest/test_minitest_test.rb +362 -42
- data/test/minitest/test_minitest_test_task.rb +46 -0
- data.tar.gz.sig +2 -2
- metadata +28 -19
- metadata.gz.sig +0 -0
@@ -9,10 +9,11 @@
|
|
9
9
|
#
|
10
10
|
# it "should still work in threads" do
|
11
11
|
# my_threaded_thingy do
|
12
|
-
# (1+1).must_equal 2
|
13
|
-
# assert_equal 2, 1+1
|
14
|
-
# _(1 + 1).must_equal 2
|
15
|
-
# value(1 + 1).must_equal 2
|
12
|
+
# (1+1).must_equal 2 # bad
|
13
|
+
# assert_equal 2, 1+1 # good
|
14
|
+
# _(1 + 1).must_equal 2 # good
|
15
|
+
# value(1 + 1).must_equal 2 # good, also #expect
|
16
|
+
# _ { 1 + "1" }.must_raise TypeError # good
|
16
17
|
# end
|
17
18
|
# end
|
18
19
|
|
@@ -21,7 +22,7 @@ module Minitest::Expectations
|
|
21
22
|
##
|
22
23
|
# See Minitest::Assertions#assert_empty.
|
23
24
|
#
|
24
|
-
# collection.must_be_empty
|
25
|
+
# _(collection).must_be_empty
|
25
26
|
#
|
26
27
|
# :method: must_be_empty
|
27
28
|
|
@@ -30,7 +31,7 @@ module Minitest::Expectations
|
|
30
31
|
##
|
31
32
|
# See Minitest::Assertions#assert_equal
|
32
33
|
#
|
33
|
-
# a.must_equal b
|
34
|
+
# _(a).must_equal b
|
34
35
|
#
|
35
36
|
# :method: must_equal
|
36
37
|
|
@@ -39,18 +40,18 @@ module Minitest::Expectations
|
|
39
40
|
##
|
40
41
|
# See Minitest::Assertions#assert_in_delta
|
41
42
|
#
|
42
|
-
# n.must_be_close_to m [, delta]
|
43
|
+
# _(n).must_be_close_to m [, delta]
|
43
44
|
#
|
44
45
|
# :method: must_be_close_to
|
45
46
|
|
46
47
|
infect_an_assertion :assert_in_delta, :must_be_close_to
|
47
48
|
|
48
|
-
|
49
|
+
infect_an_assertion :assert_in_delta, :must_be_within_delta # :nodoc:
|
49
50
|
|
50
51
|
##
|
51
52
|
# See Minitest::Assertions#assert_in_epsilon
|
52
53
|
#
|
53
|
-
# n.must_be_within_epsilon m [, epsilon]
|
54
|
+
# _(n).must_be_within_epsilon m [, epsilon]
|
54
55
|
#
|
55
56
|
# :method: must_be_within_epsilon
|
56
57
|
|
@@ -59,7 +60,7 @@ module Minitest::Expectations
|
|
59
60
|
##
|
60
61
|
# See Minitest::Assertions#assert_includes
|
61
62
|
#
|
62
|
-
# collection.must_include obj
|
63
|
+
# _(collection).must_include obj
|
63
64
|
#
|
64
65
|
# :method: must_include
|
65
66
|
|
@@ -68,7 +69,7 @@ module Minitest::Expectations
|
|
68
69
|
##
|
69
70
|
# See Minitest::Assertions#assert_instance_of
|
70
71
|
#
|
71
|
-
# obj.must_be_instance_of klass
|
72
|
+
# _(obj).must_be_instance_of klass
|
72
73
|
#
|
73
74
|
# :method: must_be_instance_of
|
74
75
|
|
@@ -77,7 +78,7 @@ module Minitest::Expectations
|
|
77
78
|
##
|
78
79
|
# See Minitest::Assertions#assert_kind_of
|
79
80
|
#
|
80
|
-
# obj.must_be_kind_of mod
|
81
|
+
# _(obj).must_be_kind_of mod
|
81
82
|
#
|
82
83
|
# :method: must_be_kind_of
|
83
84
|
|
@@ -86,7 +87,7 @@ module Minitest::Expectations
|
|
86
87
|
##
|
87
88
|
# See Minitest::Assertions#assert_match
|
88
89
|
#
|
89
|
-
# a.must_match b
|
90
|
+
# _(a).must_match b
|
90
91
|
#
|
91
92
|
# :method: must_match
|
92
93
|
|
@@ -95,7 +96,7 @@ module Minitest::Expectations
|
|
95
96
|
##
|
96
97
|
# See Minitest::Assertions#assert_nil
|
97
98
|
#
|
98
|
-
# obj.must_be_nil
|
99
|
+
# _(obj).must_be_nil
|
99
100
|
#
|
100
101
|
# :method: must_be_nil
|
101
102
|
|
@@ -104,11 +105,11 @@ module Minitest::Expectations
|
|
104
105
|
##
|
105
106
|
# See Minitest::Assertions#assert_operator
|
106
107
|
#
|
107
|
-
# n.must_be :<=, 42
|
108
|
+
# _(n).must_be :<=, 42
|
108
109
|
#
|
109
110
|
# This can also do predicates:
|
110
111
|
#
|
111
|
-
# str.must_be :empty?
|
112
|
+
# _(str).must_be :empty?
|
112
113
|
#
|
113
114
|
# :method: must_be
|
114
115
|
|
@@ -117,16 +118,25 @@ module Minitest::Expectations
|
|
117
118
|
##
|
118
119
|
# See Minitest::Assertions#assert_output
|
119
120
|
#
|
120
|
-
#
|
121
|
+
# _ { ... }.must_output out_or_nil [, err]
|
121
122
|
#
|
122
123
|
# :method: must_output
|
123
124
|
|
124
125
|
infect_an_assertion :assert_output, :must_output, :block
|
125
126
|
|
127
|
+
##
|
128
|
+
# See Minitest::Assertions#assert_pattern_match
|
129
|
+
#
|
130
|
+
# _ { ... }.must_pattern_match [...]
|
131
|
+
#
|
132
|
+
# :method: must_pattern_match
|
133
|
+
|
134
|
+
infect_an_assertion :assert_pattern, :must_pattern_match, :block
|
135
|
+
|
126
136
|
##
|
127
137
|
# See Minitest::Assertions#assert_raises
|
128
138
|
#
|
129
|
-
#
|
139
|
+
# _ { ... }.must_raise exception
|
130
140
|
#
|
131
141
|
# :method: must_raise
|
132
142
|
|
@@ -135,7 +145,7 @@ module Minitest::Expectations
|
|
135
145
|
##
|
136
146
|
# See Minitest::Assertions#assert_respond_to
|
137
147
|
#
|
138
|
-
# obj.must_respond_to msg
|
148
|
+
# _(obj).must_respond_to msg
|
139
149
|
#
|
140
150
|
# :method: must_respond_to
|
141
151
|
|
@@ -144,7 +154,7 @@ module Minitest::Expectations
|
|
144
154
|
##
|
145
155
|
# See Minitest::Assertions#assert_same
|
146
156
|
#
|
147
|
-
# a.must_be_same_as b
|
157
|
+
# _(a).must_be_same_as b
|
148
158
|
#
|
149
159
|
# :method: must_be_same_as
|
150
160
|
|
@@ -153,7 +163,7 @@ module Minitest::Expectations
|
|
153
163
|
##
|
154
164
|
# See Minitest::Assertions#assert_silent
|
155
165
|
#
|
156
|
-
#
|
166
|
+
# _ { ... }.must_be_silent
|
157
167
|
#
|
158
168
|
# :method: must_be_silent
|
159
169
|
|
@@ -162,16 +172,34 @@ module Minitest::Expectations
|
|
162
172
|
##
|
163
173
|
# See Minitest::Assertions#assert_throws
|
164
174
|
#
|
165
|
-
#
|
175
|
+
# _ { ... }.must_throw sym
|
166
176
|
#
|
167
177
|
# :method: must_throw
|
168
178
|
|
169
179
|
infect_an_assertion :assert_throws, :must_throw, :block
|
170
180
|
|
181
|
+
##
|
182
|
+
# See Minitest::Assertions#assert_path_exists
|
183
|
+
#
|
184
|
+
# _(some_path).path_must_exist
|
185
|
+
#
|
186
|
+
# :method: path_must_exist
|
187
|
+
|
188
|
+
infect_an_assertion :assert_path_exists, :path_must_exist, :unary
|
189
|
+
|
190
|
+
##
|
191
|
+
# See Minitest::Assertions#refute_path_exists
|
192
|
+
#
|
193
|
+
# _(some_path).path_wont_exist
|
194
|
+
#
|
195
|
+
# :method: path_wont_exist
|
196
|
+
|
197
|
+
infect_an_assertion :refute_path_exists, :path_wont_exist, :unary
|
198
|
+
|
171
199
|
##
|
172
200
|
# See Minitest::Assertions#refute_empty
|
173
201
|
#
|
174
|
-
# collection.wont_be_empty
|
202
|
+
# _(collection).wont_be_empty
|
175
203
|
#
|
176
204
|
# :method: wont_be_empty
|
177
205
|
|
@@ -180,7 +208,7 @@ module Minitest::Expectations
|
|
180
208
|
##
|
181
209
|
# See Minitest::Assertions#refute_equal
|
182
210
|
#
|
183
|
-
# a.wont_equal b
|
211
|
+
# _(a).wont_equal b
|
184
212
|
#
|
185
213
|
# :method: wont_equal
|
186
214
|
|
@@ -189,18 +217,18 @@ module Minitest::Expectations
|
|
189
217
|
##
|
190
218
|
# See Minitest::Assertions#refute_in_delta
|
191
219
|
#
|
192
|
-
# n.wont_be_close_to m [, delta]
|
220
|
+
# _(n).wont_be_close_to m [, delta]
|
193
221
|
#
|
194
222
|
# :method: wont_be_close_to
|
195
223
|
|
196
224
|
infect_an_assertion :refute_in_delta, :wont_be_close_to
|
197
225
|
|
198
|
-
|
226
|
+
infect_an_assertion :refute_in_delta, :wont_be_within_delta # :nodoc:
|
199
227
|
|
200
228
|
##
|
201
229
|
# See Minitest::Assertions#refute_in_epsilon
|
202
230
|
#
|
203
|
-
# n.wont_be_within_epsilon m [, epsilon]
|
231
|
+
# _(n).wont_be_within_epsilon m [, epsilon]
|
204
232
|
#
|
205
233
|
# :method: wont_be_within_epsilon
|
206
234
|
|
@@ -209,7 +237,7 @@ module Minitest::Expectations
|
|
209
237
|
##
|
210
238
|
# See Minitest::Assertions#refute_includes
|
211
239
|
#
|
212
|
-
# collection.wont_include obj
|
240
|
+
# _(collection).wont_include obj
|
213
241
|
#
|
214
242
|
# :method: wont_include
|
215
243
|
|
@@ -218,7 +246,7 @@ module Minitest::Expectations
|
|
218
246
|
##
|
219
247
|
# See Minitest::Assertions#refute_instance_of
|
220
248
|
#
|
221
|
-
# obj.wont_be_instance_of klass
|
249
|
+
# _(obj).wont_be_instance_of klass
|
222
250
|
#
|
223
251
|
# :method: wont_be_instance_of
|
224
252
|
|
@@ -227,7 +255,7 @@ module Minitest::Expectations
|
|
227
255
|
##
|
228
256
|
# See Minitest::Assertions#refute_kind_of
|
229
257
|
#
|
230
|
-
# obj.wont_be_kind_of mod
|
258
|
+
# _(obj).wont_be_kind_of mod
|
231
259
|
#
|
232
260
|
# :method: wont_be_kind_of
|
233
261
|
|
@@ -236,7 +264,7 @@ module Minitest::Expectations
|
|
236
264
|
##
|
237
265
|
# See Minitest::Assertions#refute_match
|
238
266
|
#
|
239
|
-
# a.wont_match b
|
267
|
+
# _(a).wont_match b
|
240
268
|
#
|
241
269
|
# :method: wont_match
|
242
270
|
|
@@ -245,7 +273,7 @@ module Minitest::Expectations
|
|
245
273
|
##
|
246
274
|
# See Minitest::Assertions#refute_nil
|
247
275
|
#
|
248
|
-
# obj.wont_be_nil
|
276
|
+
# _(obj).wont_be_nil
|
249
277
|
#
|
250
278
|
# :method: wont_be_nil
|
251
279
|
|
@@ -254,7 +282,7 @@ module Minitest::Expectations
|
|
254
282
|
##
|
255
283
|
# See Minitest::Assertions#refute_operator
|
256
284
|
#
|
257
|
-
# n.wont_be :<=, 42
|
285
|
+
# _(n).wont_be :<=, 42
|
258
286
|
#
|
259
287
|
# This can also do predicates:
|
260
288
|
#
|
@@ -264,10 +292,19 @@ module Minitest::Expectations
|
|
264
292
|
|
265
293
|
infect_an_assertion :refute_operator, :wont_be, :reverse
|
266
294
|
|
295
|
+
##
|
296
|
+
# See Minitest::Assertions#refute_pattern_match
|
297
|
+
#
|
298
|
+
# _ { ... }.wont_pattern_match [...]
|
299
|
+
#
|
300
|
+
# :method: wont_pattern_match
|
301
|
+
|
302
|
+
infect_an_assertion :refute_pattern, :wont_pattern_match, :block
|
303
|
+
|
267
304
|
##
|
268
305
|
# See Minitest::Assertions#refute_respond_to
|
269
306
|
#
|
270
|
-
# obj.wont_respond_to msg
|
307
|
+
# _(obj).wont_respond_to msg
|
271
308
|
#
|
272
309
|
# :method: wont_respond_to
|
273
310
|
|
@@ -276,7 +313,7 @@ module Minitest::Expectations
|
|
276
313
|
##
|
277
314
|
# See Minitest::Assertions#refute_same
|
278
315
|
#
|
279
|
-
# a.wont_be_same_as b
|
316
|
+
# _(a).wont_be_same_as b
|
280
317
|
#
|
281
318
|
# :method: wont_be_same_as
|
282
319
|
|
data/lib/minitest/mock.rb
CHANGED
@@ -10,7 +10,7 @@ module Minitest # :nodoc:
|
|
10
10
|
class Mock
|
11
11
|
alias :__respond_to? :respond_to?
|
12
12
|
|
13
|
-
overridden_methods = %
|
13
|
+
overridden_methods = %i[
|
14
14
|
===
|
15
15
|
class
|
16
16
|
inspect
|
@@ -23,16 +23,26 @@ module Minitest # :nodoc:
|
|
23
23
|
to_s
|
24
24
|
]
|
25
25
|
|
26
|
+
overridden_methods << :singleton_method_added if defined?(::DEBUGGER__)
|
27
|
+
|
26
28
|
instance_methods.each do |m|
|
27
|
-
undef_method m unless overridden_methods.include?(m
|
29
|
+
undef_method m unless overridden_methods.include?(m) || m =~ /^__/
|
28
30
|
end
|
29
31
|
|
30
32
|
overridden_methods.map(&:to_sym).each do |method_id|
|
31
|
-
define_method method_id do |*args, &b|
|
33
|
+
define_method method_id do |*args, **kwargs, &b|
|
32
34
|
if @expected_calls.key? method_id then
|
33
|
-
|
35
|
+
if kwargs.empty? then # FIX: drop this after 2.7 dead
|
36
|
+
method_missing(method_id, *args, &b)
|
37
|
+
else
|
38
|
+
method_missing(method_id, *args, **kwargs, &b)
|
39
|
+
end
|
34
40
|
else
|
35
|
-
|
41
|
+
if kwargs.empty? then # FIX: drop this after 2.7 dead
|
42
|
+
super(*args, &b)
|
43
|
+
else
|
44
|
+
super(*args, **kwargs, &b)
|
45
|
+
end
|
36
46
|
end
|
37
47
|
end
|
38
48
|
end
|
@@ -43,9 +53,11 @@ module Minitest # :nodoc:
|
|
43
53
|
@actual_calls = Hash.new { |calls, name| calls[name] = [] }
|
44
54
|
end
|
45
55
|
|
56
|
+
@@KW_WARNED = false # :nodoc:
|
57
|
+
|
46
58
|
##
|
47
|
-
# Expect that method +name+ is called, optionally with +args+
|
48
|
-
# +blk
|
59
|
+
# Expect that method +name+ is called, optionally with +args+ (and
|
60
|
+
# +kwargs+ or a +blk+), and returns +retval+.
|
49
61
|
#
|
50
62
|
# @mock.expect(:meaning_of_life, 42)
|
51
63
|
# @mock.meaning_of_life # => 42
|
@@ -78,15 +90,31 @@ module Minitest # :nodoc:
|
|
78
90
|
# @mock.ordinal_increment # => raises MockExpectationError "No more expects available for :ordinal_increment"
|
79
91
|
#
|
80
92
|
|
81
|
-
def expect name, retval, args = [], &blk
|
93
|
+
def expect name, retval, args = [], **kwargs, &blk
|
82
94
|
name = name.to_sym
|
83
95
|
|
84
96
|
if block_given?
|
85
97
|
raise ArgumentError, "args ignored when block given" unless args.empty?
|
98
|
+
raise ArgumentError, "kwargs ignored when block given" unless kwargs.empty?
|
86
99
|
@expected_calls[name] << { :retval => retval, :block => blk }
|
87
100
|
else
|
88
101
|
raise ArgumentError, "args must be an array" unless Array === args
|
89
|
-
|
102
|
+
|
103
|
+
if ENV["MT_KWARGS_HAC\K"] && (Hash === args.last ||
|
104
|
+
Hash == args.last) then
|
105
|
+
if kwargs.empty? then
|
106
|
+
kwargs = args.pop
|
107
|
+
else
|
108
|
+
unless @@KW_WARNED then
|
109
|
+
from = caller.first
|
110
|
+
warn "Using MT_KWARGS_HAC\K yet passing kwargs. From #{from}"
|
111
|
+
@@KW_WARNED = true
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
@expected_calls[name] <<
|
117
|
+
{ :retval => retval, :args => args, :kwargs => kwargs }
|
90
118
|
end
|
91
119
|
self
|
92
120
|
end
|
@@ -94,7 +122,13 @@ module Minitest # :nodoc:
|
|
94
122
|
def __call name, data # :nodoc:
|
95
123
|
case data
|
96
124
|
when Hash then
|
97
|
-
|
125
|
+
args = data[:args].inspect[1..-2]
|
126
|
+
kwargs = data[:kwargs]
|
127
|
+
if kwargs && !kwargs.empty? then
|
128
|
+
args << ", " unless args.empty?
|
129
|
+
args << kwargs.inspect[1..-2]
|
130
|
+
end
|
131
|
+
"#{name}(#{args}) => #{data[:retval].inspect}"
|
98
132
|
else
|
99
133
|
data.map { |d| __call name, d }.join ", "
|
100
134
|
end
|
@@ -115,10 +149,14 @@ module Minitest # :nodoc:
|
|
115
149
|
true
|
116
150
|
end
|
117
151
|
|
118
|
-
def method_missing sym, *args, &block # :nodoc:
|
152
|
+
def method_missing sym, *args, **kwargs, &block # :nodoc:
|
119
153
|
unless @expected_calls.key?(sym) then
|
120
154
|
if @delegator && @delegator.respond_to?(sym)
|
121
|
-
|
155
|
+
if kwargs.empty? then # FIX: drop this after 2.7 dead
|
156
|
+
return @delegator.public_send(sym, *args, &block)
|
157
|
+
else
|
158
|
+
return @delegator.public_send(sym, *args, **kwargs, &block)
|
159
|
+
end
|
122
160
|
else
|
123
161
|
raise NoMethodError, "unmocked method %p, expected one of %p" %
|
124
162
|
[sym, @expected_calls.keys.sort_by(&:to_s)]
|
@@ -129,26 +167,34 @@ module Minitest # :nodoc:
|
|
129
167
|
expected_call = @expected_calls[sym][index]
|
130
168
|
|
131
169
|
unless expected_call then
|
132
|
-
raise MockExpectationError, "No more expects available for %p: %p" %
|
133
|
-
[sym, args]
|
170
|
+
raise MockExpectationError, "No more expects available for %p: %p %p" %
|
171
|
+
[sym, args, kwargs]
|
134
172
|
end
|
135
173
|
|
136
|
-
expected_args, retval, val_block =
|
137
|
-
expected_call.values_at(:args, :retval, :block)
|
174
|
+
expected_args, expected_kwargs, retval, val_block =
|
175
|
+
expected_call.values_at(:args, :kwargs, :retval, :block)
|
176
|
+
|
177
|
+
expected_kwargs = kwargs.map { |ak, av| [ak, Object] }.to_h if
|
178
|
+
Hash == expected_kwargs
|
138
179
|
|
139
180
|
if val_block then
|
140
181
|
# keep "verify" happy
|
141
182
|
@actual_calls[sym] << expected_call
|
142
183
|
|
143
|
-
raise MockExpectationError, "mocked method %p failed block w/ %p" %
|
144
|
-
[sym, args] unless val_block.call(*args, &block)
|
184
|
+
raise MockExpectationError, "mocked method %p failed block w/ %p %p" %
|
185
|
+
[sym, args, kwargs] unless val_block.call(*args, **kwargs, &block)
|
145
186
|
|
146
187
|
return retval
|
147
188
|
end
|
148
189
|
|
149
190
|
if expected_args.size != args.size then
|
150
|
-
raise ArgumentError, "mocked method %p expects %d arguments, got %
|
151
|
-
[sym, expected_args.size, args
|
191
|
+
raise ArgumentError, "mocked method %p expects %d arguments, got %p" %
|
192
|
+
[sym, expected_args.size, args]
|
193
|
+
end
|
194
|
+
|
195
|
+
if expected_kwargs.size != kwargs.size then
|
196
|
+
raise ArgumentError, "mocked method %p expects %d keyword arguments, got %p" %
|
197
|
+
[sym, expected_kwargs.size, kwargs]
|
152
198
|
end
|
153
199
|
|
154
200
|
zipped_args = expected_args.zip(args)
|
@@ -157,13 +203,33 @@ module Minitest # :nodoc:
|
|
157
203
|
}
|
158
204
|
|
159
205
|
unless fully_matched then
|
160
|
-
|
161
|
-
|
206
|
+
fmt = "mocked method %p called with unexpected arguments %p"
|
207
|
+
raise MockExpectationError, fmt % [sym, args]
|
208
|
+
end
|
209
|
+
|
210
|
+
unless expected_kwargs.keys.sort == kwargs.keys.sort then
|
211
|
+
fmt = "mocked method %p called with unexpected keywords %p vs %p"
|
212
|
+
raise MockExpectationError, fmt % [sym, expected_kwargs.keys, kwargs.keys]
|
213
|
+
end
|
214
|
+
|
215
|
+
zipped_kwargs = expected_kwargs.map { |ek, ev|
|
216
|
+
av = kwargs[ek]
|
217
|
+
[ek, [ev, av]]
|
218
|
+
}.to_h
|
219
|
+
|
220
|
+
fully_matched = zipped_kwargs.all? { |ek, (ev, av)|
|
221
|
+
ev === av or ev == av
|
222
|
+
}
|
223
|
+
|
224
|
+
unless fully_matched then
|
225
|
+
fmt = "mocked method %p called with unexpected keyword arguments %p vs %p"
|
226
|
+
raise MockExpectationError, fmt % [sym, expected_kwargs, kwargs]
|
162
227
|
end
|
163
228
|
|
164
229
|
@actual_calls[sym] << {
|
165
230
|
:retval => retval,
|
166
|
-
:args => zipped_args.map
|
231
|
+
:args => zipped_args.map { |e, a| e === a ? e : a },
|
232
|
+
:kwargs => zipped_kwargs.map { |k, (e, a)| [k, e === a ? e : a] }.to_h,
|
167
233
|
}
|
168
234
|
|
169
235
|
retval
|
@@ -207,31 +273,54 @@ class Object
|
|
207
273
|
# assert obj_under_test.stale?
|
208
274
|
# end
|
209
275
|
# end
|
210
|
-
|
276
|
+
#--
|
277
|
+
# NOTE: keyword args in callables are NOT checked for correctness
|
278
|
+
# against the existing method. Too many edge cases to be worth it.
|
211
279
|
|
212
|
-
def stub name, val_or_callable, *block_args
|
280
|
+
def stub name, val_or_callable, *block_args, **block_kwargs, &block
|
213
281
|
new_name = "__minitest_stub__#{name}"
|
214
282
|
|
215
283
|
metaclass = class << self; self; end
|
216
284
|
|
217
285
|
if respond_to? name and not methods.map(&:to_s).include? name.to_s then
|
218
|
-
metaclass.send :define_method, name do |*args|
|
219
|
-
super(*args)
|
286
|
+
metaclass.send :define_method, name do |*args, **kwargs|
|
287
|
+
super(*args, **kwargs)
|
220
288
|
end
|
221
289
|
end
|
222
290
|
|
223
291
|
metaclass.send :alias_method, new_name, name
|
224
292
|
|
225
|
-
|
226
|
-
|
227
|
-
val_or_callable.call
|
228
|
-
|
229
|
-
|
230
|
-
|
293
|
+
if ENV["MT_KWARGS_HAC\K"] then
|
294
|
+
metaclass.send :define_method, name do |*args, &blk|
|
295
|
+
if val_or_callable.respond_to? :call then
|
296
|
+
val_or_callable.call(*args, &blk)
|
297
|
+
else
|
298
|
+
blk.call(*block_args, **block_kwargs) if blk
|
299
|
+
val_or_callable
|
300
|
+
end
|
301
|
+
end
|
302
|
+
else
|
303
|
+
metaclass.send :define_method, name do |*args, **kwargs, &blk|
|
304
|
+
if val_or_callable.respond_to? :call then
|
305
|
+
if kwargs.empty? then # FIX: drop this after 2.7 dead
|
306
|
+
val_or_callable.call(*args, &blk)
|
307
|
+
else
|
308
|
+
val_or_callable.call(*args, **kwargs, &blk)
|
309
|
+
end
|
310
|
+
else
|
311
|
+
if blk then
|
312
|
+
if block_kwargs.empty? then # FIX: drop this after 2.7 dead
|
313
|
+
blk.call(*block_args)
|
314
|
+
else
|
315
|
+
blk.call(*block_args, **block_kwargs)
|
316
|
+
end
|
317
|
+
end
|
318
|
+
val_or_callable
|
319
|
+
end
|
231
320
|
end
|
232
321
|
end
|
233
322
|
|
234
|
-
|
323
|
+
block[self]
|
235
324
|
ensure
|
236
325
|
metaclass.send :undef_method, name
|
237
326
|
metaclass.send :alias_method, name, new_name
|
@@ -48,7 +48,7 @@ module Minitest
|
|
48
48
|
def initialize io # :nodoc:
|
49
49
|
@io = io
|
50
50
|
# stolen from /System/Library/Perl/5.10.0/Term/ANSIColor.pm
|
51
|
-
# also reference
|
51
|
+
# also reference https://en.wikipedia.org/wiki/ANSI_escape_code
|
52
52
|
@colors ||= (31..36).to_a
|
53
53
|
@size = @colors.size
|
54
54
|
@index = 0
|
data/lib/minitest/spec.rb
CHANGED
@@ -4,15 +4,21 @@ class Module # :nodoc:
|
|
4
4
|
def infect_an_assertion meth, new_name, dont_flip = false # :nodoc:
|
5
5
|
block = dont_flip == :block
|
6
6
|
dont_flip = false if block
|
7
|
+
target_obj = block ? '_{obj.method}' : '_(obj)'
|
8
|
+
|
9
|
+
# https://eregon.me/blog/2021/02/13/correct-delegation-in-ruby-2-27-3.html
|
10
|
+
# Drop this when we can drop ruby 2.6 (aka after rails 6.1 EOL, ~2024-06)
|
11
|
+
kw_extra = "ruby2_keywords %p" % [new_name] if respond_to?(:ruby2_keywords, true)
|
7
12
|
|
8
13
|
# warn "%-22p -> %p %p" % [meth, new_name, dont_flip]
|
9
14
|
self.class_eval <<-EOM, __FILE__, __LINE__ + 1
|
10
15
|
def #{new_name} *args
|
11
16
|
where = Minitest.filter_backtrace(caller).first
|
12
17
|
where = where.split(/:in /, 2).first # clean up noise
|
13
|
-
warn "DEPRECATED: global use of #{new_name} from #\{where}. Use
|
18
|
+
Kernel.warn "DEPRECATED: global use of #{new_name} from #\{where}. Use #{target_obj}.#{new_name} instead. This will fail in Minitest 6."
|
14
19
|
Minitest::Expectation.new(self, Minitest::Spec.current).#{new_name}(*args)
|
15
20
|
end
|
21
|
+
#{kw_extra}
|
16
22
|
EOM
|
17
23
|
|
18
24
|
Minitest::Expectation.class_eval <<-EOM, __FILE__, __LINE__ + 1
|
@@ -27,6 +33,7 @@ class Module # :nodoc:
|
|
27
33
|
ctx.#{meth}(args.first, target, *args[1..-1])
|
28
34
|
end
|
29
35
|
end
|
36
|
+
#{kw_extra}
|
30
37
|
EOM
|
31
38
|
end
|
32
39
|
end
|
@@ -65,7 +72,7 @@ module Kernel
|
|
65
72
|
#
|
66
73
|
# For some suggestions on how to improve your specs, try:
|
67
74
|
#
|
68
|
-
#
|
75
|
+
# https://betterspecs.org
|
69
76
|
#
|
70
77
|
# but do note that several items there are debatable or specific to
|
71
78
|
# rspec.
|
@@ -289,21 +296,28 @@ class Minitest::Spec < Minitest::Test
|
|
289
296
|
|
290
297
|
module InstanceMethods
|
291
298
|
##
|
292
|
-
#
|
293
|
-
# available to it.
|
299
|
+
# Takes a value or a block and returns a value monad that has
|
300
|
+
# all of Expectations methods available to it.
|
294
301
|
#
|
295
|
-
#
|
302
|
+
# _(1 + 1).must_equal 2
|
296
303
|
#
|
297
|
-
#
|
298
|
-
#
|
299
|
-
#
|
304
|
+
# And for blocks:
|
305
|
+
#
|
306
|
+
# _ { 1 + "1" }.must_raise TypeError
|
300
307
|
#
|
301
308
|
# This method of expectation-based testing is preferable to
|
302
309
|
# straight-expectation methods (on Object) because it stores its
|
303
310
|
# test context, bypassing our hacky use of thread-local variables.
|
304
311
|
#
|
305
|
-
# At some point, the methods on Object will be deprecated
|
306
|
-
# removed.
|
312
|
+
# NOTE: At some point, the methods on Object will be deprecated
|
313
|
+
# and then removed.
|
314
|
+
#
|
315
|
+
# It is also aliased to #value and #expect for your aesthetic
|
316
|
+
# pleasure:
|
317
|
+
#
|
318
|
+
# _(1 + 1).must_equal 2
|
319
|
+
# value(1 + 1).must_equal 2
|
320
|
+
# expect(1 + 1).must_equal 2
|
307
321
|
|
308
322
|
def _ value = nil, &block
|
309
323
|
Minitest::Expectation.new block || value, self
|