minitest 5.22.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.
@@ -2,7 +2,7 @@ require "minitest/autorun"
2
2
  require "minitest/metametameta"
3
3
  require "forwardable"
4
4
 
5
- class Runnable
5
+ class FakeTest < Minitest::Test
6
6
  def woot
7
7
  assert true
8
8
  end
@@ -13,10 +13,6 @@ class TestMinitestReporter < MetaMetaMetaTestCase
13
13
  attr_accessor :r, :io
14
14
 
15
15
  def new_composite_reporter
16
- # Ruby bug in older versions of 2.2 & 2.3 on all platforms
17
- # Latest Windows builds were 2.2.6 and 2.3.3. Latest Ruby releases were
18
- # 2.2.10 and 2.3.8.
19
- skip if windows? && RUBY_VERSION < '2.4'
20
16
  reporter = Minitest::CompositeReporter.new
21
17
  reporter << Minitest::SummaryReporter.new(self.io)
22
18
  reporter << Minitest::ProgressReporter.new(self.io)
@@ -31,13 +27,13 @@ class TestMinitestReporter < MetaMetaMetaTestCase
31
27
 
32
28
  def setup
33
29
  super
34
- self.io = StringIO.new("")
30
+ self.io = StringIO.new(+"")
35
31
  self.r = new_composite_reporter
36
32
  end
37
33
 
38
34
  def error_test
39
35
  unless defined? @et then
40
- @et = Minitest::Test.new(:woot)
36
+ @et = FakeTest.new :woot
41
37
  @et.failures << Minitest::UnexpectedError.new(begin
42
38
  raise "no"
43
39
  rescue => e
@@ -60,7 +56,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
60
56
 
61
57
  ex.set_backtrace ary
62
58
 
63
- @sse = Minitest::Test.new(:woot)
59
+ @sse = FakeTest.new :woot
64
60
  @sse.failures << Minitest::UnexpectedError.new(ex)
65
61
  @sse = Minitest::Result.from @sse
66
62
  end
@@ -69,7 +65,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
69
65
 
70
66
  def fail_test
71
67
  unless defined? @ft then
72
- @ft = Minitest::Test.new(:woot)
68
+ @ft = FakeTest.new :woot
73
69
  @ft.failures << begin
74
70
  raise Minitest::Assertion, "boo"
75
71
  rescue Minitest::Assertion => e
@@ -81,18 +77,18 @@ class TestMinitestReporter < MetaMetaMetaTestCase
81
77
  end
82
78
 
83
79
  def passing_test
84
- @pt ||= Minitest::Result.from Minitest::Test.new(:woot)
80
+ @pt ||= Minitest::Result.from FakeTest.new(:woot)
85
81
  end
86
82
 
87
83
  def passing_test_with_metadata
88
- test = Minitest::Test.new(:woot)
84
+ test = FakeTest.new :woot
89
85
  test.metadata[:meta] = :data
90
86
  @pt ||= Minitest::Result.from test
91
87
  end
92
88
 
93
89
  def skip_test
94
90
  unless defined? @st then
95
- @st = Minitest::Test.new(:woot)
91
+ @st = FakeTest.new :woot
96
92
  @st.failures << begin
97
93
  raise Minitest::Skip
98
94
  rescue Minitest::Assertion => e
@@ -248,7 +244,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
248
244
  r.start
249
245
  r.report
250
246
 
251
- exp = clean <<-EOM
247
+ exp = <<~EOM
252
248
  Run options:
253
249
 
254
250
  # Running:
@@ -268,7 +264,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
268
264
  r.record passing_test
269
265
  r.report
270
266
 
271
- exp = clean <<-EOM
267
+ exp = <<~EOM
272
268
  Run options:
273
269
 
274
270
  # Running:
@@ -288,7 +284,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
288
284
  r.record fail_test
289
285
  r.report
290
286
 
291
- exp = clean <<-EOM
287
+ exp = <<~EOM
292
288
  Run options:
293
289
 
294
290
  # Running:
@@ -298,7 +294,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
298
294
  Finished in 0.00
299
295
 
300
296
  1) Failure:
301
- Minitest::Test#woot [FILE:LINE]:
297
+ FakeTest#woot [FILE:LINE]:
302
298
  boo
303
299
 
304
300
  1 runs, 0 assertions, 1 failures, 0 errors, 0 skips
@@ -312,7 +308,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
312
308
  r.record error_test
313
309
  r.report
314
310
 
315
- exp = clean <<-EOM
311
+ exp = <<~EOM
316
312
  Run options:
317
313
 
318
314
  # Running:
@@ -322,7 +318,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
322
318
  Finished in 0.00
323
319
 
324
320
  1) Error:
325
- Minitest::Test#woot:
321
+ FakeTest#woot:
326
322
  RuntimeError: no
327
323
  FILE:LINE:in 'error_test'
328
324
  FILE:LINE:in 'test_report_error'
@@ -338,7 +334,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
338
334
  r.record system_stack_error_test
339
335
  r.report
340
336
 
341
- exp = clean <<-EOM
337
+ exp = <<~EOM
342
338
  Run options:
343
339
 
344
340
  # Running:
@@ -348,7 +344,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
348
344
  Finished in 0.00
349
345
 
350
346
  1) Error:
351
- Minitest::Test#woot:
347
+ FakeTest#woot:
352
348
  SystemStackError: 274 -> 12
353
349
  a
354
350
  b
@@ -377,7 +373,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
377
373
  r.report
378
374
  end
379
375
 
380
- exp = clean <<-EOM
376
+ exp = <<~EOM
381
377
  Run options:
382
378
 
383
379
  # Running:
@@ -406,7 +402,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
406
402
  r.report
407
403
  end
408
404
 
409
- exp = "Minitest::Test#woot [foo.rb:123]"
405
+ exp = "FakeTest#woot [foo.rb:123]"
410
406
 
411
407
  assert_includes io.string, exp
412
408
  end
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  require "minitest/metametameta"
3
2
  require "stringio"
4
3
 
@@ -12,15 +11,12 @@ class ExampleA; end
12
11
  class ExampleB < ExampleA; end
13
12
 
14
13
  describe Minitest::Spec do
15
- # helps to deal with 2.4 deprecation of Fixnum for Integer
16
- Int = 1.class
17
-
18
14
  # do not parallelize this suite... it just can"t handle it.
19
15
 
20
16
  def assert_triggered expected = "blah", klass = Minitest::Assertion
21
17
  @assertion_count += 1
22
18
 
23
- e = assert_raises(klass) do
19
+ e = assert_raises klass do
24
20
  yield
25
21
  end
26
22
 
@@ -29,17 +25,17 @@ describe Minitest::Spec do
29
25
  msg.gsub!(/(\d\.\d{6})\d+/, '\1xxx') # normalize: ruby version, impl, platform
30
26
  msg.gsub!(/:0x[Xa-fA-F0-9]{4,}[ @].+?>/, ":0xXXXXXX@PATH>")
31
27
 
32
- if expected
28
+ return unless expected
29
+
30
+ @assertion_count += 1
31
+ case expected
32
+ when String then
33
+ assert_equal expected, msg
34
+ when Regexp then
33
35
  @assertion_count += 1
34
- case expected
35
- when String then
36
- assert_equal expected, msg
37
- when Regexp then
38
- @assertion_count += 1
39
- assert_match expected, msg
40
- else
41
- flunk "Unknown: #{expected.inspect}"
42
- end
36
+ assert_match expected, msg
37
+ else
38
+ flunk "Unknown: #{expected.inspect}"
43
39
  end
44
40
  end
45
41
 
@@ -196,7 +192,7 @@ describe Minitest::Spec do
196
192
  methods = Minitest::Expectations.public_instance_methods.grep(/must|wont/)
197
193
  methods.map!(&:to_s) if Symbol === methods.first
198
194
 
199
- musts, wonts = methods.sort.partition { |m| m =~ /must/ }
195
+ musts, wonts = methods.sort.partition { |m| m.include? "must" }
200
196
 
201
197
  expected_musts = %w[must_be
202
198
  must_be_close_to
@@ -216,11 +212,12 @@ describe Minitest::Spec do
216
212
  must_raise
217
213
  must_respond_to
218
214
  must_throw
215
+ must_verify
219
216
  path_must_exist]
220
217
 
221
- bad = %w[not raise throw send output be_silent]
218
+ bad = %w[not raise throw send output be_silent verify]
222
219
 
223
- expected_wonts = expected_musts.map { |m| m.sub(/must/, "wont") }.sort
220
+ expected_wonts = expected_musts.map { |m| m.sub("must", "wont") }.sort
224
221
  expected_wonts.reject! { |m| m =~ /wont_#{Regexp.union(*bad)}/ }
225
222
 
226
223
  _(musts).must_equal expected_musts
@@ -284,18 +281,14 @@ describe Minitest::Spec do
284
281
  end
285
282
 
286
283
  it "needs to warn on equality with nil" do
287
- @assertion_count += 1 # extra test
284
+ @assertion_count = 3
285
+ @assertion_count += 2 unless error_on_warn? # 2 extra assertions
286
+
287
+ exp = /DEPRECATED: Use assert_nil if expecting nil from .* This will fail in Minitest 6./
288
288
 
289
- out, err = capture_io do
289
+ assert_deprecation exp do
290
290
  assert_success _(nil).must_equal(nil)
291
291
  end
292
-
293
- exp = "DEPRECATED: Use assert_nil if expecting nil from #{__FILE__}:#{__LINE__-3}. " \
294
- "This will fail in Minitest 6.\n"
295
- exp = "" if $-w.nil?
296
-
297
- assert_empty out
298
- assert_equal exp, err
299
292
  end
300
293
 
301
294
  it "needs to verify floats outside a delta" do
@@ -403,12 +396,12 @@ describe Minitest::Spec do
403
396
  it "needs to verify instances of a class" do
404
397
  assert_success _(42).wont_be_instance_of(String)
405
398
 
406
- assert_triggered "Expected 42 to not be a kind of #{Int.name}." do
407
- _(42).wont_be_kind_of Int
399
+ assert_triggered "Expected 42 to not be a kind of Integer." do
400
+ _(42).wont_be_kind_of Integer
408
401
  end
409
402
 
410
- assert_triggered "msg.\nExpected 42 to not be an instance of #{Int.name}." do
411
- _(42).wont_be_instance_of Int, "msg"
403
+ assert_triggered "msg.\nExpected 42 to not be an instance of Integer." do
404
+ _(42).wont_be_instance_of Integer, "msg"
412
405
  end
413
406
  end
414
407
 
@@ -418,26 +411,26 @@ describe Minitest::Spec do
418
411
  assert_success _(42).wont_be_kind_of(String)
419
412
  assert_success _(proc {}).wont_be_kind_of(String)
420
413
 
421
- assert_triggered "Expected 42 to not be a kind of #{Int.name}." do
422
- _(42).wont_be_kind_of Int
414
+ assert_triggered "Expected 42 to not be a kind of Integer." do
415
+ _(42).wont_be_kind_of Integer
423
416
  end
424
417
 
425
- assert_triggered "msg.\nExpected 42 to not be a kind of #{Int.name}." do
426
- _(42).wont_be_kind_of Int, "msg"
418
+ assert_triggered "msg.\nExpected 42 to not be a kind of Integer." do
419
+ _(42).wont_be_kind_of Integer, "msg"
427
420
  end
428
421
  end
429
422
 
430
423
  it "needs to verify kinds of objects" do
431
424
  @assertion_count += 3 # extra test
432
425
 
433
- assert_success _(6 * 7).must_be_kind_of(Int)
426
+ assert_success _(6 * 7).must_be_kind_of(Integer)
434
427
  assert_success _(6 * 7).must_be_kind_of(Numeric)
435
428
 
436
- assert_triggered "Expected 42 to be a kind of String, not #{Int.name}." do
429
+ assert_triggered "Expected 42 to be a kind of String, not Integer." do
437
430
  _(6 * 7).must_be_kind_of String
438
431
  end
439
432
 
440
- assert_triggered "msg.\nExpected 42 to be a kind of String, not #{Int.name}." do
433
+ assert_triggered "msg.\nExpected 42 to be a kind of String, not Integer." do
441
434
  _(6 * 7).must_be_kind_of String, "msg"
442
435
  end
443
436
 
@@ -576,7 +569,8 @@ describe Minitest::Spec do
576
569
 
577
570
  it "can NOT use must_equal in a thread. It must use expect in a thread" do
578
571
  skip "N/A" if ENV["MT_NO_EXPECTATIONS"]
579
- assert_raises RuntimeError do
572
+
573
+ assert_raises RuntimeError, Minitest::UnexpectedWarning do
580
574
  capture_io do
581
575
  Thread.new { (1 + 1).must_equal 2 }.join
582
576
  end
@@ -586,29 +580,33 @@ describe Minitest::Spec do
586
580
  it "fails gracefully when expectation used outside of `it`" do
587
581
  skip "N/A" if ENV["MT_NO_EXPECTATIONS"]
588
582
 
589
- @assertion_count += 1
583
+ @assertion_count += 2 # assert_match is compound
590
584
 
591
- e = assert_raises RuntimeError do
585
+ e = assert_raises RuntimeError, Minitest::UnexpectedWarning do
592
586
  capture_io do
593
587
  Thread.new { # forces ctx to be nil
594
- describe("woot") do
588
+ describe "woot" do
595
589
  (1 + 1).must_equal 2
596
590
  end
597
591
  }.join
598
592
  end
599
593
  end
600
594
 
601
- assert_equal "Calling #must_equal outside of test.", e.message
595
+ exp = "Calling #must_equal outside of test."
596
+ exp = "DEPRECATED: global use of must_equal from" if error_on_warn?
597
+
598
+ assert_match exp, e.message
602
599
  end
603
600
 
604
601
  it "deprecates expectation used without _" do
605
602
  skip "N/A" if ENV["MT_NO_EXPECTATIONS"]
606
603
 
607
- @assertion_count += 3
604
+ @assertion_count += 1
605
+ @assertion_count += 2 unless error_on_warn?
608
606
 
609
607
  exp = /DEPRECATED: global use of must_equal from/
610
608
 
611
- assert_output "", exp do
609
+ assert_deprecation exp do
612
610
  (1 + 1).must_equal 2
613
611
  end
614
612
  end
@@ -618,12 +616,13 @@ describe Minitest::Spec do
618
616
  it "deprecates expectation used without _ with empty backtrace_filter" do
619
617
  skip "N/A" if ENV["MT_NO_EXPECTATIONS"]
620
618
 
621
- @assertion_count += 3
619
+ @assertion_count += 1
620
+ @assertion_count += 2 unless error_on_warn?
622
621
 
623
622
  exp = /DEPRECATED: global use of must_equal from/
624
623
 
625
624
  with_empty_backtrace_filter do
626
- assert_output "", exp do
625
+ assert_deprecation exp do
627
626
  (1 + 1).must_equal 2
628
627
  end
629
628
  end
@@ -654,9 +653,9 @@ describe Minitest::Spec do
654
653
  end
655
654
 
656
655
  it "needs to verify types of objects" do
657
- assert_success _(6 * 7).must_be_instance_of(Int)
656
+ assert_success _(6 * 7).must_be_instance_of(Integer)
658
657
 
659
- exp = "Expected 42 to be an instance of String, not #{Int.name}."
658
+ exp = "Expected 42 to be an instance of String, not Integer."
660
659
 
661
660
  assert_triggered exp do
662
661
  _(6 * 7).must_be_instance_of String
@@ -683,7 +682,7 @@ describe Minitest::Spec do
683
682
  assert_success _(41).must_be(:<, 42)
684
683
 
685
684
  assert_triggered "Expected 42 to be < 41." do
686
- _(42).must_be(:<, 41)
685
+ _(42).must_be :<, 41
687
686
  end
688
687
  end
689
688
 
@@ -700,11 +699,11 @@ describe Minitest::Spec do
700
699
  it "needs to verify using respond_to" do
701
700
  assert_success _(42).must_respond_to(:+)
702
701
 
703
- assert_triggered "Expected 42 (#{Int.name}) to respond to #clear." do
702
+ assert_triggered "Expected 42 (Integer) to respond to #clear." do
704
703
  _(42).must_respond_to :clear
705
704
  end
706
705
 
707
- assert_triggered "msg.\nExpected 42 (#{Int.name}) to respond to #clear." do
706
+ assert_triggered "msg.\nExpected 42 (Integer) to respond to #clear." do
708
707
  _(42).must_respond_to :clear, "msg"
709
708
  end
710
709
  end
@@ -751,9 +750,9 @@ describe Minitest::Spec, :let do
751
750
  it "doesn't raise an error if it is just another let" do
752
751
  v = proc do
753
752
  describe :outer do
754
- let(:bar)
753
+ let :bar
755
754
  describe :inner do
756
- let(:bar)
755
+ let :bar
757
756
  end
758
757
  end
759
758
  :good
@@ -954,6 +953,23 @@ class TestMeta < MetaMetaMetaTestCase
954
953
  assert_equal "ExampleB::random_method", spec_b.name
955
954
  end
956
955
 
956
+ def test_name_inside_class
957
+ spec_a = nil
958
+ spec_b = nil
959
+ inside_class_example = Class.new Minitest::Spec
960
+ Object.const_set :InsideClassExample, inside_class_example
961
+ inside_class_example.class_eval do
962
+ spec_a = describe "a" do
963
+ spec_b = describe "b" do; end
964
+ end
965
+ end
966
+
967
+ assert_equal "InsideClassExample::a", spec_a.name
968
+ assert_equal "InsideClassExample::a::b", spec_b.name
969
+ ensure
970
+ Object.send :remove_const, :InsideClassExample
971
+ end
972
+
957
973
  def test_structure
958
974
  x, y, z, * = util_structure
959
975
 
@@ -1016,8 +1032,9 @@ class TestMeta < MetaMetaMetaTestCase
1016
1032
  z = describe "second thingy" do end
1017
1033
  end
1018
1034
 
1019
- test_methods = ["test_0001_top level it",
1020
- "test_0002_не латинские &いった α, β, γ, δ, ε hello!!! world",
1035
+ test_methods = [
1036
+ "test_0001_top level it",
1037
+ "test_0002_не латинские &いった α, β, γ, δ, ε hello!!! world",
1021
1038
  ].sort
1022
1039
 
1023
1040
  assert_equal test_methods, [x1, x2]