minitest 5.11.3 → 5.25.4
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/History.rdoc +375 -4
- data/Manifest.txt +6 -0
- data/README.rdoc +106 -17
- data/Rakefile +11 -16
- data/lib/hoe/minitest.rb +2 -5
- data/lib/minitest/assertions.rb +255 -93
- data/lib/minitest/autorun.rb +0 -7
- data/lib/minitest/benchmark.rb +13 -16
- data/lib/minitest/compress.rb +94 -0
- data/lib/minitest/error_on_warning.rb +11 -0
- data/lib/minitest/expectations.rb +72 -35
- data/lib/minitest/manual_plugins.rb +16 -0
- data/lib/minitest/mock.rb +151 -44
- data/lib/minitest/parallel.rb +5 -5
- data/lib/minitest/pride_plugin.rb +17 -24
- data/lib/minitest/spec.rb +38 -19
- data/lib/minitest/test.rb +50 -33
- data/lib/minitest/test_task.rb +307 -0
- data/lib/minitest/unit.rb +5 -8
- data/lib/minitest.rb +414 -166
- data/test/minitest/metametameta.rb +65 -17
- data/test/minitest/test_minitest_assertions.rb +1720 -0
- data/test/minitest/test_minitest_benchmark.rb +3 -3
- data/test/minitest/test_minitest_mock.rb +409 -65
- data/test/minitest/test_minitest_reporter.rb +169 -32
- data/test/minitest/test_minitest_spec.rb +369 -193
- data/test/minitest/test_minitest_test.rb +463 -1249
- data/test/minitest/test_minitest_test_task.rb +57 -0
- data.tar.gz.sig +0 -0
- metadata +40 -23
- metadata.gz.sig +0 -0
data/lib/minitest/assertions.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
1
|
require "rbconfig"
|
4
2
|
require "tempfile"
|
5
3
|
require "stringio"
|
@@ -27,20 +25,18 @@ module Minitest
|
|
27
25
|
# figure out what diff to use.
|
28
26
|
|
29
27
|
def self.diff
|
30
|
-
@diff
|
31
|
-
|
28
|
+
return @diff if defined? @diff
|
29
|
+
|
30
|
+
@diff = if (RbConfig::CONFIG["host_os"] =~ /mswin|mingw/ and
|
31
|
+
system "diff.exe", __FILE__, __FILE__) then
|
32
32
|
"diff.exe -u"
|
33
|
-
elsif
|
34
|
-
"diff -u"
|
35
|
-
elsif system("gdiff", __FILE__, __FILE__)
|
33
|
+
elsif system "gdiff", __FILE__, __FILE__ then
|
36
34
|
"gdiff -u" # solaris and kin suck
|
37
|
-
elsif system
|
35
|
+
elsif system "diff", __FILE__, __FILE__ then
|
38
36
|
"diff -u"
|
39
37
|
else
|
40
38
|
nil
|
41
|
-
end
|
42
|
-
|
43
|
-
@diff
|
39
|
+
end
|
44
40
|
end
|
45
41
|
|
46
42
|
##
|
@@ -55,28 +51,22 @@ module Minitest
|
|
55
51
|
# diff command or if it doesn't make sense to diff the output
|
56
52
|
# (single line, short output), then it simply returns a basic
|
57
53
|
# comparison between the two.
|
54
|
+
#
|
55
|
+
# See +things_to_diff+ for more info.
|
58
56
|
|
59
57
|
def diff exp, act
|
60
|
-
expect = mu_pp_for_diff exp
|
61
|
-
butwas = mu_pp_for_diff act
|
62
58
|
result = nil
|
63
59
|
|
64
|
-
|
65
|
-
(expect.include?("\n") ||
|
66
|
-
butwas.include?("\n") ||
|
67
|
-
expect.size > 30 ||
|
68
|
-
butwas.size > 30 ||
|
69
|
-
expect == butwas) &&
|
70
|
-
Minitest::Assertions.diff
|
60
|
+
expect, butwas = things_to_diff exp, act
|
71
61
|
|
72
62
|
return "Expected: #{mu_pp exp}\n Actual: #{mu_pp act}" unless
|
73
|
-
|
63
|
+
expect
|
74
64
|
|
75
|
-
Tempfile.open
|
65
|
+
Tempfile.open "expect" do |a|
|
76
66
|
a.puts expect
|
77
67
|
a.flush
|
78
68
|
|
79
|
-
Tempfile.open
|
69
|
+
Tempfile.open "butwas" do |b|
|
80
70
|
b.puts butwas
|
81
71
|
b.flush
|
82
72
|
|
@@ -87,10 +77,10 @@ module Minitest
|
|
87
77
|
if result.empty? then
|
88
78
|
klass = exp.class
|
89
79
|
result = [
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
80
|
+
"No visible difference in the #{klass}#inspect output.\n",
|
81
|
+
"You should look at the implementation of #== on ",
|
82
|
+
"#{klass} or its members.\n",
|
83
|
+
expect,
|
94
84
|
].join
|
95
85
|
end
|
96
86
|
end
|
@@ -99,33 +89,80 @@ module Minitest
|
|
99
89
|
result
|
100
90
|
end
|
101
91
|
|
92
|
+
##
|
93
|
+
# Returns things to diff [expect, butwas], or [nil, nil] if nothing to diff.
|
94
|
+
#
|
95
|
+
# Criterion:
|
96
|
+
#
|
97
|
+
# 1. Strings include newlines or escaped newlines, but not both.
|
98
|
+
# 2. or: String lengths are > 30 characters.
|
99
|
+
# 3. or: Strings are equal to each other (but maybe different encodings?).
|
100
|
+
# 4. and: we found a diff executable.
|
101
|
+
|
102
|
+
def things_to_diff exp, act
|
103
|
+
expect = mu_pp_for_diff exp
|
104
|
+
butwas = mu_pp_for_diff act
|
105
|
+
|
106
|
+
e1, e2 = expect.include?("\n"), expect.include?("\\n")
|
107
|
+
b1, b2 = butwas.include?("\n"), butwas.include?("\\n")
|
108
|
+
|
109
|
+
need_to_diff =
|
110
|
+
(e1 ^ e2 ||
|
111
|
+
b1 ^ b2 ||
|
112
|
+
expect.size > 30 ||
|
113
|
+
butwas.size > 30 ||
|
114
|
+
expect == butwas) &&
|
115
|
+
Minitest::Assertions.diff
|
116
|
+
|
117
|
+
need_to_diff && [expect, butwas]
|
118
|
+
end
|
119
|
+
|
102
120
|
##
|
103
121
|
# This returns a human-readable version of +obj+. By default
|
104
|
-
# #inspect is called. You can override this to use #
|
122
|
+
# #inspect is called. You can override this to use #pretty_inspect
|
105
123
|
# if you want.
|
124
|
+
#
|
125
|
+
# See Minitest::Test.make_my_diffs_pretty!
|
106
126
|
|
107
127
|
def mu_pp obj
|
108
|
-
s = obj.inspect
|
128
|
+
s = obj.inspect.encode Encoding.default_external
|
109
129
|
|
110
|
-
|
111
|
-
|
130
|
+
return s unless String === obj &&
|
131
|
+
(obj.encoding != Encoding.default_external || !obj.valid_encoding?)
|
112
132
|
|
113
|
-
|
114
|
-
|
115
|
-
end
|
116
|
-
end
|
133
|
+
enc = "# encoding: #{obj.encoding}"
|
134
|
+
val = "# valid: #{obj.valid_encoding?}"
|
117
135
|
|
118
|
-
s
|
136
|
+
[enc, val, s].join "\n"
|
119
137
|
end
|
120
138
|
|
121
139
|
##
|
122
|
-
# This returns a diff-able human-readable version of +obj+.
|
123
|
-
# differs from the regular mu_pp because it expands escaped
|
124
|
-
# newlines and makes hex-values
|
140
|
+
# This returns a diff-able more human-readable version of +obj+.
|
141
|
+
# This differs from the regular mu_pp because it expands escaped
|
142
|
+
# newlines and makes hex-values (like object_ids) generic. This
|
125
143
|
# uses mu_pp to do the first pass and then cleans it up.
|
126
144
|
|
127
145
|
def mu_pp_for_diff obj
|
128
|
-
mu_pp
|
146
|
+
str = mu_pp obj
|
147
|
+
|
148
|
+
# both '\n' & '\\n' (_after_ mu_pp (aka inspect))
|
149
|
+
single = str.match?(/(?<!\\|^)\\n/)
|
150
|
+
double = str.match?(/(?<=\\|^)\\n/)
|
151
|
+
|
152
|
+
process =
|
153
|
+
if single ^ double then
|
154
|
+
if single then
|
155
|
+
lambda { |s| s == "\\n" ? "\n" : s } # unescape
|
156
|
+
else
|
157
|
+
lambda { |s| s == "\\\\n" ? "\\n\n" : s } # unescape a bit, add nls
|
158
|
+
end
|
159
|
+
else
|
160
|
+
:itself # leave it alone
|
161
|
+
end
|
162
|
+
|
163
|
+
str
|
164
|
+
.gsub(/\\?\\n/, &process)
|
165
|
+
.gsub(/:0x[a-fA-F0-9]{4,}/m, ":0xXXXXXX") # anonymize hex values
|
129
166
|
end
|
130
167
|
|
131
168
|
##
|
@@ -149,11 +186,16 @@ module Minitest
|
|
149
186
|
# Fails unless +obj+ is empty.
|
150
187
|
|
151
188
|
def assert_empty obj, msg = nil
|
152
|
-
msg = message(msg) { "Expected #{mu_pp
|
189
|
+
msg = message(msg) { "Expected #{mu_pp obj} to be empty" }
|
153
190
|
assert_respond_to obj, :empty?
|
154
191
|
assert obj.empty?, msg
|
155
192
|
end
|
156
193
|
|
194
|
+
def _where # :nodoc:
|
195
|
+
Minitest.filter_backtrace(caller).first
|
196
|
+
.split(":in ", 2).first # clean up noise
|
197
|
+
end
|
198
|
+
|
157
199
|
E = "" # :nodoc:
|
158
200
|
|
159
201
|
##
|
@@ -174,13 +216,10 @@ module Minitest
|
|
174
216
|
result = assert exp == act, msg
|
175
217
|
|
176
218
|
if nil == exp then
|
177
|
-
if Minitest::VERSION
|
219
|
+
if Minitest::VERSION >= "6" then
|
178
220
|
refute_nil exp, "Use assert_nil if expecting nil."
|
179
221
|
else
|
180
|
-
|
181
|
-
where = where.split(/:in /, 2).first # clean up noise
|
182
|
-
|
183
|
-
warn "DEPRECATED: Use assert_nil if expecting nil from #{where}. This will fail in Minitest 6."
|
222
|
+
warn "DEPRECATED: Use assert_nil if expecting nil from #{_where}. This will fail in Minitest 6."
|
184
223
|
end
|
185
224
|
end
|
186
225
|
|
@@ -214,7 +253,7 @@ module Minitest
|
|
214
253
|
|
215
254
|
def assert_includes collection, obj, msg = nil
|
216
255
|
msg = message(msg) {
|
217
|
-
"Expected #{mu_pp
|
256
|
+
"Expected #{mu_pp collection} to include #{mu_pp obj}"
|
218
257
|
}
|
219
258
|
assert_respond_to collection, :include?
|
220
259
|
assert collection.include?(obj), msg
|
@@ -225,7 +264,7 @@ module Minitest
|
|
225
264
|
|
226
265
|
def assert_instance_of cls, obj, msg = nil
|
227
266
|
msg = message(msg) {
|
228
|
-
"Expected #{mu_pp
|
267
|
+
"Expected #{mu_pp obj} to be an instance of #{cls}, not #{obj.class}"
|
229
268
|
}
|
230
269
|
|
231
270
|
assert obj.instance_of?(cls), msg
|
@@ -236,7 +275,8 @@ module Minitest
|
|
236
275
|
|
237
276
|
def assert_kind_of cls, obj, msg = nil
|
238
277
|
msg = message(msg) {
|
239
|
-
"Expected #{mu_pp
|
278
|
+
"Expected #{mu_pp obj} to be a kind of #{cls}, not #{obj.class}"
|
279
|
+
}
|
240
280
|
|
241
281
|
assert obj.kind_of?(cls), msg
|
242
282
|
end
|
@@ -246,16 +286,18 @@ module Minitest
|
|
246
286
|
|
247
287
|
def assert_match matcher, obj, msg = nil
|
248
288
|
msg = message(msg) { "Expected #{mu_pp matcher} to match #{mu_pp obj}" }
|
249
|
-
assert_respond_to matcher,
|
289
|
+
assert_respond_to matcher, :=~
|
250
290
|
matcher = Regexp.new Regexp.escape matcher if String === matcher
|
251
291
|
assert matcher =~ obj, msg
|
292
|
+
|
293
|
+
Regexp.last_match
|
252
294
|
end
|
253
295
|
|
254
296
|
##
|
255
297
|
# Fails unless +obj+ is nil
|
256
298
|
|
257
299
|
def assert_nil obj, msg = nil
|
258
|
-
msg = message(msg) { "Expected #{mu_pp
|
300
|
+
msg = message(msg) { "Expected #{mu_pp obj} to be nil" }
|
259
301
|
assert obj.nil?, msg
|
260
302
|
end
|
261
303
|
|
@@ -266,7 +308,7 @@ module Minitest
|
|
266
308
|
|
267
309
|
def assert_operator o1, op, o2 = UNDEFINED, msg = nil
|
268
310
|
return assert_predicate o1, op, msg if UNDEFINED == o2
|
269
|
-
msg = message(msg) { "Expected #{mu_pp
|
311
|
+
msg = message(msg) { "Expected #{mu_pp o1} to be #{op} #{mu_pp o2}" }
|
270
312
|
assert o1.__send__(op, o2), msg
|
271
313
|
end
|
272
314
|
|
@@ -283,6 +325,9 @@ module Minitest
|
|
283
325
|
# See also: #assert_silent
|
284
326
|
|
285
327
|
def assert_output stdout = nil, stderr = nil
|
328
|
+
flunk "assert_output requires a block to capture output." unless
|
329
|
+
block_given?
|
330
|
+
|
286
331
|
out, err = capture_io do
|
287
332
|
yield
|
288
333
|
end
|
@@ -294,6 +339,44 @@ module Minitest
|
|
294
339
|
x = send out_msg, stdout, out, "In stdout" if out_msg
|
295
340
|
|
296
341
|
(!stdout || x) && (!stderr || y)
|
342
|
+
rescue Assertion
|
343
|
+
raise
|
344
|
+
rescue => e
|
345
|
+
raise UnexpectedError, e
|
346
|
+
end
|
347
|
+
|
348
|
+
##
|
349
|
+
# Fails unless +path+ exists.
|
350
|
+
|
351
|
+
def assert_path_exists path, msg = nil
|
352
|
+
msg = message(msg) { "Expected path '#{path}' to exist" }
|
353
|
+
assert File.exist?(path), msg
|
354
|
+
end
|
355
|
+
|
356
|
+
##
|
357
|
+
# For testing with pattern matching (only supported with Ruby 3.0 and later)
|
358
|
+
#
|
359
|
+
# # pass
|
360
|
+
# assert_pattern { [1,2,3] => [Integer, Integer, Integer] }
|
361
|
+
#
|
362
|
+
# # fail "length mismatch (given 3, expected 1)"
|
363
|
+
# assert_pattern { [1,2,3] => [Integer] }
|
364
|
+
#
|
365
|
+
# The bare <tt>=></tt> pattern will raise a NoMatchingPatternError on failure, which would
|
366
|
+
# normally be counted as a test error. This assertion rescues NoMatchingPatternError and
|
367
|
+
# generates a test failure. Any other exception will be raised as normal and generate a test
|
368
|
+
# error.
|
369
|
+
|
370
|
+
def assert_pattern
|
371
|
+
raise NotImplementedError, "only available in Ruby 3.0+" unless RUBY_VERSION >= "3.0"
|
372
|
+
flunk "assert_pattern requires a block to capture errors." unless block_given?
|
373
|
+
|
374
|
+
begin # TODO: remove after ruby 2.6 dropped
|
375
|
+
yield
|
376
|
+
pass
|
377
|
+
rescue NoMatchingPatternError => e
|
378
|
+
flunk e.message
|
379
|
+
end
|
297
380
|
end
|
298
381
|
|
299
382
|
##
|
@@ -306,7 +389,7 @@ module Minitest
|
|
306
389
|
# str.must_be :empty?
|
307
390
|
|
308
391
|
def assert_predicate o1, op, msg = nil
|
309
|
-
msg = message(msg) { "Expected #{mu_pp
|
392
|
+
msg = message(msg) { "Expected #{mu_pp o1} to be #{op}" }
|
310
393
|
assert o1.__send__(op), msg
|
311
394
|
end
|
312
395
|
|
@@ -316,9 +399,26 @@ module Minitest
|
|
316
399
|
#
|
317
400
|
# +exp+ takes an optional message on the end to help explain
|
318
401
|
# failures and defaults to StandardError if no exception class is
|
319
|
-
# passed.
|
402
|
+
# passed. Eg:
|
403
|
+
#
|
404
|
+
# assert_raises(CustomError) { method_with_custom_error }
|
405
|
+
#
|
406
|
+
# With custom error message:
|
407
|
+
#
|
408
|
+
# assert_raises(CustomError, 'This should have raised CustomError') { method_with_custom_error }
|
409
|
+
#
|
410
|
+
# Using the returned object:
|
411
|
+
#
|
412
|
+
# error = assert_raises(CustomError) do
|
413
|
+
# raise CustomError, 'This is really bad'
|
414
|
+
# end
|
415
|
+
#
|
416
|
+
# assert_equal 'This is really bad', error.message
|
320
417
|
|
321
418
|
def assert_raises *exp
|
419
|
+
flunk "assert_raises requires a block to capture errors." unless
|
420
|
+
block_given?
|
421
|
+
|
322
422
|
msg = "#{exp.pop}.\n" if String === exp.last
|
323
423
|
exp << StandardError if exp.empty?
|
324
424
|
|
@@ -327,30 +427,31 @@ module Minitest
|
|
327
427
|
rescue *exp => e
|
328
428
|
pass # count assertion
|
329
429
|
return e
|
330
|
-
rescue Minitest::Skip
|
430
|
+
rescue Minitest::Assertion # incl Skip & UnexpectedError
|
331
431
|
# don't count assertion
|
332
432
|
raise
|
333
433
|
rescue SignalException, SystemExit
|
334
434
|
raise
|
335
435
|
rescue Exception => e
|
336
436
|
flunk proc {
|
337
|
-
exception_details(e, "#{msg}#{mu_pp
|
437
|
+
exception_details(e, "#{msg}#{mu_pp exp} exception expected, not")
|
338
438
|
}
|
339
439
|
end
|
340
440
|
|
341
441
|
exp = exp.first if exp.size == 1
|
342
442
|
|
343
|
-
flunk "#{msg}#{mu_pp
|
443
|
+
flunk "#{msg}#{mu_pp exp} expected but nothing was raised."
|
344
444
|
end
|
345
445
|
|
346
446
|
##
|
347
447
|
# Fails unless +obj+ responds to +meth+.
|
448
|
+
# include_all defaults to false to match Object#respond_to?
|
348
449
|
|
349
|
-
def assert_respond_to obj, meth, msg = nil
|
450
|
+
def assert_respond_to obj, meth, msg = nil, include_all: false
|
350
451
|
msg = message(msg) {
|
351
|
-
"Expected #{mu_pp
|
452
|
+
"Expected #{mu_pp obj} (#{obj.class}) to respond to ##{meth}"
|
352
453
|
}
|
353
|
-
assert obj.respond_to?(meth), msg
|
454
|
+
assert obj.respond_to?(meth, include_all), msg
|
354
455
|
end
|
355
456
|
|
356
457
|
##
|
@@ -370,13 +471,12 @@ module Minitest
|
|
370
471
|
# Fails unless the call returns a true value
|
371
472
|
|
372
473
|
def assert_send send_ary, m = nil
|
373
|
-
|
374
|
-
where = where.split(/:in /, 2).first # clean up noise
|
375
|
-
warn "DEPRECATED: assert_send. From #{where}"
|
474
|
+
warn "DEPRECATED: assert_send. From #{_where}"
|
376
475
|
|
377
476
|
recv, msg, *args = send_ary
|
378
477
|
m = message(m) {
|
379
|
-
"Expected #{mu_pp
|
478
|
+
"Expected #{mu_pp recv}.#{msg}(*#{mu_pp args}) to return true"
|
479
|
+
}
|
380
480
|
assert recv.__send__(msg, *args), m
|
381
481
|
end
|
382
482
|
|
@@ -395,15 +495,15 @@ module Minitest
|
|
395
495
|
# Fails unless the block throws +sym+
|
396
496
|
|
397
497
|
def assert_throws sym, msg = nil
|
398
|
-
default = "Expected #{mu_pp
|
498
|
+
default = "Expected #{mu_pp sym} to have been thrown"
|
399
499
|
caught = true
|
400
|
-
catch
|
500
|
+
value = catch sym do
|
401
501
|
begin
|
402
502
|
yield
|
403
503
|
rescue ThreadError => e # wtf?!? 1.8 + threads == suck
|
404
|
-
default += ", not
|
504
|
+
default += ", not :#{e.message[/uncaught throw \`(\w+?)\'/, 1]}"
|
405
505
|
rescue ArgumentError => e # 1.9 exception
|
406
|
-
raise e unless e.message.include?
|
506
|
+
raise e unless e.message.include? "uncaught throw"
|
407
507
|
default += ", not #{e.message.split(/ /).last}"
|
408
508
|
rescue NameError => e # 1.8 exception
|
409
509
|
raise e unless e.name == sym
|
@@ -413,6 +513,11 @@ module Minitest
|
|
413
513
|
end
|
414
514
|
|
415
515
|
assert caught, message(msg) { default }
|
516
|
+
value
|
517
|
+
rescue Assertion
|
518
|
+
raise
|
519
|
+
rescue => e
|
520
|
+
raise UnexpectedError, e
|
416
521
|
end
|
417
522
|
|
418
523
|
##
|
@@ -481,10 +586,13 @@ module Minitest
|
|
481
586
|
|
482
587
|
return captured_stdout.read, captured_stderr.read
|
483
588
|
ensure
|
484
|
-
captured_stdout.unlink
|
485
|
-
captured_stderr.unlink
|
486
589
|
$stdout.reopen orig_stdout
|
487
590
|
$stderr.reopen orig_stderr
|
591
|
+
|
592
|
+
orig_stdout.close
|
593
|
+
orig_stderr.close
|
594
|
+
captured_stdout.close!
|
595
|
+
captured_stderr.close!
|
488
596
|
end
|
489
597
|
end
|
490
598
|
end
|
@@ -494,17 +602,26 @@ module Minitest
|
|
494
602
|
|
495
603
|
def exception_details e, msg
|
496
604
|
[
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
605
|
+
msg,
|
606
|
+
"Class: <#{e.class}>",
|
607
|
+
"Message: <#{e.message.inspect}>",
|
608
|
+
"---Backtrace---",
|
609
|
+
Minitest.filter_backtrace(e.backtrace),
|
610
|
+
"---------------",
|
503
611
|
].join "\n"
|
504
612
|
end
|
505
613
|
|
506
614
|
##
|
507
|
-
# Fails
|
615
|
+
# Fails after a given date (in the local time zone). This allows
|
616
|
+
# you to put time-bombs in your tests if you need to keep
|
617
|
+
# something around until a later date lest you forget about it.
|
618
|
+
|
619
|
+
def fail_after y, m, d, msg
|
620
|
+
flunk msg if Time.now > Time.local(y, m, d)
|
621
|
+
end
|
622
|
+
|
623
|
+
##
|
624
|
+
# Fails with +msg+.
|
508
625
|
|
509
626
|
def flunk msg = nil
|
510
627
|
msg ||= "Epic Fail!"
|
@@ -533,15 +650,15 @@ module Minitest
|
|
533
650
|
# Fails if +test+ is truthy.
|
534
651
|
|
535
652
|
def refute test, msg = nil
|
536
|
-
msg ||= message { "Expected #{mu_pp
|
537
|
-
|
653
|
+
msg ||= message { "Expected #{mu_pp test} to not be truthy" }
|
654
|
+
assert !test, msg
|
538
655
|
end
|
539
656
|
|
540
657
|
##
|
541
658
|
# Fails if +obj+ is empty.
|
542
659
|
|
543
660
|
def refute_empty obj, msg = nil
|
544
|
-
msg = message(msg) { "Expected #{mu_pp
|
661
|
+
msg = message(msg) { "Expected #{mu_pp obj} to not be empty" }
|
545
662
|
assert_respond_to obj, :empty?
|
546
663
|
refute obj.empty?, msg
|
547
664
|
end
|
@@ -553,7 +670,7 @@ module Minitest
|
|
553
670
|
|
554
671
|
def refute_equal exp, act, msg = nil
|
555
672
|
msg = message(msg) {
|
556
|
-
"Expected #{mu_pp
|
673
|
+
"Expected #{mu_pp act} to not be equal to #{mu_pp exp}"
|
557
674
|
}
|
558
675
|
refute exp == act, msg
|
559
676
|
end
|
@@ -584,7 +701,7 @@ module Minitest
|
|
584
701
|
|
585
702
|
def refute_includes collection, obj, msg = nil
|
586
703
|
msg = message(msg) {
|
587
|
-
"Expected #{mu_pp
|
704
|
+
"Expected #{mu_pp collection} to not include #{mu_pp obj}"
|
588
705
|
}
|
589
706
|
assert_respond_to collection, :include?
|
590
707
|
refute collection.include?(obj), msg
|
@@ -595,7 +712,7 @@ module Minitest
|
|
595
712
|
|
596
713
|
def refute_instance_of cls, obj, msg = nil
|
597
714
|
msg = message(msg) {
|
598
|
-
"Expected #{mu_pp
|
715
|
+
"Expected #{mu_pp obj} to not be an instance of #{cls}"
|
599
716
|
}
|
600
717
|
refute obj.instance_of?(cls), msg
|
601
718
|
end
|
@@ -604,7 +721,7 @@ module Minitest
|
|
604
721
|
# Fails if +obj+ is a kind of +cls+.
|
605
722
|
|
606
723
|
def refute_kind_of cls, obj, msg = nil
|
607
|
-
msg = message(msg) { "Expected #{mu_pp
|
724
|
+
msg = message(msg) { "Expected #{mu_pp obj} to not be a kind of #{cls}" }
|
608
725
|
refute obj.kind_of?(cls), msg
|
609
726
|
end
|
610
727
|
|
@@ -613,7 +730,7 @@ module Minitest
|
|
613
730
|
|
614
731
|
def refute_match matcher, obj, msg = nil
|
615
732
|
msg = message(msg) { "Expected #{mu_pp matcher} to not match #{mu_pp obj}" }
|
616
|
-
assert_respond_to matcher,
|
733
|
+
assert_respond_to matcher, :=~
|
617
734
|
matcher = Regexp.new Regexp.escape matcher if String === matcher
|
618
735
|
refute matcher =~ obj, msg
|
619
736
|
end
|
@@ -622,10 +739,34 @@ module Minitest
|
|
622
739
|
# Fails if +obj+ is nil.
|
623
740
|
|
624
741
|
def refute_nil obj, msg = nil
|
625
|
-
msg = message(msg) { "Expected #{mu_pp
|
742
|
+
msg = message(msg) { "Expected #{mu_pp obj} to not be nil" }
|
626
743
|
refute obj.nil?, msg
|
627
744
|
end
|
628
745
|
|
746
|
+
##
|
747
|
+
# For testing with pattern matching (only supported with Ruby 3.0 and later)
|
748
|
+
#
|
749
|
+
# # pass
|
750
|
+
# refute_pattern { [1,2,3] => [String] }
|
751
|
+
#
|
752
|
+
# # fail "NoMatchingPatternError expected, but nothing was raised."
|
753
|
+
# refute_pattern { [1,2,3] => [Integer, Integer, Integer] }
|
754
|
+
#
|
755
|
+
# This assertion expects a NoMatchingPatternError exception, and will fail if none is raised. Any
|
756
|
+
# other exceptions will be raised as normal and generate a test error.
|
757
|
+
|
758
|
+
def refute_pattern
|
759
|
+
raise NotImplementedError, "only available in Ruby 3.0+" unless RUBY_VERSION >= "3.0"
|
760
|
+
flunk "refute_pattern requires a block to capture errors." unless block_given?
|
761
|
+
|
762
|
+
begin
|
763
|
+
yield
|
764
|
+
flunk "NoMatchingPatternError expected, but nothing was raised."
|
765
|
+
rescue NoMatchingPatternError
|
766
|
+
pass
|
767
|
+
end
|
768
|
+
end
|
769
|
+
|
629
770
|
##
|
630
771
|
# Fails if +o1+ is not +op+ +o2+. Eg:
|
631
772
|
#
|
@@ -634,10 +775,18 @@ module Minitest
|
|
634
775
|
|
635
776
|
def refute_operator o1, op, o2 = UNDEFINED, msg = nil
|
636
777
|
return refute_predicate o1, op, msg if UNDEFINED == o2
|
637
|
-
msg = message(msg) { "Expected #{mu_pp
|
778
|
+
msg = message(msg) { "Expected #{mu_pp o1} to not be #{op} #{mu_pp o2}" }
|
638
779
|
refute o1.__send__(op, o2), msg
|
639
780
|
end
|
640
781
|
|
782
|
+
##
|
783
|
+
# Fails if +path+ exists.
|
784
|
+
|
785
|
+
def refute_path_exists path, msg = nil
|
786
|
+
msg = message(msg) { "Expected path '#{path}' to not exist" }
|
787
|
+
refute File.exist?(path), msg
|
788
|
+
end
|
789
|
+
|
641
790
|
##
|
642
791
|
# For testing with predicates.
|
643
792
|
#
|
@@ -648,17 +797,18 @@ module Minitest
|
|
648
797
|
# str.wont_be :empty?
|
649
798
|
|
650
799
|
def refute_predicate o1, op, msg = nil
|
651
|
-
msg = message(msg) { "Expected #{mu_pp
|
800
|
+
msg = message(msg) { "Expected #{mu_pp o1} to not be #{op}" }
|
652
801
|
refute o1.__send__(op), msg
|
653
802
|
end
|
654
803
|
|
655
804
|
##
|
656
805
|
# Fails if +obj+ responds to the message +meth+.
|
806
|
+
# include_all defaults to false to match Object#respond_to?
|
657
807
|
|
658
|
-
def refute_respond_to obj, meth, msg = nil
|
659
|
-
msg = message(msg) { "Expected #{mu_pp
|
808
|
+
def refute_respond_to obj, meth, msg = nil, include_all: false
|
809
|
+
msg = message(msg) { "Expected #{mu_pp obj} to not respond to #{meth}" }
|
660
810
|
|
661
|
-
refute obj.respond_to?(meth), msg
|
811
|
+
refute obj.respond_to?(meth, include_all), msg
|
662
812
|
end
|
663
813
|
|
664
814
|
##
|
@@ -677,10 +827,22 @@ module Minitest
|
|
677
827
|
# gets listed at the end of the run but doesn't cause a failure
|
678
828
|
# exit code.
|
679
829
|
|
680
|
-
def skip msg = nil,
|
830
|
+
def skip msg = nil, _ignored = nil
|
681
831
|
msg ||= "Skipped, no message given"
|
682
832
|
@skip = true
|
683
|
-
raise Minitest::Skip, msg
|
833
|
+
raise Minitest::Skip, msg
|
834
|
+
end
|
835
|
+
|
836
|
+
##
|
837
|
+
# Skips the current run until a given date (in the local time
|
838
|
+
# zone). This allows you to put some fixes on hold until a later
|
839
|
+
# date, but still holds you accountable and prevents you from
|
840
|
+
# forgetting it.
|
841
|
+
|
842
|
+
def skip_until y, m, d, msg
|
843
|
+
skip msg if Time.now < Time.local(y, m, d)
|
844
|
+
where = caller(1..1).first.rpartition(":in").reject(&:empty?).first
|
845
|
+
warn "Stale skip_until %p at %s" % [msg, where]
|
684
846
|
end
|
685
847
|
|
686
848
|
##
|