minitest 5.10.3 → 5.15.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.
@@ -64,8 +64,6 @@ class TestMinitestMock < Minitest::Test
64
64
  end
65
65
 
66
66
  def test_mock_args_does_not_raise
67
- skip "non-opaque use of ==" if maglev?
68
-
69
67
  arg = Minitest::Mock.new
70
68
  mock = Minitest::Mock.new
71
69
  mock.expect(:foo, nil, [arg])
@@ -135,7 +133,7 @@ class TestMinitestMock < Minitest::Test
135
133
  @mock.expect :blah, 3, false
136
134
  end
137
135
 
138
- assert_equal "args must be an array", e.message
136
+ assert_match "args must be an array", e.message
139
137
  end
140
138
 
141
139
  def test_respond_appropriately
@@ -152,7 +150,7 @@ class TestMinitestMock < Minitest::Test
152
150
 
153
151
  expected = "unmocked method :bar, expected one of [:foo, :meaning_of_life]"
154
152
 
155
- assert_equal expected, e.message
153
+ assert_match expected, e.message
156
154
  end
157
155
 
158
156
  def test_assign_per_mock_return_values
@@ -311,7 +309,7 @@ class TestMinitestMock < Minitest::Test
311
309
 
312
310
  exp = "args ignored when block given"
313
311
 
314
- assert_equal exp, e.message
312
+ assert_match exp, e.message
315
313
  end
316
314
 
317
315
  def test_mock_returns_retval_when_called_with_block
@@ -362,7 +360,7 @@ end
362
360
  require "minitest/metametameta"
363
361
 
364
362
  class TestMinitestStub < Minitest::Test
365
- parallelize_me!
363
+ # Do not parallelize since we're calling stub on class methods
366
364
 
367
365
  def setup
368
366
  super
@@ -374,7 +372,7 @@ class TestMinitestStub < Minitest::Test
374
372
 
375
373
  def teardown
376
374
  super
377
- assert_equal @assertion_count, @tc.assertions
375
+ assert_equal @assertion_count, @tc.assertions if self.passed?
378
376
  end
379
377
 
380
378
  class Time
@@ -494,6 +492,18 @@ class TestMinitestStub < Minitest::Test
494
492
  @tc.assert_equal false, dynamic.found
495
493
  end
496
494
 
495
+ def test_stub_NameError
496
+ e = @tc.assert_raises NameError do
497
+ Time.stub :nope_nope_nope, 42 do
498
+ # do nothing
499
+ end
500
+ end
501
+
502
+ exp = jruby? ? /Undefined method nope_nope_nope for '#{self.class}::Time'/ :
503
+ /undefined method `nope_nope_nope' for( class)? `#{self.class}::Time'/
504
+ assert_match exp, e.message
505
+ end
506
+
497
507
  def test_mock_with_yield
498
508
  mock = Minitest::Mock.new
499
509
  mock.expect(:write, true) do
@@ -509,4 +519,367 @@ class TestMinitestStub < Minitest::Test
509
519
  @tc.assert_equal true, rs
510
520
  end
511
521
 
522
+ alias test_stub_value__old test_stub_value # TODO: remove/rename
523
+
524
+ ## Permutation Sets:
525
+
526
+ # [:value, :lambda]
527
+ # [:*, :block, :block_call]
528
+ # [:**, :block_args]
529
+ #
530
+ # Where:
531
+ #
532
+ # :value = a normal value
533
+ # :lambda = callable or lambda
534
+ # :* = no block
535
+ # :block = normal block
536
+ # :block_call = :lambda invokes the block (N/A for :value)
537
+ # :** = no args
538
+ # :args = args passed to stub
539
+
540
+ ## Permutations
541
+
542
+ # [:call, :*, :**] =>5 callable+block FIX: CALL BOTH (bug)
543
+ # [:call, :*, :**] =>6 callable
544
+
545
+ # [:lambda, :*, :**] => lambda result
546
+
547
+ # [:lambda, :*, :args] => lambda result NO ARGS
548
+
549
+ # [:lambda, :block, :**] =>5 lambda result FIX: CALL BOTH (bug)
550
+ # [:lambda, :block, :**] =>6 lambda result
551
+
552
+ # [:lambda, :block, :args] =>5 lambda result FIX: CALL BOTH (bug)
553
+ # [:lambda, :block, :args] =>6 lambda result
554
+ # [:lambda, :block, :args] =>7 raise ArgumentError
555
+
556
+ # [:lambda, :block_call, :**] =>5 lambda FIX: BUG!-not passed block to lambda
557
+ # [:lambda, :block_call, :**] =>6 lambda+block result
558
+
559
+ # [:lambda, :block_call, :args] =>5 lambda FIX: BUG!-not passed block to lambda
560
+ # [:lambda, :block_call, :args] =>6 lambda+block result
561
+
562
+ # [:value, :*, :**] => value
563
+
564
+ # [:value, :*, :args] => value, ignore args
565
+
566
+ # [:value, :block, :**] =>5 value, call block
567
+ # [:value, :block, :**] =>6 value
568
+
569
+ # [:value, :block, :args] =>5 value, call block w/ args
570
+ # [:value, :block, :args] =>6 value, call block w/ args, deprecated
571
+ # [:value, :block, :args] =>7 raise ArgumentError
572
+
573
+ # [:value, :block_call, :**] => N/A
574
+
575
+ # [:value, :block_call, :args] => N/A
576
+
577
+ class Bar
578
+ def call
579
+ puts "hi"
580
+ end
581
+ end
582
+
583
+ class Foo
584
+ def self.blocking
585
+ yield
586
+ end
587
+ end
588
+
589
+ class Thingy
590
+ def self.identity arg
591
+ arg
592
+ end
593
+ end
594
+
595
+ class Keywords
596
+ def self.args req, kw1:, kw2:24
597
+ [req, kw1, kw2]
598
+ end
599
+ end
600
+
601
+ def test_stub_callable_keyword_args
602
+ Keywords.stub :args, ->(*args, **kws) { [args, kws] } do
603
+ @tc.assert_equal [["woot"], { kw1: 42 }], Keywords.args("woot", kw1: 42)
604
+ end
605
+ end
606
+
607
+ def test_stub_callable_block_5 # from tenderlove
608
+ @assertion_count += 1
609
+ Foo.stub5 :blocking, Bar.new do
610
+ @tc.assert_output "hi\n", "" do
611
+ Foo.blocking do
612
+ @tc.flunk "shouldn't ever hit this"
613
+ end
614
+ end
615
+ end
616
+ end
617
+
618
+ def test_stub_callable_block_6 # from tenderlove
619
+ skip_stub6
620
+
621
+ @assertion_count += 1
622
+ Foo.stub6 :blocking, Bar.new do
623
+ @tc.assert_output "hi\n", "" do
624
+ Foo.blocking do
625
+ @tc.flunk "shouldn't ever hit this"
626
+ end
627
+ end
628
+ end
629
+ end
630
+
631
+ def test_stub_lambda
632
+ Thread.stub :new, lambda { 21+21 } do
633
+ @tc.assert_equal 42, Thread.new
634
+ end
635
+ end
636
+
637
+ def test_stub_lambda_args
638
+ Thread.stub :new, lambda { 21+21 }, :wtf do
639
+ @tc.assert_equal 42, Thread.new
640
+ end
641
+ end
642
+
643
+ def test_stub_lambda_block_5
644
+ Thread.stub5 :new, lambda { 21+21 } do
645
+ result = Thread.new do
646
+ @tc.flunk "shouldn't ever hit this"
647
+ end
648
+ @tc.assert_equal 42, result
649
+ end
650
+ end
651
+
652
+ def test_stub_lambda_block_6
653
+ skip_stub6
654
+
655
+ Thread.stub6 :new, lambda { 21+21 } do
656
+ result = Thread.new do
657
+ @tc.flunk "shouldn't ever hit this"
658
+ end
659
+ @tc.assert_equal 42, result
660
+ end
661
+ end
662
+
663
+ def test_stub_lambda_block_args_5
664
+ @assertion_count += 1
665
+ Thingy.stub5 :identity, lambda { |y| @tc.assert_equal :nope, y; 21+21 }, :WTF? do
666
+ result = Thingy.identity :nope do |x|
667
+ @tc.flunk "shouldn't reach this"
668
+ end
669
+ @tc.assert_equal 42, result
670
+ end
671
+ end
672
+
673
+ def test_stub_lambda_block_args_6
674
+ skip_stub6
675
+
676
+ @assertion_count += 1
677
+ Thingy.stub6 :identity, lambda { |y| @tc.assert_equal :nope, y; 21+21 }, :WTF? do
678
+ result = Thingy.identity :nope do |x|
679
+ @tc.flunk "shouldn't reach this"
680
+ end
681
+ @tc.assert_equal 42, result
682
+ end
683
+ end
684
+
685
+ def test_stub_lambda_block_args_6_2
686
+ skip_stub6
687
+
688
+ @tc.assert_raises ArgumentError do
689
+ Thingy.stub6_2 :identity, lambda { |y| :__not_run__ }, :WTF? do
690
+ # doesn't matter
691
+ end
692
+ end
693
+ end
694
+
695
+ def test_stub_lambda_block_call_5
696
+ @assertion_count += 1
697
+ rs = nil
698
+ io = StringIO.new "", "w"
699
+ File.stub5 :open, lambda { |p, m, &blk| blk and blk.call io } do
700
+ File.open "foo.txt", "r" do |f|
701
+ rs = f && f.write("woot")
702
+ end
703
+ end
704
+ @tc.assert_equal 4, rs
705
+ @tc.assert_equal "woot", io.string
706
+ end
707
+
708
+ def test_stub_lambda_block_call_6
709
+ skip_stub6
710
+
711
+ @assertion_count += 1
712
+ rs = nil
713
+ io = StringIO.new "", "w"
714
+ File.stub6 :open, lambda { |p, m, &blk| blk.call io } do
715
+ File.open "foo.txt", "r" do |f|
716
+ rs = f.write("woot")
717
+ end
718
+ end
719
+ @tc.assert_equal 4, rs
720
+ @tc.assert_equal "woot", io.string
721
+ end
722
+
723
+ def test_stub_lambda_block_call_args_5
724
+ @assertion_count += 1
725
+ rs = nil
726
+ io = StringIO.new "", "w"
727
+ File.stub5(:open, lambda { |p, m, &blk| blk and blk.call io }, :WTF?) do
728
+ File.open "foo.txt", "r" do |f|
729
+ rs = f.write("woot")
730
+ end
731
+ end
732
+ @tc.assert_equal 4, rs
733
+ @tc.assert_equal "woot", io.string
734
+ end
735
+
736
+ def test_stub_lambda_block_call_args_6
737
+ skip_stub6
738
+
739
+ @assertion_count += 1
740
+ rs = nil
741
+ io = StringIO.new "", "w"
742
+ File.stub6(:open, lambda { |p, m, &blk| blk.call io }, :WTF?) do
743
+ File.open "foo.txt", "r" do |f|
744
+ rs = f.write("woot")
745
+ end
746
+ end
747
+ @tc.assert_equal 4, rs
748
+ @tc.assert_equal "woot", io.string
749
+ end
750
+
751
+ def test_stub_lambda_block_call_args_6_2
752
+ skip_stub6
753
+
754
+ @assertion_count += 2
755
+ rs = nil
756
+ io = StringIO.new "", "w"
757
+ @tc.assert_raises ArgumentError do
758
+ File.stub6_2(:open, lambda { |p, m, &blk| blk.call io }, :WTF?) do
759
+ File.open "foo.txt", "r" do |f|
760
+ rs = f.write("woot")
761
+ end
762
+ end
763
+ end
764
+ @tc.assert_nil rs
765
+ @tc.assert_equal "", io.string
766
+ end
767
+
768
+ def test_stub_value
769
+ Thread.stub :new, 42 do
770
+ result = Thread.new
771
+ @tc.assert_equal 42, result
772
+ end
773
+ end
774
+
775
+ def test_stub_value_args
776
+ Thread.stub :new, 42, :WTF? do
777
+ result = Thread.new
778
+ @tc.assert_equal 42, result
779
+ end
780
+ end
781
+
782
+ def test_stub_value_block_5
783
+ @assertion_count += 1
784
+ Thread.stub5 :new, 42 do
785
+ result = Thread.new do
786
+ @tc.assert true
787
+ end
788
+ @tc.assert_equal 42, result
789
+ end
790
+ end
791
+
792
+ def test_stub_value_block_6
793
+ skip_stub6
794
+
795
+ Thread.stub6 :new, 42 do
796
+ result = Thread.new do
797
+ @tc.flunk "shouldn't hit this"
798
+ end
799
+ @tc.assert_equal 42, result
800
+ end
801
+ end
802
+
803
+ def test_stub_value_block_args_5
804
+ @assertion_count += 2
805
+ rs = nil
806
+ io = StringIO.new "", "w"
807
+ File.stub5 :open, :value, io do
808
+ result = File.open "foo.txt", "r" do |f|
809
+ rs = f.write("woot")
810
+ end
811
+ @tc.assert_equal :value, result
812
+ end
813
+ @tc.assert_equal 4, rs
814
+ @tc.assert_equal "woot", io.string
815
+ end
816
+
817
+ def test_stub_value_block_args_5__break_if_not_passed
818
+ e = @tc.assert_raises NoMethodError do
819
+ File.stub5 :open, :return_value do # intentionally bad setup w/ no args
820
+ File.open "foo.txt", "r" do |f|
821
+ f.write "woot"
822
+ end
823
+ end
824
+ end
825
+ exp = "undefined method `write' for nil:NilClass"
826
+ assert_match exp, e.message
827
+ end
828
+
829
+ def test_stub_value_block_args_6
830
+ skip_stub6
831
+
832
+ @assertion_count += 2
833
+ rs = nil
834
+ io = StringIO.new "", "w"
835
+ assert_deprecated do
836
+ File.stub6 :open, :value, io do
837
+ result = File.open "foo.txt", "r" do |f|
838
+ rs = f.write("woot")
839
+ end
840
+ @tc.assert_equal :value, result
841
+ end
842
+ end
843
+ @tc.assert_equal 4, rs
844
+ @tc.assert_equal "woot", io.string
845
+ end
846
+
847
+ def test_stub_value_block_args_6_2
848
+ skip_stub6
849
+
850
+ @assertion_count += 2
851
+ rs = nil
852
+ io = StringIO.new "", "w"
853
+ @tc.assert_raises ArgumentError do
854
+ File.stub6_2 :open, :value, io do
855
+ result = File.open "foo.txt", "r" do |f|
856
+ @tc.flunk "shouldn't hit this"
857
+ end
858
+ @tc.assert_equal :value, result
859
+ end
860
+ end
861
+ @tc.assert_nil rs
862
+ @tc.assert_equal "", io.string
863
+ end
864
+
865
+ def assert_deprecated re = /deprecated/
866
+ assert_output "", re do
867
+ yield
868
+ end
869
+ end
870
+
871
+ def skip_stub6
872
+ skip "not yet" unless STUB6
873
+ end
874
+ end
875
+
876
+ STUB6 = ENV["STUB6"]
877
+
878
+ if STUB6 then
879
+ require "minitest/mock6" if STUB6
880
+ else
881
+ class Object
882
+ alias stub5 stub
883
+ alias stub6 stub
884
+ end
512
885
  end
@@ -1,30 +1,30 @@
1
1
  require "minitest/autorun"
2
2
  require "minitest/metametameta"
3
+ require "forwardable"
4
+
5
+ class Runnable
6
+ def woot
7
+ assert true
8
+ end
9
+ end
3
10
 
4
11
  class TestMinitestReporter < MetaMetaMetaTestCase
5
12
 
6
13
  attr_accessor :r, :io
7
14
 
8
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'
9
20
  reporter = Minitest::CompositeReporter.new
10
21
  reporter << Minitest::SummaryReporter.new(self.io)
11
22
  reporter << Minitest::ProgressReporter.new(self.io)
12
23
 
13
- def reporter.first
14
- reporters.first
15
- end
16
-
17
- def reporter.results
18
- first.results
19
- end
20
-
21
- def reporter.count
22
- first.count
23
- end
24
-
25
- def reporter.assertions
26
- first.assertions
27
- end
24
+ # eg reporter.results -> reporters.first.results
25
+ reporter.extend Forwardable
26
+ reporter.delegate :first => :reporters
27
+ reporter.delegate %i[results count assertions options to_s] => :first
28
28
 
29
29
  reporter
30
30
  end
@@ -42,6 +42,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
42
42
  rescue => e
43
43
  e
44
44
  end)
45
+ @et = Minitest::Result.from @et
45
46
  end
46
47
  @et
47
48
  end
@@ -54,12 +55,13 @@ class TestMinitestReporter < MetaMetaMetaTestCase
54
55
  rescue Minitest::Assertion => e
55
56
  e
56
57
  end
58
+ @ft = Minitest::Result.from @ft
57
59
  end
58
60
  @ft
59
61
  end
60
62
 
61
63
  def passing_test
62
- @pt ||= Minitest::Test.new(:woot)
64
+ @pt ||= Minitest::Result.from Minitest::Test.new(:woot)
63
65
  end
64
66
 
65
67
  def skip_test
@@ -70,6 +72,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
70
72
  rescue Minitest::Assertion => e
71
73
  e
72
74
  end
75
+ @st = Minitest::Result.from @st
73
76
  end
74
77
  @st
75
78
  end
@@ -77,17 +80,35 @@ class TestMinitestReporter < MetaMetaMetaTestCase
77
80
  def test_to_s
78
81
  r.record passing_test
79
82
  r.record fail_test
80
- assert_match "woot", r.first.to_s
83
+ assert_match "woot", r.to_s
84
+ end
85
+
86
+ def test_options_skip_F
87
+ r.options[:skip] = "F"
88
+
89
+ r.record passing_test
90
+ r.record fail_test
91
+
92
+ refute_match "woot", r.to_s
93
+ end
94
+
95
+ def test_options_skip_E
96
+ r.options[:skip] = "E"
97
+
98
+ r.record passing_test
99
+ r.record error_test
100
+
101
+ refute_match "RuntimeError: no", r.to_s
81
102
  end
82
103
 
83
104
  def test_passed_eh_empty
84
- assert r.passed?
105
+ assert_predicate r, :passed?
85
106
  end
86
107
 
87
108
  def test_passed_eh_failure
88
109
  r.results << fail_test
89
110
 
90
- refute r.passed?
111
+ refute_predicate r, :passed?
91
112
  end
92
113
 
93
114
  SKIP_MSG = "\n\nYou have skipped tests. Run with --verbose for details."
@@ -97,7 +118,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
97
118
 
98
119
  r.results << error_test
99
120
 
100
- refute r.passed?
121
+ refute_predicate r, :passed?
101
122
 
102
123
  r.report
103
124
 
@@ -117,7 +138,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
117
138
  end
118
139
 
119
140
  def test_passed_eh_skipped_verbose
120
- r.first.options[:verbose] = true
141
+ r.options[:verbose] = true
121
142
 
122
143
  r.start
123
144
  r.results << skip_test
@@ -145,6 +166,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
145
166
  end
146
167
 
147
168
  def test_record_fail
169
+ fail_test = self.fail_test
148
170
  r.record fail_test
149
171
 
150
172
  assert_equal "F", io.string
@@ -154,6 +176,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
154
176
  end
155
177
 
156
178
  def test_record_error
179
+ error_test = self.error_test
157
180
  r.record error_test
158
181
 
159
182
  assert_equal "E", io.string
@@ -163,6 +186,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
163
186
  end
164
187
 
165
188
  def test_record_skip
189
+ skip_test = self.skip_test
166
190
  r.record skip_test
167
191
 
168
192
  assert_equal "S", io.string