minitest 5.10.3 → 5.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data/History.rdoc +193 -4
- data/Manifest.txt +1 -0
- data/README.rdoc +87 -14
- data/Rakefile +4 -16
- data/lib/hoe/minitest.rb +0 -4
- data/lib/minitest/assertions.rb +145 -32
- data/lib/minitest/benchmark.rb +34 -3
- data/lib/minitest/expectations.rb +54 -35
- data/lib/minitest/mock.rb +11 -10
- data/lib/minitest/parallel.rb +1 -1
- data/lib/minitest/spec.rb +20 -8
- data/lib/minitest/test.rb +15 -69
- data/lib/minitest.rb +241 -31
- data/test/minitest/metametameta.rb +43 -8
- data/test/minitest/test_minitest_assertions.rb +1588 -0
- data/test/minitest/test_minitest_mock.rb +380 -7
- data/test/minitest/test_minitest_reporter.rb +45 -21
- data/test/minitest/test_minitest_spec.rb +220 -143
- data/test/minitest/test_minitest_test.rb +119 -1120
- data.tar.gz.sig +0 -0
- metadata +34 -24
- metadata.gz.sig +0 -0
data/lib/minitest/assertions.rb
CHANGED
@@ -27,20 +27,18 @@ module Minitest
|
|
27
27
|
# figure out what diff to use.
|
28
28
|
|
29
29
|
def self.diff
|
30
|
+
return @diff if defined? @diff
|
31
|
+
|
30
32
|
@diff = if (RbConfig::CONFIG["host_os"] =~ /mswin|mingw/ &&
|
31
33
|
system("diff.exe", __FILE__, __FILE__)) then
|
32
34
|
"diff.exe -u"
|
33
|
-
elsif Minitest::Test.maglev? then
|
34
|
-
"diff -u"
|
35
35
|
elsif system("gdiff", __FILE__, __FILE__)
|
36
36
|
"gdiff -u" # solaris and kin suck
|
37
37
|
elsif system("diff", __FILE__, __FILE__)
|
38
38
|
"diff -u"
|
39
39
|
else
|
40
40
|
nil
|
41
|
-
end
|
42
|
-
|
43
|
-
@diff
|
41
|
+
end
|
44
42
|
end
|
45
43
|
|
46
44
|
##
|
@@ -55,22 +53,16 @@ module Minitest
|
|
55
53
|
# diff command or if it doesn't make sense to diff the output
|
56
54
|
# (single line, short output), then it simply returns a basic
|
57
55
|
# comparison between the two.
|
56
|
+
#
|
57
|
+
# See +things_to_diff+ for more info.
|
58
58
|
|
59
59
|
def diff exp, act
|
60
|
-
expect = mu_pp_for_diff exp
|
61
|
-
butwas = mu_pp_for_diff act
|
62
60
|
result = nil
|
63
61
|
|
64
|
-
|
65
|
-
(expect.include?("\n") ||
|
66
|
-
butwas.include?("\n") ||
|
67
|
-
expect.size > 30 ||
|
68
|
-
butwas.size > 30 ||
|
69
|
-
expect == butwas) &&
|
70
|
-
Minitest::Assertions.diff
|
62
|
+
expect, butwas = things_to_diff(exp, act)
|
71
63
|
|
72
64
|
return "Expected: #{mu_pp exp}\n Actual: #{mu_pp act}" unless
|
73
|
-
|
65
|
+
expect
|
74
66
|
|
75
67
|
Tempfile.open("expect") do |a|
|
76
68
|
a.puts expect
|
@@ -99,10 +91,40 @@ module Minitest
|
|
99
91
|
result
|
100
92
|
end
|
101
93
|
|
94
|
+
##
|
95
|
+
# Returns things to diff [expect, butwas], or [nil, nil] if nothing to diff.
|
96
|
+
#
|
97
|
+
# Criterion:
|
98
|
+
#
|
99
|
+
# 1. Strings include newlines or escaped newlines, but not both.
|
100
|
+
# 2. or: String lengths are > 30 characters.
|
101
|
+
# 3. or: Strings are equal to each other (but maybe different encodings?).
|
102
|
+
# 4. and: we found a diff executable.
|
103
|
+
|
104
|
+
def things_to_diff exp, act
|
105
|
+
expect = mu_pp_for_diff exp
|
106
|
+
butwas = mu_pp_for_diff act
|
107
|
+
|
108
|
+
e1, e2 = expect.include?("\n"), expect.include?("\\n")
|
109
|
+
b1, b2 = butwas.include?("\n"), butwas.include?("\\n")
|
110
|
+
|
111
|
+
need_to_diff =
|
112
|
+
(e1 ^ e2 ||
|
113
|
+
b1 ^ b2 ||
|
114
|
+
expect.size > 30 ||
|
115
|
+
butwas.size > 30 ||
|
116
|
+
expect == butwas) &&
|
117
|
+
Minitest::Assertions.diff
|
118
|
+
|
119
|
+
need_to_diff && [expect, butwas]
|
120
|
+
end
|
121
|
+
|
102
122
|
##
|
103
123
|
# This returns a human-readable version of +obj+. By default
|
104
|
-
# #inspect is called. You can override this to use #
|
124
|
+
# #inspect is called. You can override this to use #pretty_inspect
|
105
125
|
# if you want.
|
126
|
+
#
|
127
|
+
# See Minitest::Test.make_my_diffs_pretty!
|
106
128
|
|
107
129
|
def mu_pp obj
|
108
130
|
s = obj.inspect
|
@@ -110,8 +132,11 @@ module Minitest
|
|
110
132
|
if defined? Encoding then
|
111
133
|
s = s.encode Encoding.default_external
|
112
134
|
|
113
|
-
if String === obj && obj.encoding != Encoding.default_external
|
114
|
-
|
135
|
+
if String === obj && (obj.encoding != Encoding.default_external ||
|
136
|
+
!obj.valid_encoding?) then
|
137
|
+
enc = "# encoding: #{obj.encoding}"
|
138
|
+
val = "# valid: #{obj.valid_encoding?}"
|
139
|
+
s = "#{enc}\n#{val}\n#{s}"
|
115
140
|
end
|
116
141
|
end
|
117
142
|
|
@@ -119,13 +144,32 @@ module Minitest
|
|
119
144
|
end
|
120
145
|
|
121
146
|
##
|
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
|
147
|
+
# This returns a diff-able more human-readable version of +obj+.
|
148
|
+
# This differs from the regular mu_pp because it expands escaped
|
149
|
+
# newlines and makes hex-values (like object_ids) generic. This
|
125
150
|
# uses mu_pp to do the first pass and then cleans it up.
|
126
151
|
|
127
152
|
def mu_pp_for_diff obj
|
128
|
-
mu_pp
|
153
|
+
str = mu_pp obj
|
154
|
+
|
155
|
+
# both '\n' & '\\n' (_after_ mu_pp (aka inspect))
|
156
|
+
single = !!str.match(/(?<!\\|^)\\n/)
|
157
|
+
double = !!str.match(/(?<=\\|^)\\n/)
|
158
|
+
|
159
|
+
process =
|
160
|
+
if single ^ double then
|
161
|
+
if single then
|
162
|
+
lambda { |s| s == "\\n" ? "\n" : s } # unescape
|
163
|
+
else
|
164
|
+
lambda { |s| s == "\\\\n" ? "\\n\n" : s } # unescape a bit, add nls
|
165
|
+
end
|
166
|
+
else
|
167
|
+
:itself # leave it alone
|
168
|
+
end
|
169
|
+
|
170
|
+
str.
|
171
|
+
gsub(/\\?\\n/, &process).
|
172
|
+
gsub(/:0x[a-fA-F0-9]{4,}/m, ":0xXXXXXX") # anonymize hex values
|
129
173
|
end
|
130
174
|
|
131
175
|
##
|
@@ -173,7 +217,7 @@ module Minitest
|
|
173
217
|
msg = message(msg, E) { diff exp, act }
|
174
218
|
result = assert exp == act, msg
|
175
219
|
|
176
|
-
if
|
220
|
+
if nil == exp then
|
177
221
|
if Minitest::VERSION =~ /^6/ then
|
178
222
|
refute_nil exp, "Use assert_nil if expecting nil."
|
179
223
|
else
|
@@ -205,8 +249,8 @@ module Minitest
|
|
205
249
|
# For comparing Floats. Fails unless +exp+ and +act+ have a relative
|
206
250
|
# error less than +epsilon+.
|
207
251
|
|
208
|
-
def assert_in_epsilon
|
209
|
-
assert_in_delta
|
252
|
+
def assert_in_epsilon exp, act, epsilon = 0.001, msg = nil
|
253
|
+
assert_in_delta exp, act, [exp.abs, act.abs].min * epsilon, msg
|
210
254
|
end
|
211
255
|
|
212
256
|
##
|
@@ -283,6 +327,9 @@ module Minitest
|
|
283
327
|
# See also: #assert_silent
|
284
328
|
|
285
329
|
def assert_output stdout = nil, stderr = nil
|
330
|
+
flunk "assert_output requires a block to capture output." unless
|
331
|
+
block_given?
|
332
|
+
|
286
333
|
out, err = capture_io do
|
287
334
|
yield
|
288
335
|
end
|
@@ -294,6 +341,18 @@ module Minitest
|
|
294
341
|
x = send out_msg, stdout, out, "In stdout" if out_msg
|
295
342
|
|
296
343
|
(!stdout || x) && (!stderr || y)
|
344
|
+
rescue Assertion
|
345
|
+
raise
|
346
|
+
rescue => e
|
347
|
+
raise UnexpectedError, e
|
348
|
+
end
|
349
|
+
|
350
|
+
##
|
351
|
+
# Fails unless +path+ exists.
|
352
|
+
|
353
|
+
def assert_path_exists path, msg = nil
|
354
|
+
msg = message(msg) { "Expected path '#{path}' to exist" }
|
355
|
+
assert File.exist?(path), msg
|
297
356
|
end
|
298
357
|
|
299
358
|
##
|
@@ -316,9 +375,26 @@ module Minitest
|
|
316
375
|
#
|
317
376
|
# +exp+ takes an optional message on the end to help explain
|
318
377
|
# failures and defaults to StandardError if no exception class is
|
319
|
-
# passed.
|
378
|
+
# passed. Eg:
|
379
|
+
#
|
380
|
+
# assert_raises(CustomError) { method_with_custom_error }
|
381
|
+
#
|
382
|
+
# With custom error message:
|
383
|
+
#
|
384
|
+
# assert_raises(CustomError, 'This should have raised CustomError') { method_with_custom_error }
|
385
|
+
#
|
386
|
+
# Using the returned object:
|
387
|
+
#
|
388
|
+
# error = assert_raises(CustomError) do
|
389
|
+
# raise CustomError, 'This is really bad'
|
390
|
+
# end
|
391
|
+
#
|
392
|
+
# assert_equal 'This is really bad', error.message
|
320
393
|
|
321
394
|
def assert_raises *exp
|
395
|
+
flunk "assert_raises requires a block to capture errors." unless
|
396
|
+
block_given?
|
397
|
+
|
322
398
|
msg = "#{exp.pop}.\n" if String === exp.last
|
323
399
|
exp << StandardError if exp.empty?
|
324
400
|
|
@@ -327,7 +403,7 @@ module Minitest
|
|
327
403
|
rescue *exp => e
|
328
404
|
pass # count assertion
|
329
405
|
return e
|
330
|
-
rescue Minitest::Skip
|
406
|
+
rescue Minitest::Assertion # incl Skip & UnexpectedError
|
331
407
|
# don't count assertion
|
332
408
|
raise
|
333
409
|
rescue SignalException, SystemExit
|
@@ -397,7 +473,7 @@ module Minitest
|
|
397
473
|
def assert_throws sym, msg = nil
|
398
474
|
default = "Expected #{mu_pp(sym)} to have been thrown"
|
399
475
|
caught = true
|
400
|
-
catch(sym) do
|
476
|
+
value = catch(sym) do
|
401
477
|
begin
|
402
478
|
yield
|
403
479
|
rescue ThreadError => e # wtf?!? 1.8 + threads == suck
|
@@ -413,6 +489,11 @@ module Minitest
|
|
413
489
|
end
|
414
490
|
|
415
491
|
assert caught, message(msg) { default }
|
492
|
+
value
|
493
|
+
rescue Assertion
|
494
|
+
raise
|
495
|
+
rescue => e
|
496
|
+
raise UnexpectedError, e
|
416
497
|
end
|
417
498
|
|
418
499
|
##
|
@@ -481,10 +562,13 @@ module Minitest
|
|
481
562
|
|
482
563
|
return captured_stdout.read, captured_stderr.read
|
483
564
|
ensure
|
484
|
-
captured_stdout.unlink
|
485
|
-
captured_stderr.unlink
|
486
565
|
$stdout.reopen orig_stdout
|
487
566
|
$stderr.reopen orig_stderr
|
567
|
+
|
568
|
+
orig_stdout.close
|
569
|
+
orig_stderr.close
|
570
|
+
captured_stdout.close!
|
571
|
+
captured_stderr.close!
|
488
572
|
end
|
489
573
|
end
|
490
574
|
end
|
@@ -504,7 +588,16 @@ module Minitest
|
|
504
588
|
end
|
505
589
|
|
506
590
|
##
|
507
|
-
# Fails
|
591
|
+
# Fails after a given date (in the local time zone). This allows
|
592
|
+
# you to put time-bombs in your tests if you need to keep
|
593
|
+
# something around until a later date lest you forget about it.
|
594
|
+
|
595
|
+
def fail_after y,m,d,msg
|
596
|
+
flunk msg if Time.now > Time.local(y, m, d)
|
597
|
+
end
|
598
|
+
|
599
|
+
##
|
600
|
+
# Fails with +msg+.
|
508
601
|
|
509
602
|
def flunk msg = nil
|
510
603
|
msg ||= "Epic Fail!"
|
@@ -534,7 +627,7 @@ module Minitest
|
|
534
627
|
|
535
628
|
def refute test, msg = nil
|
536
629
|
msg ||= message { "Expected #{mu_pp(test)} to not be truthy" }
|
537
|
-
|
630
|
+
assert !test, msg
|
538
631
|
end
|
539
632
|
|
540
633
|
##
|
@@ -638,6 +731,14 @@ module Minitest
|
|
638
731
|
refute o1.__send__(op, o2), msg
|
639
732
|
end
|
640
733
|
|
734
|
+
##
|
735
|
+
# Fails if +path+ exists.
|
736
|
+
|
737
|
+
def refute_path_exists path, msg = nil
|
738
|
+
msg = message(msg) { "Expected path '#{path}' to not exist" }
|
739
|
+
refute File.exist?(path), msg
|
740
|
+
end
|
741
|
+
|
641
742
|
##
|
642
743
|
# For testing with predicates.
|
643
744
|
#
|
@@ -683,6 +784,18 @@ module Minitest
|
|
683
784
|
raise Minitest::Skip, msg, bt
|
684
785
|
end
|
685
786
|
|
787
|
+
##
|
788
|
+
# Skips the current run until a given date (in the local time
|
789
|
+
# zone). This allows you to put some fixes on hold until a later
|
790
|
+
# date, but still holds you accountable and prevents you from
|
791
|
+
# forgetting it.
|
792
|
+
|
793
|
+
def skip_until y,m,d,msg
|
794
|
+
skip msg if Time.now < Time.local(y, m, d)
|
795
|
+
where = caller.first.rpartition(':in').reject(&:empty?).first
|
796
|
+
warn "Stale skip_until %p at %s" % [msg, where]
|
797
|
+
end
|
798
|
+
|
686
799
|
##
|
687
800
|
# Was this testcase skipped? Meant for #teardown.
|
688
801
|
|
data/lib/minitest/benchmark.rb
CHANGED
@@ -109,8 +109,8 @@ module Minitest
|
|
109
109
|
# is applied against the slope itself. As such, you probably want
|
110
110
|
# to tighten it from the default.
|
111
111
|
#
|
112
|
-
# See
|
113
|
-
# more details.
|
112
|
+
# See https://www.graphpad.com/guides/prism/8/curve-fitting/reg_intepretingnonlinr2.htm
|
113
|
+
# for more details.
|
114
114
|
#
|
115
115
|
# Fit is calculated by #fit_linear.
|
116
116
|
#
|
@@ -318,7 +318,7 @@ module Minitest
|
|
318
318
|
# Enumerates over +enum+ mapping +block+ if given, returning the
|
319
319
|
# sum of the result. Eg:
|
320
320
|
#
|
321
|
-
# sigma([1, 2, 3]) # => 1 + 2 + 3 =>
|
321
|
+
# sigma([1, 2, 3]) # => 1 + 2 + 3 => 6
|
322
322
|
# sigma([1, 2, 3]) { |n| n ** 2 } # => 1 + 4 + 9 => 14
|
323
323
|
|
324
324
|
def sigma enum, &block
|
@@ -418,6 +418,37 @@ module Minitest
|
|
418
418
|
assert_performance_exponential threshold, &work
|
419
419
|
end
|
420
420
|
end
|
421
|
+
|
422
|
+
|
423
|
+
##
|
424
|
+
# Create a benchmark that verifies that the performance is logarithmic.
|
425
|
+
#
|
426
|
+
# describe "my class Bench" do
|
427
|
+
# bench_performance_logarithmic "algorithm" do |n|
|
428
|
+
# @obj.algorithm(n)
|
429
|
+
# end
|
430
|
+
# end
|
431
|
+
|
432
|
+
def self.bench_performance_logarithmic name, threshold = 0.99, &work
|
433
|
+
bench name do
|
434
|
+
assert_performance_logarithmic threshold, &work
|
435
|
+
end
|
436
|
+
end
|
437
|
+
|
438
|
+
##
|
439
|
+
# Create a benchmark that verifies that the performance is power.
|
440
|
+
#
|
441
|
+
# describe "my class Bench" do
|
442
|
+
# bench_performance_power "algorithm" do |n|
|
443
|
+
# @obj.algorithm(n)
|
444
|
+
# end
|
445
|
+
# end
|
446
|
+
|
447
|
+
def self.bench_performance_power name, threshold = 0.99, &work
|
448
|
+
bench name do
|
449
|
+
assert_performance_power threshold, &work
|
450
|
+
end
|
451
|
+
end
|
421
452
|
end
|
422
453
|
|
423
454
|
Minitest::Spec.register_spec_type(/Bench(mark)?$/, Minitest::BenchSpec)
|
@@ -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,7 +118,7 @@ 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
|
|
@@ -126,7 +127,7 @@ module Minitest::Expectations
|
|
126
127
|
##
|
127
128
|
# See Minitest::Assertions#assert_raises
|
128
129
|
#
|
129
|
-
#
|
130
|
+
# _ { ... }.must_raise exception
|
130
131
|
#
|
131
132
|
# :method: must_raise
|
132
133
|
|
@@ -135,7 +136,7 @@ module Minitest::Expectations
|
|
135
136
|
##
|
136
137
|
# See Minitest::Assertions#assert_respond_to
|
137
138
|
#
|
138
|
-
# obj.must_respond_to msg
|
139
|
+
# _(obj).must_respond_to msg
|
139
140
|
#
|
140
141
|
# :method: must_respond_to
|
141
142
|
|
@@ -144,7 +145,7 @@ module Minitest::Expectations
|
|
144
145
|
##
|
145
146
|
# See Minitest::Assertions#assert_same
|
146
147
|
#
|
147
|
-
# a.must_be_same_as b
|
148
|
+
# _(a).must_be_same_as b
|
148
149
|
#
|
149
150
|
# :method: must_be_same_as
|
150
151
|
|
@@ -153,7 +154,7 @@ module Minitest::Expectations
|
|
153
154
|
##
|
154
155
|
# See Minitest::Assertions#assert_silent
|
155
156
|
#
|
156
|
-
#
|
157
|
+
# _ { ... }.must_be_silent
|
157
158
|
#
|
158
159
|
# :method: must_be_silent
|
159
160
|
|
@@ -162,16 +163,34 @@ module Minitest::Expectations
|
|
162
163
|
##
|
163
164
|
# See Minitest::Assertions#assert_throws
|
164
165
|
#
|
165
|
-
#
|
166
|
+
# _ { ... }.must_throw sym
|
166
167
|
#
|
167
168
|
# :method: must_throw
|
168
169
|
|
169
170
|
infect_an_assertion :assert_throws, :must_throw, :block
|
170
171
|
|
172
|
+
##
|
173
|
+
# See Minitest::Assertions#assert_path_exists
|
174
|
+
#
|
175
|
+
# _(some_path).path_must_exist
|
176
|
+
#
|
177
|
+
# :method: path_must_exist
|
178
|
+
|
179
|
+
infect_an_assertion :assert_path_exists, :path_must_exist, :unary
|
180
|
+
|
181
|
+
##
|
182
|
+
# See Minitest::Assertions#refute_path_exists
|
183
|
+
#
|
184
|
+
# _(some_path).path_wont_exist
|
185
|
+
#
|
186
|
+
# :method: path_wont_exist
|
187
|
+
|
188
|
+
infect_an_assertion :refute_path_exists, :path_wont_exist, :unary
|
189
|
+
|
171
190
|
##
|
172
191
|
# See Minitest::Assertions#refute_empty
|
173
192
|
#
|
174
|
-
# collection.wont_be_empty
|
193
|
+
# _(collection).wont_be_empty
|
175
194
|
#
|
176
195
|
# :method: wont_be_empty
|
177
196
|
|
@@ -180,7 +199,7 @@ module Minitest::Expectations
|
|
180
199
|
##
|
181
200
|
# See Minitest::Assertions#refute_equal
|
182
201
|
#
|
183
|
-
# a.wont_equal b
|
202
|
+
# _(a).wont_equal b
|
184
203
|
#
|
185
204
|
# :method: wont_equal
|
186
205
|
|
@@ -189,18 +208,18 @@ module Minitest::Expectations
|
|
189
208
|
##
|
190
209
|
# See Minitest::Assertions#refute_in_delta
|
191
210
|
#
|
192
|
-
# n.wont_be_close_to m [, delta]
|
211
|
+
# _(n).wont_be_close_to m [, delta]
|
193
212
|
#
|
194
213
|
# :method: wont_be_close_to
|
195
214
|
|
196
215
|
infect_an_assertion :refute_in_delta, :wont_be_close_to
|
197
216
|
|
198
|
-
|
217
|
+
infect_an_assertion :refute_in_delta, :wont_be_within_delta # :nodoc:
|
199
218
|
|
200
219
|
##
|
201
220
|
# See Minitest::Assertions#refute_in_epsilon
|
202
221
|
#
|
203
|
-
# n.wont_be_within_epsilon m [, epsilon]
|
222
|
+
# _(n).wont_be_within_epsilon m [, epsilon]
|
204
223
|
#
|
205
224
|
# :method: wont_be_within_epsilon
|
206
225
|
|
@@ -209,7 +228,7 @@ module Minitest::Expectations
|
|
209
228
|
##
|
210
229
|
# See Minitest::Assertions#refute_includes
|
211
230
|
#
|
212
|
-
# collection.wont_include obj
|
231
|
+
# _(collection).wont_include obj
|
213
232
|
#
|
214
233
|
# :method: wont_include
|
215
234
|
|
@@ -218,7 +237,7 @@ module Minitest::Expectations
|
|
218
237
|
##
|
219
238
|
# See Minitest::Assertions#refute_instance_of
|
220
239
|
#
|
221
|
-
# obj.wont_be_instance_of klass
|
240
|
+
# _(obj).wont_be_instance_of klass
|
222
241
|
#
|
223
242
|
# :method: wont_be_instance_of
|
224
243
|
|
@@ -227,7 +246,7 @@ module Minitest::Expectations
|
|
227
246
|
##
|
228
247
|
# See Minitest::Assertions#refute_kind_of
|
229
248
|
#
|
230
|
-
# obj.wont_be_kind_of mod
|
249
|
+
# _(obj).wont_be_kind_of mod
|
231
250
|
#
|
232
251
|
# :method: wont_be_kind_of
|
233
252
|
|
@@ -236,7 +255,7 @@ module Minitest::Expectations
|
|
236
255
|
##
|
237
256
|
# See Minitest::Assertions#refute_match
|
238
257
|
#
|
239
|
-
# a.wont_match b
|
258
|
+
# _(a).wont_match b
|
240
259
|
#
|
241
260
|
# :method: wont_match
|
242
261
|
|
@@ -245,7 +264,7 @@ module Minitest::Expectations
|
|
245
264
|
##
|
246
265
|
# See Minitest::Assertions#refute_nil
|
247
266
|
#
|
248
|
-
# obj.wont_be_nil
|
267
|
+
# _(obj).wont_be_nil
|
249
268
|
#
|
250
269
|
# :method: wont_be_nil
|
251
270
|
|
@@ -254,7 +273,7 @@ module Minitest::Expectations
|
|
254
273
|
##
|
255
274
|
# See Minitest::Assertions#refute_operator
|
256
275
|
#
|
257
|
-
# n.wont_be :<=, 42
|
276
|
+
# _(n).wont_be :<=, 42
|
258
277
|
#
|
259
278
|
# This can also do predicates:
|
260
279
|
#
|
@@ -267,7 +286,7 @@ module Minitest::Expectations
|
|
267
286
|
##
|
268
287
|
# See Minitest::Assertions#refute_respond_to
|
269
288
|
#
|
270
|
-
# obj.wont_respond_to msg
|
289
|
+
# _(obj).wont_respond_to msg
|
271
290
|
#
|
272
291
|
# :method: wont_respond_to
|
273
292
|
|
@@ -276,7 +295,7 @@ module Minitest::Expectations
|
|
276
295
|
##
|
277
296
|
# See Minitest::Assertions#refute_same
|
278
297
|
#
|
279
|
-
# a.wont_be_same_as b
|
298
|
+
# _(a).wont_be_same_as b
|
280
299
|
#
|
281
300
|
# :method: wont_be_same_as
|
282
301
|
|
data/lib/minitest/mock.rb
CHANGED
@@ -207,7 +207,9 @@ class Object
|
|
207
207
|
# assert obj_under_test.stale?
|
208
208
|
# end
|
209
209
|
# end
|
210
|
-
|
210
|
+
#--
|
211
|
+
# NOTE: keyword args in callables are NOT checked for correctness
|
212
|
+
# against the existing method. Too many edge cases to be worth it.
|
211
213
|
|
212
214
|
def stub name, val_or_callable, *block_args
|
213
215
|
new_name = "__minitest_stub__#{name}"
|
@@ -223,17 +225,16 @@ class Object
|
|
223
225
|
metaclass.send :alias_method, new_name, name
|
224
226
|
|
225
227
|
metaclass.send :define_method, name do |*args, &blk|
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
blk.call(*block_args) if blk
|
233
|
-
|
234
|
-
ret
|
228
|
+
if val_or_callable.respond_to? :call then
|
229
|
+
val_or_callable.call(*args, &blk)
|
230
|
+
else
|
231
|
+
blk.call(*block_args) if blk
|
232
|
+
val_or_callable
|
233
|
+
end
|
235
234
|
end
|
236
235
|
|
236
|
+
metaclass.send(:ruby2_keywords, name) if metaclass.respond_to?(:ruby2_keywords, true)
|
237
|
+
|
237
238
|
yield self
|
238
239
|
ensure
|
239
240
|
metaclass.send :undef_method, name
|