minitest 5.11.3 → 5.27.0

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.
@@ -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 = if (RbConfig::CONFIG["host_os"] =~ /mswin|mingw/ &&
31
- system("diff.exe", __FILE__, __FILE__)) then
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 Minitest::Test.maglev? then
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("diff", __FILE__, __FILE__)
35
+ elsif system "diff", __FILE__, __FILE__ then
38
36
  "diff -u"
39
37
  else
40
38
  nil
41
- end unless defined? @diff
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
- need_to_diff =
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
- need_to_diff
63
+ expect
74
64
 
75
- Tempfile.open("expect") do |a|
65
+ Tempfile.create "expect" do |a|
76
66
  a.puts expect
77
67
  a.flush
78
68
 
79
- Tempfile.open("butwas") do |b|
69
+ Tempfile.create "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
- "No visible difference in the #{klass}#inspect output.\n",
91
- "You should look at the implementation of #== on ",
92
- "#{klass} or its members.\n",
93
- expect,
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 #pretty_print
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
- if defined? Encoding then
111
- s = s.encode Encoding.default_external
130
+ return s unless String === obj &&
131
+ (obj.encoding != Encoding.default_external || !obj.valid_encoding?)
112
132
 
113
- if String === obj && obj.encoding != Encoding.default_external then
114
- s = "# encoding: #{obj.encoding}\n#{s}"
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+. This
123
- # differs from the regular mu_pp because it expands escaped
124
- # newlines and makes hex-values generic (like object_ids). This
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(obj).gsub(/\\n/, "\n").gsub(/:0x[a-fA-F0-9]{4,}/m, ":0xXXXXXX")
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,22 @@ 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(obj)} to be empty" }
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
+
199
+ def _caller_uplevel # :nodoc:
200
+ backtrace = caller
201
+ real_caller = Minitest.filter_backtrace(caller).first
202
+ backtrace.index(real_caller)
203
+ end
204
+
157
205
  E = "" # :nodoc:
158
206
 
159
207
  ##
@@ -174,13 +222,10 @@ module Minitest
174
222
  result = assert exp == act, msg
175
223
 
176
224
  if nil == exp then
177
- if Minitest::VERSION =~ /^6/ then
225
+ if Minitest::VERSION >= "6" then
178
226
  refute_nil exp, "Use assert_nil if expecting nil."
179
227
  else
180
- where = Minitest.filter_backtrace(caller).first
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."
228
+ warn "DEPRECATED: Use assert_nil if expecting nil. This will fail in Minitest 6.", uplevel: _caller_uplevel
184
229
  end
185
230
  end
186
231
 
@@ -214,7 +259,7 @@ module Minitest
214
259
 
215
260
  def assert_includes collection, obj, msg = nil
216
261
  msg = message(msg) {
217
- "Expected #{mu_pp(collection)} to include #{mu_pp(obj)}"
262
+ "Expected #{mu_pp collection} to include #{mu_pp obj}"
218
263
  }
219
264
  assert_respond_to collection, :include?
220
265
  assert collection.include?(obj), msg
@@ -225,7 +270,7 @@ module Minitest
225
270
 
226
271
  def assert_instance_of cls, obj, msg = nil
227
272
  msg = message(msg) {
228
- "Expected #{mu_pp(obj)} to be an instance of #{cls}, not #{obj.class}"
273
+ "Expected #{mu_pp obj} to be an instance of #{cls}, not #{obj.class}"
229
274
  }
230
275
 
231
276
  assert obj.instance_of?(cls), msg
@@ -236,7 +281,8 @@ module Minitest
236
281
 
237
282
  def assert_kind_of cls, obj, msg = nil
238
283
  msg = message(msg) {
239
- "Expected #{mu_pp(obj)} to be a kind of #{cls}, not #{obj.class}" }
284
+ "Expected #{mu_pp obj} to be a kind of #{cls}, not #{obj.class}"
285
+ }
240
286
 
241
287
  assert obj.kind_of?(cls), msg
242
288
  end
@@ -246,16 +292,18 @@ module Minitest
246
292
 
247
293
  def assert_match matcher, obj, msg = nil
248
294
  msg = message(msg) { "Expected #{mu_pp matcher} to match #{mu_pp obj}" }
249
- assert_respond_to matcher, :"=~"
295
+ assert_respond_to matcher, :=~
250
296
  matcher = Regexp.new Regexp.escape matcher if String === matcher
251
297
  assert matcher =~ obj, msg
298
+
299
+ Regexp.last_match
252
300
  end
253
301
 
254
302
  ##
255
303
  # Fails unless +obj+ is nil
256
304
 
257
305
  def assert_nil obj, msg = nil
258
- msg = message(msg) { "Expected #{mu_pp(obj)} to be nil" }
306
+ msg = message(msg) { "Expected #{mu_pp obj} to be nil" }
259
307
  assert obj.nil?, msg
260
308
  end
261
309
 
@@ -266,7 +314,7 @@ module Minitest
266
314
 
267
315
  def assert_operator o1, op, o2 = UNDEFINED, msg = nil
268
316
  return assert_predicate o1, op, msg if UNDEFINED == o2
269
- msg = message(msg) { "Expected #{mu_pp(o1)} to be #{op} #{mu_pp(o2)}" }
317
+ msg = message(msg) { "Expected #{mu_pp o1} to be #{op} #{mu_pp o2}" }
270
318
  assert o1.__send__(op, o2), msg
271
319
  end
272
320
 
@@ -283,6 +331,9 @@ module Minitest
283
331
  # See also: #assert_silent
284
332
 
285
333
  def assert_output stdout = nil, stderr = nil
334
+ flunk "assert_output requires a block to capture output." unless
335
+ block_given?
336
+
286
337
  out, err = capture_io do
287
338
  yield
288
339
  end
@@ -294,6 +345,41 @@ module Minitest
294
345
  x = send out_msg, stdout, out, "In stdout" if out_msg
295
346
 
296
347
  (!stdout || x) && (!stderr || y)
348
+ rescue Assertion
349
+ raise
350
+ rescue => e
351
+ raise UnexpectedError, e
352
+ end
353
+
354
+ ##
355
+ # Fails unless +path+ exists.
356
+
357
+ def assert_path_exists path, msg = nil
358
+ msg = message(msg) { "Expected path '#{path}' to exist" }
359
+ assert File.exist?(path), msg
360
+ end
361
+
362
+ ##
363
+ # For testing with pattern matching (only supported with Ruby 3.0 and later)
364
+ #
365
+ # # pass
366
+ # assert_pattern { [1,2,3] => [Integer, Integer, Integer] }
367
+ #
368
+ # # fail "length mismatch (given 3, expected 1)"
369
+ # assert_pattern { [1,2,3] => [Integer] }
370
+ #
371
+ # The bare <tt>=></tt> pattern will raise a NoMatchingPatternError on failure, which would
372
+ # normally be counted as a test error. This assertion rescues NoMatchingPatternError and
373
+ # generates a test failure. Any other exception will be raised as normal and generate a test
374
+ # error.
375
+
376
+ def assert_pattern
377
+ flunk "assert_pattern requires a block to capture errors." unless block_given?
378
+
379
+ yield
380
+ pass
381
+ rescue NoMatchingPatternError => e
382
+ flunk e.message
297
383
  end
298
384
 
299
385
  ##
@@ -306,7 +392,7 @@ module Minitest
306
392
  # str.must_be :empty?
307
393
 
308
394
  def assert_predicate o1, op, msg = nil
309
- msg = message(msg) { "Expected #{mu_pp(o1)} to be #{op}" }
395
+ msg = message(msg) { "Expected #{mu_pp o1} to be #{op}" }
310
396
  assert o1.__send__(op), msg
311
397
  end
312
398
 
@@ -316,9 +402,26 @@ module Minitest
316
402
  #
317
403
  # +exp+ takes an optional message on the end to help explain
318
404
  # failures and defaults to StandardError if no exception class is
319
- # passed.
405
+ # passed. Eg:
406
+ #
407
+ # assert_raises(CustomError) { method_with_custom_error }
408
+ #
409
+ # With custom error message:
410
+ #
411
+ # assert_raises(CustomError, 'This should have raised CustomError') { method_with_custom_error }
412
+ #
413
+ # Using the returned object:
414
+ #
415
+ # error = assert_raises(CustomError) do
416
+ # raise CustomError, 'This is really bad'
417
+ # end
418
+ #
419
+ # assert_equal 'This is really bad', error.message
320
420
 
321
421
  def assert_raises *exp
422
+ flunk "assert_raises requires a block to capture errors." unless
423
+ block_given?
424
+
322
425
  msg = "#{exp.pop}.\n" if String === exp.last
323
426
  exp << StandardError if exp.empty?
324
427
 
@@ -327,30 +430,31 @@ module Minitest
327
430
  rescue *exp => e
328
431
  pass # count assertion
329
432
  return e
330
- rescue Minitest::Skip, Minitest::Assertion
433
+ rescue Minitest::Assertion # incl Skip & UnexpectedError
331
434
  # don't count assertion
332
435
  raise
333
436
  rescue SignalException, SystemExit
334
437
  raise
335
438
  rescue Exception => e
336
439
  flunk proc {
337
- exception_details(e, "#{msg}#{mu_pp(exp)} exception expected, not")
440
+ exception_details(e, "#{msg}#{mu_pp exp} exception expected, not")
338
441
  }
339
442
  end
340
443
 
341
444
  exp = exp.first if exp.size == 1
342
445
 
343
- flunk "#{msg}#{mu_pp(exp)} expected but nothing was raised."
446
+ flunk "#{msg}#{mu_pp exp} expected but nothing was raised."
344
447
  end
345
448
 
346
449
  ##
347
450
  # Fails unless +obj+ responds to +meth+.
451
+ # include_all defaults to false to match Object#respond_to?
348
452
 
349
- def assert_respond_to obj, meth, msg = nil
453
+ def assert_respond_to obj, meth, msg = nil, include_all: false
350
454
  msg = message(msg) {
351
- "Expected #{mu_pp(obj)} (#{obj.class}) to respond to ##{meth}"
455
+ "Expected #{mu_pp obj} (#{obj.class}) to respond to ##{meth}"
352
456
  }
353
- assert obj.respond_to?(meth), msg
457
+ assert obj.respond_to?(meth, include_all), msg
354
458
  end
355
459
 
356
460
  ##
@@ -370,13 +474,12 @@ module Minitest
370
474
  # Fails unless the call returns a true value
371
475
 
372
476
  def assert_send send_ary, m = nil
373
- where = Minitest.filter_backtrace(caller).first
374
- where = where.split(/:in /, 2).first # clean up noise
375
- warn "DEPRECATED: assert_send. From #{where}"
477
+ warn "DEPRECATED: assert_send.", uplevel: _caller_uplevel
376
478
 
377
479
  recv, msg, *args = send_ary
378
480
  m = message(m) {
379
- "Expected #{mu_pp(recv)}.#{msg}(*#{mu_pp(args)}) to return true" }
481
+ "Expected #{mu_pp recv}.#{msg}(*#{mu_pp args}) to return true"
482
+ }
380
483
  assert recv.__send__(msg, *args), m
381
484
  end
382
485
 
@@ -395,24 +498,24 @@ module Minitest
395
498
  # Fails unless the block throws +sym+
396
499
 
397
500
  def assert_throws sym, msg = nil
398
- default = "Expected #{mu_pp(sym)} to have been thrown"
501
+ default = "Expected #{mu_pp sym} to have been thrown"
399
502
  caught = true
400
- catch(sym) do
503
+ value = catch sym do
401
504
  begin
402
505
  yield
403
- rescue ThreadError => e # wtf?!? 1.8 + threads == suck
404
- default += ", not \:#{e.message[/uncaught throw \`(\w+?)\'/, 1]}"
405
- rescue ArgumentError => e # 1.9 exception
406
- raise e unless e.message.include?("uncaught throw")
506
+ rescue ArgumentError => e # 1.9+ exception
507
+ raise e unless e.message.include? "uncaught throw"
407
508
  default += ", not #{e.message.split(/ /).last}"
408
- rescue NameError => e # 1.8 exception
409
- raise e unless e.name == sym
410
- default += ", not #{e.name.inspect}"
411
509
  end
412
510
  caught = false
413
511
  end
414
512
 
415
513
  assert caught, message(msg) { default }
514
+ value
515
+ rescue Assertion
516
+ raise
517
+ rescue => e
518
+ raise UnexpectedError, e
416
519
  end
417
520
 
418
521
  ##
@@ -481,10 +584,13 @@ module Minitest
481
584
 
482
585
  return captured_stdout.read, captured_stderr.read
483
586
  ensure
484
- captured_stdout.unlink
485
- captured_stderr.unlink
486
587
  $stdout.reopen orig_stdout
487
588
  $stderr.reopen orig_stderr
589
+
590
+ orig_stdout.close
591
+ orig_stderr.close
592
+ captured_stdout.close!
593
+ captured_stderr.close!
488
594
  end
489
595
  end
490
596
  end
@@ -494,17 +600,26 @@ module Minitest
494
600
 
495
601
  def exception_details e, msg
496
602
  [
497
- "#{msg}",
498
- "Class: <#{e.class}>",
499
- "Message: <#{e.message.inspect}>",
500
- "---Backtrace---",
501
- "#{Minitest.filter_backtrace(e.backtrace).join("\n")}",
502
- "---------------",
603
+ msg,
604
+ "Class: <#{e.class}>",
605
+ "Message: <#{e.message.inspect}>",
606
+ "---Backtrace---",
607
+ Minitest.filter_backtrace(e.backtrace),
608
+ "---------------",
503
609
  ].join "\n"
504
610
  end
505
611
 
506
612
  ##
507
- # Fails with +msg+
613
+ # Fails after a given date (in the local time zone). This allows
614
+ # you to put time-bombs in your tests if you need to keep
615
+ # something around until a later date lest you forget about it.
616
+
617
+ def fail_after y, m, d, msg
618
+ flunk msg if Time.now > Time.local(y, m, d)
619
+ end
620
+
621
+ ##
622
+ # Fails with +msg+.
508
623
 
509
624
  def flunk msg = nil
510
625
  msg ||= "Epic Fail!"
@@ -533,15 +648,15 @@ module Minitest
533
648
  # Fails if +test+ is truthy.
534
649
 
535
650
  def refute test, msg = nil
536
- msg ||= message { "Expected #{mu_pp(test)} to not be truthy" }
537
- not assert !test, msg
651
+ msg ||= message { "Expected #{mu_pp test} to not be truthy" }
652
+ assert !test, msg
538
653
  end
539
654
 
540
655
  ##
541
656
  # Fails if +obj+ is empty.
542
657
 
543
658
  def refute_empty obj, msg = nil
544
- msg = message(msg) { "Expected #{mu_pp(obj)} to not be empty" }
659
+ msg = message(msg) { "Expected #{mu_pp obj} to not be empty" }
545
660
  assert_respond_to obj, :empty?
546
661
  refute obj.empty?, msg
547
662
  end
@@ -553,7 +668,7 @@ module Minitest
553
668
 
554
669
  def refute_equal exp, act, msg = nil
555
670
  msg = message(msg) {
556
- "Expected #{mu_pp(act)} to not be equal to #{mu_pp(exp)}"
671
+ "Expected #{mu_pp act} to not be equal to #{mu_pp exp}"
557
672
  }
558
673
  refute exp == act, msg
559
674
  end
@@ -575,8 +690,8 @@ module Minitest
575
690
  # For comparing Floats. Fails if +exp+ and +act+ have a relative error
576
691
  # less than +epsilon+.
577
692
 
578
- def refute_in_epsilon a, b, epsilon = 0.001, msg = nil
579
- refute_in_delta a, b, a * epsilon, msg
693
+ def refute_in_epsilon exp, act, epsilon = 0.001, msg = nil
694
+ refute_in_delta exp, act, [exp.abs, act.abs].min * epsilon, msg
580
695
  end
581
696
 
582
697
  ##
@@ -584,7 +699,7 @@ module Minitest
584
699
 
585
700
  def refute_includes collection, obj, msg = nil
586
701
  msg = message(msg) {
587
- "Expected #{mu_pp(collection)} to not include #{mu_pp(obj)}"
702
+ "Expected #{mu_pp collection} to not include #{mu_pp obj}"
588
703
  }
589
704
  assert_respond_to collection, :include?
590
705
  refute collection.include?(obj), msg
@@ -595,7 +710,7 @@ module Minitest
595
710
 
596
711
  def refute_instance_of cls, obj, msg = nil
597
712
  msg = message(msg) {
598
- "Expected #{mu_pp(obj)} to not be an instance of #{cls}"
713
+ "Expected #{mu_pp obj} to not be an instance of #{cls}"
599
714
  }
600
715
  refute obj.instance_of?(cls), msg
601
716
  end
@@ -604,7 +719,7 @@ module Minitest
604
719
  # Fails if +obj+ is a kind of +cls+.
605
720
 
606
721
  def refute_kind_of cls, obj, msg = nil
607
- msg = message(msg) { "Expected #{mu_pp(obj)} to not be a kind of #{cls}" }
722
+ msg = message(msg) { "Expected #{mu_pp obj} to not be a kind of #{cls}" }
608
723
  refute obj.kind_of?(cls), msg
609
724
  end
610
725
 
@@ -613,7 +728,7 @@ module Minitest
613
728
 
614
729
  def refute_match matcher, obj, msg = nil
615
730
  msg = message(msg) { "Expected #{mu_pp matcher} to not match #{mu_pp obj}" }
616
- assert_respond_to matcher, :"=~"
731
+ assert_respond_to matcher, :=~
617
732
  matcher = Regexp.new Regexp.escape matcher if String === matcher
618
733
  refute matcher =~ obj, msg
619
734
  end
@@ -622,10 +737,31 @@ module Minitest
622
737
  # Fails if +obj+ is nil.
623
738
 
624
739
  def refute_nil obj, msg = nil
625
- msg = message(msg) { "Expected #{mu_pp(obj)} to not be nil" }
740
+ msg = message(msg) { "Expected #{mu_pp obj} to not be nil" }
626
741
  refute obj.nil?, msg
627
742
  end
628
743
 
744
+ ##
745
+ # For testing with pattern matching (only supported with Ruby 3.0 and later)
746
+ #
747
+ # # pass
748
+ # refute_pattern { [1,2,3] => [String] }
749
+ #
750
+ # # fail "NoMatchingPatternError expected, but nothing was raised."
751
+ # refute_pattern { [1,2,3] => [Integer, Integer, Integer] }
752
+ #
753
+ # This assertion expects a NoMatchingPatternError exception, and will fail if none is raised. Any
754
+ # other exceptions will be raised as normal and generate a test error.
755
+
756
+ def refute_pattern
757
+ flunk "refute_pattern requires a block to capture errors." unless block_given?
758
+
759
+ yield
760
+ flunk "NoMatchingPatternError expected, but nothing was raised."
761
+ rescue NoMatchingPatternError
762
+ pass
763
+ end
764
+
629
765
  ##
630
766
  # Fails if +o1+ is not +op+ +o2+. Eg:
631
767
  #
@@ -634,10 +770,18 @@ module Minitest
634
770
 
635
771
  def refute_operator o1, op, o2 = UNDEFINED, msg = nil
636
772
  return refute_predicate o1, op, msg if UNDEFINED == o2
637
- msg = message(msg) { "Expected #{mu_pp(o1)} to not be #{op} #{mu_pp(o2)}" }
773
+ msg = message(msg) { "Expected #{mu_pp o1} to not be #{op} #{mu_pp o2}" }
638
774
  refute o1.__send__(op, o2), msg
639
775
  end
640
776
 
777
+ ##
778
+ # Fails if +path+ exists.
779
+
780
+ def refute_path_exists path, msg = nil
781
+ msg = message(msg) { "Expected path '#{path}' to not exist" }
782
+ refute File.exist?(path), msg
783
+ end
784
+
641
785
  ##
642
786
  # For testing with predicates.
643
787
  #
@@ -648,17 +792,18 @@ module Minitest
648
792
  # str.wont_be :empty?
649
793
 
650
794
  def refute_predicate o1, op, msg = nil
651
- msg = message(msg) { "Expected #{mu_pp(o1)} to not be #{op}" }
795
+ msg = message(msg) { "Expected #{mu_pp o1} to not be #{op}" }
652
796
  refute o1.__send__(op), msg
653
797
  end
654
798
 
655
799
  ##
656
800
  # Fails if +obj+ responds to the message +meth+.
801
+ # include_all defaults to false to match Object#respond_to?
657
802
 
658
- def refute_respond_to obj, meth, msg = nil
659
- msg = message(msg) { "Expected #{mu_pp(obj)} to not respond to #{meth}" }
803
+ def refute_respond_to obj, meth, msg = nil, include_all: false
804
+ msg = message(msg) { "Expected #{mu_pp obj} to not respond to #{meth}" }
660
805
 
661
- refute obj.respond_to?(meth), msg
806
+ refute obj.respond_to?(meth, include_all), msg
662
807
  end
663
808
 
664
809
  ##
@@ -677,10 +822,22 @@ module Minitest
677
822
  # gets listed at the end of the run but doesn't cause a failure
678
823
  # exit code.
679
824
 
680
- def skip msg = nil, bt = caller
825
+ def skip msg = nil, _ignored = nil
681
826
  msg ||= "Skipped, no message given"
682
827
  @skip = true
683
- raise Minitest::Skip, msg, bt
828
+ raise Minitest::Skip, msg
829
+ end
830
+
831
+ ##
832
+ # Skips the current run until a given date (in the local time
833
+ # zone). This allows you to put some fixes on hold until a later
834
+ # date, but still holds you accountable and prevents you from
835
+ # forgetting it.
836
+
837
+ def skip_until y, m, d, msg
838
+ skip msg if Time.now < Time.local(y, m, d)
839
+ where = caller(1..1).first.rpartition(":in").reject(&:empty?).first
840
+ warn "Stale skip_until %p at %s" % [msg, where]
684
841
  end
685
842
 
686
843
  ##
@@ -1,13 +1,6 @@
1
- begin
2
- require "rubygems"
3
- gem "minitest"
4
- rescue Gem::LoadError
5
- # do nothing
6
- end
7
-
8
- require "minitest"
9
- require "minitest/spec"
10
- require "minitest/mock"
11
- require "minitest/hell" if ENV["MT_HELL"]
1
+ require_relative "../minitest"
2
+ require_relative "spec"
3
+ require_relative "mock"
4
+ require_relative "hell" if ENV["MT_HELL"]
12
5
 
13
6
  Minitest.autorun