minitest 5.14.4 → 5.25.5
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 +283 -2
- data/Manifest.txt +5 -0
- data/README.rdoc +78 -36
- data/Rakefile +8 -1
- data/lib/hoe/minitest.rb +2 -5
- data/lib/minitest/assertions.rb +131 -83
- data/lib/minitest/autorun.rb +0 -7
- data/lib/minitest/benchmark.rb +11 -14
- data/lib/minitest/compress.rb +94 -0
- data/lib/minitest/error_on_warning.rb +11 -0
- data/lib/minitest/expectations.rb +18 -0
- data/lib/minitest/manual_plugins.rb +16 -0
- data/lib/minitest/mock.rb +148 -45
- data/lib/minitest/parallel.rb +5 -5
- data/lib/minitest/pride_plugin.rb +17 -24
- data/lib/minitest/spec.rb +20 -12
- data/lib/minitest/test.rb +51 -34
- data/lib/minitest/test_task.rb +307 -0
- data/lib/minitest/unit.rb +5 -8
- data/lib/minitest.rb +333 -154
- data/test/minitest/metametameta.rb +33 -19
- data/test/minitest/test_minitest_assertions.rb +292 -147
- data/test/minitest/test_minitest_benchmark.rb +3 -3
- data/test/minitest/test_minitest_mock.rb +396 -62
- data/test/minitest/test_minitest_reporter.rb +169 -32
- data/test/minitest/test_minitest_spec.rb +174 -72
- data/test/minitest/test_minitest_test.rb +420 -130
- data/test/minitest/test_minitest_test_task.rb +57 -0
- data.tar.gz.sig +0 -0
- metadata +23 -20
- 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"
|
@@ -29,12 +27,12 @@ module Minitest
|
|
29
27
|
def self.diff
|
30
28
|
return @diff if defined? @diff
|
31
29
|
|
32
|
-
@diff = if (RbConfig::CONFIG["host_os"] =~ /mswin|mingw/
|
33
|
-
system
|
30
|
+
@diff = if (RbConfig::CONFIG["host_os"] =~ /mswin|mingw/ and
|
31
|
+
system "diff.exe", __FILE__, __FILE__) then
|
34
32
|
"diff.exe -u"
|
35
|
-
elsif system
|
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
|
@@ -59,16 +57,16 @@ module Minitest
|
|
59
57
|
def diff exp, act
|
60
58
|
result = nil
|
61
59
|
|
62
|
-
expect, butwas = things_to_diff
|
60
|
+
expect, butwas = things_to_diff exp, act
|
63
61
|
|
64
62
|
return "Expected: #{mu_pp exp}\n Actual: #{mu_pp act}" unless
|
65
63
|
expect
|
66
64
|
|
67
|
-
Tempfile.open
|
65
|
+
Tempfile.open "expect" do |a|
|
68
66
|
a.puts expect
|
69
67
|
a.flush
|
70
68
|
|
71
|
-
Tempfile.open
|
69
|
+
Tempfile.open "butwas" do |b|
|
72
70
|
b.puts butwas
|
73
71
|
b.flush
|
74
72
|
|
@@ -79,10 +77,10 @@ module Minitest
|
|
79
77
|
if result.empty? then
|
80
78
|
klass = exp.class
|
81
79
|
result = [
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
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,
|
86
84
|
].join
|
87
85
|
end
|
88
86
|
end
|
@@ -127,20 +125,15 @@ module Minitest
|
|
127
125
|
# See Minitest::Test.make_my_diffs_pretty!
|
128
126
|
|
129
127
|
def mu_pp obj
|
130
|
-
s = obj.inspect
|
128
|
+
s = obj.inspect.encode Encoding.default_external
|
131
129
|
|
132
|
-
|
133
|
-
|
130
|
+
return s unless String === obj &&
|
131
|
+
(obj.encoding != Encoding.default_external || !obj.valid_encoding?)
|
134
132
|
|
135
|
-
|
136
|
-
|
137
|
-
enc = "# encoding: #{obj.encoding}"
|
138
|
-
val = "# valid: #{obj.valid_encoding?}"
|
139
|
-
s = "#{enc}\n#{val}\n#{s}"
|
140
|
-
end
|
141
|
-
end
|
133
|
+
enc = "# encoding: #{obj.encoding}"
|
134
|
+
val = "# valid: #{obj.valid_encoding?}"
|
142
135
|
|
143
|
-
s
|
136
|
+
[enc, val, s].join "\n"
|
144
137
|
end
|
145
138
|
|
146
139
|
##
|
@@ -153,8 +146,8 @@ module Minitest
|
|
153
146
|
str = mu_pp obj
|
154
147
|
|
155
148
|
# both '\n' & '\\n' (_after_ mu_pp (aka inspect))
|
156
|
-
single =
|
157
|
-
double =
|
149
|
+
single = str.match?(/(?<!\\|^)\\n/)
|
150
|
+
double = str.match?(/(?<=\\|^)\\n/)
|
158
151
|
|
159
152
|
process =
|
160
153
|
if single ^ double then
|
@@ -167,9 +160,9 @@ module Minitest
|
|
167
160
|
:itself # leave it alone
|
168
161
|
end
|
169
162
|
|
170
|
-
str
|
171
|
-
gsub(/\\?\\n/, &process)
|
172
|
-
gsub(/:0x[a-fA-F0-9]{4,}/m, ":0xXXXXXX") # anonymize hex values
|
163
|
+
str
|
164
|
+
.gsub(/\\?\\n/, &process)
|
165
|
+
.gsub(/:0x[a-fA-F0-9]{4,}/m, ":0xXXXXXX") # anonymize hex values
|
173
166
|
end
|
174
167
|
|
175
168
|
##
|
@@ -193,11 +186,16 @@ module Minitest
|
|
193
186
|
# Fails unless +obj+ is empty.
|
194
187
|
|
195
188
|
def assert_empty obj, msg = nil
|
196
|
-
msg = message(msg) { "Expected #{mu_pp
|
189
|
+
msg = message(msg) { "Expected #{mu_pp obj} to be empty" }
|
197
190
|
assert_respond_to obj, :empty?
|
198
191
|
assert obj.empty?, msg
|
199
192
|
end
|
200
193
|
|
194
|
+
def _where # :nodoc:
|
195
|
+
Minitest.filter_backtrace(caller).first
|
196
|
+
.split(":in ", 2).first # clean up noise
|
197
|
+
end
|
198
|
+
|
201
199
|
E = "" # :nodoc:
|
202
200
|
|
203
201
|
##
|
@@ -218,13 +216,10 @@ module Minitest
|
|
218
216
|
result = assert exp == act, msg
|
219
217
|
|
220
218
|
if nil == exp then
|
221
|
-
if Minitest::VERSION
|
219
|
+
if Minitest::VERSION >= "6" then
|
222
220
|
refute_nil exp, "Use assert_nil if expecting nil."
|
223
221
|
else
|
224
|
-
|
225
|
-
where = where.split(/:in /, 2).first # clean up noise
|
226
|
-
|
227
|
-
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."
|
228
223
|
end
|
229
224
|
end
|
230
225
|
|
@@ -258,7 +253,7 @@ module Minitest
|
|
258
253
|
|
259
254
|
def assert_includes collection, obj, msg = nil
|
260
255
|
msg = message(msg) {
|
261
|
-
"Expected #{mu_pp
|
256
|
+
"Expected #{mu_pp collection} to include #{mu_pp obj}"
|
262
257
|
}
|
263
258
|
assert_respond_to collection, :include?
|
264
259
|
assert collection.include?(obj), msg
|
@@ -269,7 +264,7 @@ module Minitest
|
|
269
264
|
|
270
265
|
def assert_instance_of cls, obj, msg = nil
|
271
266
|
msg = message(msg) {
|
272
|
-
"Expected #{mu_pp
|
267
|
+
"Expected #{mu_pp obj} to be an instance of #{cls}, not #{obj.class}"
|
273
268
|
}
|
274
269
|
|
275
270
|
assert obj.instance_of?(cls), msg
|
@@ -280,7 +275,8 @@ module Minitest
|
|
280
275
|
|
281
276
|
def assert_kind_of cls, obj, msg = nil
|
282
277
|
msg = message(msg) {
|
283
|
-
"Expected #{mu_pp
|
278
|
+
"Expected #{mu_pp obj} to be a kind of #{cls}, not #{obj.class}"
|
279
|
+
}
|
284
280
|
|
285
281
|
assert obj.kind_of?(cls), msg
|
286
282
|
end
|
@@ -290,16 +286,18 @@ module Minitest
|
|
290
286
|
|
291
287
|
def assert_match matcher, obj, msg = nil
|
292
288
|
msg = message(msg) { "Expected #{mu_pp matcher} to match #{mu_pp obj}" }
|
293
|
-
assert_respond_to matcher,
|
289
|
+
assert_respond_to matcher, :=~
|
294
290
|
matcher = Regexp.new Regexp.escape matcher if String === matcher
|
295
291
|
assert matcher =~ obj, msg
|
292
|
+
|
293
|
+
Regexp.last_match
|
296
294
|
end
|
297
295
|
|
298
296
|
##
|
299
297
|
# Fails unless +obj+ is nil
|
300
298
|
|
301
299
|
def assert_nil obj, msg = nil
|
302
|
-
msg = message(msg) { "Expected #{mu_pp
|
300
|
+
msg = message(msg) { "Expected #{mu_pp obj} to be nil" }
|
303
301
|
assert obj.nil?, msg
|
304
302
|
end
|
305
303
|
|
@@ -310,7 +308,7 @@ module Minitest
|
|
310
308
|
|
311
309
|
def assert_operator o1, op, o2 = UNDEFINED, msg = nil
|
312
310
|
return assert_predicate o1, op, msg if UNDEFINED == o2
|
313
|
-
msg = message(msg) { "Expected #{mu_pp
|
311
|
+
msg = message(msg) { "Expected #{mu_pp o1} to be #{op} #{mu_pp o2}" }
|
314
312
|
assert o1.__send__(op, o2), msg
|
315
313
|
end
|
316
314
|
|
@@ -355,6 +353,32 @@ module Minitest
|
|
355
353
|
assert File.exist?(path), msg
|
356
354
|
end
|
357
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
|
380
|
+
end
|
381
|
+
|
358
382
|
##
|
359
383
|
# For testing with predicates. Eg:
|
360
384
|
#
|
@@ -365,7 +389,7 @@ module Minitest
|
|
365
389
|
# str.must_be :empty?
|
366
390
|
|
367
391
|
def assert_predicate o1, op, msg = nil
|
368
|
-
msg = message(msg) { "Expected #{mu_pp
|
392
|
+
msg = message(msg) { "Expected #{mu_pp o1} to be #{op}" }
|
369
393
|
assert o1.__send__(op), msg
|
370
394
|
end
|
371
395
|
|
@@ -410,23 +434,24 @@ module Minitest
|
|
410
434
|
raise
|
411
435
|
rescue Exception => e
|
412
436
|
flunk proc {
|
413
|
-
exception_details(e, "#{msg}#{mu_pp
|
437
|
+
exception_details(e, "#{msg}#{mu_pp exp} exception expected, not")
|
414
438
|
}
|
415
439
|
end
|
416
440
|
|
417
441
|
exp = exp.first if exp.size == 1
|
418
442
|
|
419
|
-
flunk "#{msg}#{mu_pp
|
443
|
+
flunk "#{msg}#{mu_pp exp} expected but nothing was raised."
|
420
444
|
end
|
421
445
|
|
422
446
|
##
|
423
447
|
# Fails unless +obj+ responds to +meth+.
|
448
|
+
# include_all defaults to false to match Object#respond_to?
|
424
449
|
|
425
|
-
def assert_respond_to obj, meth, msg = nil
|
450
|
+
def assert_respond_to obj, meth, msg = nil, include_all: false
|
426
451
|
msg = message(msg) {
|
427
|
-
"Expected #{mu_pp
|
452
|
+
"Expected #{mu_pp obj} (#{obj.class}) to respond to ##{meth}"
|
428
453
|
}
|
429
|
-
assert obj.respond_to?(meth), msg
|
454
|
+
assert obj.respond_to?(meth, include_all), msg
|
430
455
|
end
|
431
456
|
|
432
457
|
##
|
@@ -446,13 +471,12 @@ module Minitest
|
|
446
471
|
# Fails unless the call returns a true value
|
447
472
|
|
448
473
|
def assert_send send_ary, m = nil
|
449
|
-
|
450
|
-
where = where.split(/:in /, 2).first # clean up noise
|
451
|
-
warn "DEPRECATED: assert_send. From #{where}"
|
474
|
+
warn "DEPRECATED: assert_send. From #{_where}"
|
452
475
|
|
453
476
|
recv, msg, *args = send_ary
|
454
477
|
m = message(m) {
|
455
|
-
"Expected #{mu_pp
|
478
|
+
"Expected #{mu_pp recv}.#{msg}(*#{mu_pp args}) to return true"
|
479
|
+
}
|
456
480
|
assert recv.__send__(msg, *args), m
|
457
481
|
end
|
458
482
|
|
@@ -471,15 +495,15 @@ module Minitest
|
|
471
495
|
# Fails unless the block throws +sym+
|
472
496
|
|
473
497
|
def assert_throws sym, msg = nil
|
474
|
-
default = "Expected #{mu_pp
|
498
|
+
default = "Expected #{mu_pp sym} to have been thrown"
|
475
499
|
caught = true
|
476
|
-
catch
|
500
|
+
value = catch sym do
|
477
501
|
begin
|
478
502
|
yield
|
479
503
|
rescue ThreadError => e # wtf?!? 1.8 + threads == suck
|
480
|
-
default += ", not
|
504
|
+
default += ", not :#{e.message[/uncaught throw \`(\w+?)\'/, 1]}"
|
481
505
|
rescue ArgumentError => e # 1.9 exception
|
482
|
-
raise e unless e.message.include?
|
506
|
+
raise e unless e.message.include? "uncaught throw"
|
483
507
|
default += ", not #{e.message.split(/ /).last}"
|
484
508
|
rescue NameError => e # 1.8 exception
|
485
509
|
raise e unless e.name == sym
|
@@ -489,6 +513,7 @@ module Minitest
|
|
489
513
|
end
|
490
514
|
|
491
515
|
assert caught, message(msg) { default }
|
516
|
+
value
|
492
517
|
rescue Assertion
|
493
518
|
raise
|
494
519
|
rescue => e
|
@@ -561,15 +586,13 @@ module Minitest
|
|
561
586
|
|
562
587
|
return captured_stdout.read, captured_stderr.read
|
563
588
|
ensure
|
564
|
-
captured_stdout.unlink
|
565
|
-
captured_stderr.unlink
|
566
589
|
$stdout.reopen orig_stdout
|
567
590
|
$stderr.reopen orig_stderr
|
568
591
|
|
569
592
|
orig_stdout.close
|
570
593
|
orig_stderr.close
|
571
|
-
captured_stdout.close
|
572
|
-
captured_stderr.close
|
594
|
+
captured_stdout.close!
|
595
|
+
captured_stderr.close!
|
573
596
|
end
|
574
597
|
end
|
575
598
|
end
|
@@ -579,12 +602,12 @@ module Minitest
|
|
579
602
|
|
580
603
|
def exception_details e, msg
|
581
604
|
[
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
605
|
+
msg,
|
606
|
+
"Class: <#{e.class}>",
|
607
|
+
"Message: <#{e.message.inspect}>",
|
608
|
+
"---Backtrace---",
|
609
|
+
Minitest.filter_backtrace(e.backtrace),
|
610
|
+
"---------------",
|
588
611
|
].join "\n"
|
589
612
|
end
|
590
613
|
|
@@ -593,7 +616,7 @@ module Minitest
|
|
593
616
|
# you to put time-bombs in your tests if you need to keep
|
594
617
|
# something around until a later date lest you forget about it.
|
595
618
|
|
596
|
-
def fail_after y,m,d,msg
|
619
|
+
def fail_after y, m, d, msg
|
597
620
|
flunk msg if Time.now > Time.local(y, m, d)
|
598
621
|
end
|
599
622
|
|
@@ -627,7 +650,7 @@ module Minitest
|
|
627
650
|
# Fails if +test+ is truthy.
|
628
651
|
|
629
652
|
def refute test, msg = nil
|
630
|
-
msg ||= message { "Expected #{mu_pp
|
653
|
+
msg ||= message { "Expected #{mu_pp test} to not be truthy" }
|
631
654
|
assert !test, msg
|
632
655
|
end
|
633
656
|
|
@@ -635,7 +658,7 @@ module Minitest
|
|
635
658
|
# Fails if +obj+ is empty.
|
636
659
|
|
637
660
|
def refute_empty obj, msg = nil
|
638
|
-
msg = message(msg) { "Expected #{mu_pp
|
661
|
+
msg = message(msg) { "Expected #{mu_pp obj} to not be empty" }
|
639
662
|
assert_respond_to obj, :empty?
|
640
663
|
refute obj.empty?, msg
|
641
664
|
end
|
@@ -647,7 +670,7 @@ module Minitest
|
|
647
670
|
|
648
671
|
def refute_equal exp, act, msg = nil
|
649
672
|
msg = message(msg) {
|
650
|
-
"Expected #{mu_pp
|
673
|
+
"Expected #{mu_pp act} to not be equal to #{mu_pp exp}"
|
651
674
|
}
|
652
675
|
refute exp == act, msg
|
653
676
|
end
|
@@ -678,7 +701,7 @@ module Minitest
|
|
678
701
|
|
679
702
|
def refute_includes collection, obj, msg = nil
|
680
703
|
msg = message(msg) {
|
681
|
-
"Expected #{mu_pp
|
704
|
+
"Expected #{mu_pp collection} to not include #{mu_pp obj}"
|
682
705
|
}
|
683
706
|
assert_respond_to collection, :include?
|
684
707
|
refute collection.include?(obj), msg
|
@@ -689,7 +712,7 @@ module Minitest
|
|
689
712
|
|
690
713
|
def refute_instance_of cls, obj, msg = nil
|
691
714
|
msg = message(msg) {
|
692
|
-
"Expected #{mu_pp
|
715
|
+
"Expected #{mu_pp obj} to not be an instance of #{cls}"
|
693
716
|
}
|
694
717
|
refute obj.instance_of?(cls), msg
|
695
718
|
end
|
@@ -698,7 +721,7 @@ module Minitest
|
|
698
721
|
# Fails if +obj+ is a kind of +cls+.
|
699
722
|
|
700
723
|
def refute_kind_of cls, obj, msg = nil
|
701
|
-
msg = message(msg) { "Expected #{mu_pp
|
724
|
+
msg = message(msg) { "Expected #{mu_pp obj} to not be a kind of #{cls}" }
|
702
725
|
refute obj.kind_of?(cls), msg
|
703
726
|
end
|
704
727
|
|
@@ -707,7 +730,7 @@ module Minitest
|
|
707
730
|
|
708
731
|
def refute_match matcher, obj, msg = nil
|
709
732
|
msg = message(msg) { "Expected #{mu_pp matcher} to not match #{mu_pp obj}" }
|
710
|
-
assert_respond_to matcher,
|
733
|
+
assert_respond_to matcher, :=~
|
711
734
|
matcher = Regexp.new Regexp.escape matcher if String === matcher
|
712
735
|
refute matcher =~ obj, msg
|
713
736
|
end
|
@@ -716,10 +739,34 @@ module Minitest
|
|
716
739
|
# Fails if +obj+ is nil.
|
717
740
|
|
718
741
|
def refute_nil obj, msg = nil
|
719
|
-
msg = message(msg) { "Expected #{mu_pp
|
742
|
+
msg = message(msg) { "Expected #{mu_pp obj} to not be nil" }
|
720
743
|
refute obj.nil?, msg
|
721
744
|
end
|
722
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
|
+
|
723
770
|
##
|
724
771
|
# Fails if +o1+ is not +op+ +o2+. Eg:
|
725
772
|
#
|
@@ -728,7 +775,7 @@ module Minitest
|
|
728
775
|
|
729
776
|
def refute_operator o1, op, o2 = UNDEFINED, msg = nil
|
730
777
|
return refute_predicate o1, op, msg if UNDEFINED == o2
|
731
|
-
msg = message(msg) { "Expected #{mu_pp
|
778
|
+
msg = message(msg) { "Expected #{mu_pp o1} to not be #{op} #{mu_pp o2}" }
|
732
779
|
refute o1.__send__(op, o2), msg
|
733
780
|
end
|
734
781
|
|
@@ -750,17 +797,18 @@ module Minitest
|
|
750
797
|
# str.wont_be :empty?
|
751
798
|
|
752
799
|
def refute_predicate o1, op, msg = nil
|
753
|
-
msg = message(msg) { "Expected #{mu_pp
|
800
|
+
msg = message(msg) { "Expected #{mu_pp o1} to not be #{op}" }
|
754
801
|
refute o1.__send__(op), msg
|
755
802
|
end
|
756
803
|
|
757
804
|
##
|
758
805
|
# Fails if +obj+ responds to the message +meth+.
|
806
|
+
# include_all defaults to false to match Object#respond_to?
|
759
807
|
|
760
|
-
def refute_respond_to obj, meth, msg = nil
|
761
|
-
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}" }
|
762
810
|
|
763
|
-
refute obj.respond_to?(meth), msg
|
811
|
+
refute obj.respond_to?(meth, include_all), msg
|
764
812
|
end
|
765
813
|
|
766
814
|
##
|
@@ -779,10 +827,10 @@ module Minitest
|
|
779
827
|
# gets listed at the end of the run but doesn't cause a failure
|
780
828
|
# exit code.
|
781
829
|
|
782
|
-
def skip msg = nil,
|
830
|
+
def skip msg = nil, _ignored = nil
|
783
831
|
msg ||= "Skipped, no message given"
|
784
832
|
@skip = true
|
785
|
-
raise Minitest::Skip, msg
|
833
|
+
raise Minitest::Skip, msg
|
786
834
|
end
|
787
835
|
|
788
836
|
##
|
@@ -791,9 +839,9 @@ module Minitest
|
|
791
839
|
# date, but still holds you accountable and prevents you from
|
792
840
|
# forgetting it.
|
793
841
|
|
794
|
-
def skip_until y,m,d,msg
|
842
|
+
def skip_until y, m, d, msg
|
795
843
|
skip msg if Time.now < Time.local(y, m, d)
|
796
|
-
where = caller.first.
|
844
|
+
where = caller(1..1).first.rpartition(":in").reject(&:empty?).first
|
797
845
|
warn "Stale skip_until %p at %s" % [msg, where]
|
798
846
|
end
|
799
847
|
|
data/lib/minitest/autorun.rb
CHANGED
data/lib/minitest/benchmark.rb
CHANGED
@@ -47,8 +47,6 @@ module Minitest
|
|
47
47
|
|
48
48
|
def self.bench_linear min, max, step = 10
|
49
49
|
(min..max).step(step).to_a
|
50
|
-
rescue LocalJumpError # 1.8.6
|
51
|
-
r = []; (min..max).step(step) { |n| r << n }; r
|
52
50
|
end
|
53
51
|
|
54
52
|
##
|
@@ -83,7 +81,7 @@ module Minitest
|
|
83
81
|
def assert_performance validation, &work
|
84
82
|
range = self.class.bench_range
|
85
83
|
|
86
|
-
io.print
|
84
|
+
io.print self.name
|
87
85
|
|
88
86
|
times = []
|
89
87
|
|
@@ -217,7 +215,7 @@ module Minitest
|
|
217
215
|
##
|
218
216
|
# Takes an array of x/y pairs and calculates the general R^2 value.
|
219
217
|
#
|
220
|
-
# See:
|
218
|
+
# See: https://en.wikipedia.org/wiki/Coefficient_of_determination
|
221
219
|
|
222
220
|
def fit_error xys
|
223
221
|
y_bar = sigma(xys) { |_, y| y } / xys.size.to_f
|
@@ -232,11 +230,11 @@ module Minitest
|
|
232
230
|
#
|
233
231
|
# Takes x and y values and returns [a, b, r^2].
|
234
232
|
#
|
235
|
-
# See:
|
233
|
+
# See: https://mathworld.wolfram.com/LeastSquaresFittingExponential.html
|
236
234
|
|
237
235
|
def fit_exponential xs, ys
|
238
236
|
n = xs.size
|
239
|
-
xys = xs.zip
|
237
|
+
xys = xs.zip ys
|
240
238
|
sxlny = sigma(xys) { |x, y| x * Math.log(y) }
|
241
239
|
slny = sigma(xys) { |_, y| Math.log(y) }
|
242
240
|
sx2 = sigma(xys) { |x, _| x * x }
|
@@ -254,11 +252,11 @@ module Minitest
|
|
254
252
|
#
|
255
253
|
# Takes x and y values and returns [a, b, r^2].
|
256
254
|
#
|
257
|
-
# See:
|
255
|
+
# See: https://mathworld.wolfram.com/LeastSquaresFittingLogarithmic.html
|
258
256
|
|
259
257
|
def fit_logarithmic xs, ys
|
260
258
|
n = xs.size
|
261
|
-
xys = xs.zip
|
259
|
+
xys = xs.zip ys
|
262
260
|
slnx2 = sigma(xys) { |x, _| Math.log(x) ** 2 }
|
263
261
|
slnx = sigma(xys) { |x, _| Math.log(x) }
|
264
262
|
sylnx = sigma(xys) { |x, y| y * Math.log(x) }
|
@@ -276,11 +274,11 @@ module Minitest
|
|
276
274
|
#
|
277
275
|
# Takes x and y values and returns [a, b, r^2].
|
278
276
|
#
|
279
|
-
# See:
|
277
|
+
# See: https://mathworld.wolfram.com/LeastSquaresFitting.html
|
280
278
|
|
281
279
|
def fit_linear xs, ys
|
282
280
|
n = xs.size
|
283
|
-
xys = xs.zip
|
281
|
+
xys = xs.zip ys
|
284
282
|
sx = sigma xs
|
285
283
|
sy = sigma ys
|
286
284
|
sx2 = sigma(xs) { |x| x ** 2 }
|
@@ -298,11 +296,11 @@ module Minitest
|
|
298
296
|
#
|
299
297
|
# Takes x and y values and returns [a, b, r^2].
|
300
298
|
#
|
301
|
-
# See:
|
299
|
+
# See: https://mathworld.wolfram.com/LeastSquaresFittingPowerLaw.html
|
302
300
|
|
303
301
|
def fit_power xs, ys
|
304
302
|
n = xs.size
|
305
|
-
xys = xs.zip
|
303
|
+
xys = xs.zip ys
|
306
304
|
slnxlny = sigma(xys) { |x, y| Math.log(x) * Math.log(y) }
|
307
305
|
slnx = sigma(xs) { |x | Math.log(x) }
|
308
306
|
slny = sigma(ys) { | y| Math.log(y) }
|
@@ -323,7 +321,7 @@ module Minitest
|
|
323
321
|
|
324
322
|
def sigma enum, &block
|
325
323
|
enum = enum.map(&block) if block
|
326
|
-
enum.
|
324
|
+
enum.sum
|
327
325
|
end
|
328
326
|
|
329
327
|
##
|
@@ -419,7 +417,6 @@ module Minitest
|
|
419
417
|
end
|
420
418
|
end
|
421
419
|
|
422
|
-
|
423
420
|
##
|
424
421
|
# Create a benchmark that verifies that the performance is logarithmic.
|
425
422
|
#
|