minitest 4.7.5 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/.autotest +1 -2
- data/History.txt +72 -21
- data/Manifest.txt +6 -0
- data/README.txt +57 -60
- data/design_rationale.rb +1 -1
- data/lib/hoe/minitest.rb +9 -5
- data/lib/minitest.rb +639 -0
- data/lib/minitest/assertions.rb +643 -0
- data/lib/minitest/autorun.rb +6 -6
- data/lib/minitest/benchmark.rb +92 -85
- data/lib/minitest/expectations.rb +268 -0
- data/lib/minitest/hell.rb +3 -5
- data/lib/minitest/mock.rb +3 -4
- data/lib/minitest/parallel_each.rb +59 -12
- data/lib/minitest/pride.rb +3 -111
- data/lib/minitest/pride_plugin.rb +143 -0
- data/lib/minitest/spec.rb +44 -312
- data/lib/minitest/test.rb +287 -0
- data/lib/minitest/unit.rb +33 -1407
- data/test/minitest/metametameta.rb +33 -30
- data/test/minitest/test_minitest_benchmark.rb +11 -9
- data/test/minitest/test_minitest_mock.rb +46 -48
- data/test/minitest/test_minitest_reporter.rb +245 -0
- data/test/minitest/test_minitest_spec.rb +46 -63
- data/test/minitest/test_minitest_unit.rb +213 -232
- metadata +12 -5
- metadata.gz.sig +0 -0
@@ -2,8 +2,8 @@
|
|
2
2
|
require "minitest/autorun"
|
3
3
|
require "stringio"
|
4
4
|
|
5
|
-
class MiniSpecA <
|
6
|
-
class MiniSpecB <
|
5
|
+
class MiniSpecA < Minitest::Spec; end
|
6
|
+
class MiniSpecB < Minitest::Test; extend Minitest::Spec::DSL; end
|
7
7
|
class MiniSpecC < MiniSpecB; end
|
8
8
|
class NamedExampleA < MiniSpecA; end
|
9
9
|
class NamedExampleB < MiniSpecB; end
|
@@ -11,10 +11,10 @@ class NamedExampleC < MiniSpecC; end
|
|
11
11
|
class ExampleA; end
|
12
12
|
class ExampleB < ExampleA; end
|
13
13
|
|
14
|
-
describe
|
14
|
+
describe Minitest::Spec do
|
15
15
|
# do not parallelize this suite... it just can"t handle it.
|
16
16
|
|
17
|
-
def assert_triggered expected = "blah", klass =
|
17
|
+
def assert_triggered expected = "blah", klass = Minitest::Assertion
|
18
18
|
@assertion_count += 2
|
19
19
|
|
20
20
|
e = assert_raises(klass) do
|
@@ -32,10 +32,10 @@ describe MiniTest::Spec do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
after do
|
35
|
-
self.
|
35
|
+
self.assertions.must_equal @assertion_count if passed? and not skipped?
|
36
36
|
end
|
37
37
|
|
38
|
-
it "needs to be able to catch a
|
38
|
+
it "needs to be able to catch a Minitest::Assertion exception" do
|
39
39
|
@assertion_count = 1
|
40
40
|
|
41
41
|
assert_triggered "Expected 1 to not be equal to 1." do
|
@@ -75,7 +75,7 @@ describe MiniTest::Spec do
|
|
75
75
|
@assertion_count = 2
|
76
76
|
|
77
77
|
proc { raise "blah" }.must_raise RuntimeError
|
78
|
-
proc { raise
|
78
|
+
proc { raise Minitest::Assertion }.must_raise Minitest::Assertion
|
79
79
|
end
|
80
80
|
|
81
81
|
it "needs to catch an unexpected exception" do
|
@@ -83,17 +83,17 @@ describe MiniTest::Spec do
|
|
83
83
|
|
84
84
|
msg = <<-EOM.gsub(/^ {6}/, "").chomp
|
85
85
|
[RuntimeError] exception expected, not
|
86
|
-
Class: <
|
87
|
-
Message: <"
|
86
|
+
Class: <Minitest::Assertion>
|
87
|
+
Message: <"Minitest::Assertion">
|
88
88
|
---Backtrace---
|
89
89
|
EOM
|
90
90
|
|
91
91
|
assert_triggered msg do
|
92
|
-
proc { raise
|
92
|
+
proc { raise Minitest::Assertion }.must_raise RuntimeError
|
93
93
|
end
|
94
94
|
|
95
95
|
assert_triggered "msg.\n#{msg}" do
|
96
|
-
proc { raise
|
96
|
+
proc { raise Minitest::Assertion }.must_raise RuntimeError, "msg"
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
@@ -132,7 +132,6 @@ describe MiniTest::Spec do
|
|
132
132
|
must_output
|
133
133
|
must_raise
|
134
134
|
must_respond_to
|
135
|
-
must_send
|
136
135
|
must_throw)
|
137
136
|
|
138
137
|
bad = %w[not raise throw send output be_silent]
|
@@ -523,7 +522,7 @@ describe MiniTest::Spec do
|
|
523
522
|
|
524
523
|
end
|
525
524
|
|
526
|
-
describe
|
525
|
+
describe Minitest::Spec, :let do
|
527
526
|
i_suck_and_my_tests_are_order_dependent!
|
528
527
|
|
529
528
|
def _count
|
@@ -554,7 +553,7 @@ describe MiniTest::Spec, :let do
|
|
554
553
|
end
|
555
554
|
end
|
556
555
|
|
557
|
-
describe
|
556
|
+
describe Minitest::Spec, :subject do
|
558
557
|
attr_reader :subject_evaluation_count
|
559
558
|
|
560
559
|
subject do
|
@@ -570,9 +569,9 @@ describe MiniTest::Spec, :subject do
|
|
570
569
|
end
|
571
570
|
end
|
572
571
|
|
573
|
-
class TestMetaStatic <
|
572
|
+
class TestMetaStatic < Minitest::Test
|
574
573
|
def test_children
|
575
|
-
|
574
|
+
Minitest::Spec.children.clear # prevents parallel run
|
576
575
|
|
577
576
|
x = y = z = nil
|
578
577
|
x = describe "top-level thingy" do
|
@@ -583,14 +582,16 @@ class TestMetaStatic < MiniTest::Unit::TestCase
|
|
583
582
|
z = describe "second thingy" do end
|
584
583
|
end
|
585
584
|
|
586
|
-
assert_equal [x],
|
585
|
+
assert_equal [x], Minitest::Spec.children
|
587
586
|
assert_equal [y, z], x.children
|
588
587
|
assert_equal [], y.children
|
589
588
|
assert_equal [], z.children
|
590
589
|
end
|
591
590
|
end
|
592
591
|
|
593
|
-
|
592
|
+
require "minitest/metametameta"
|
593
|
+
|
594
|
+
class TestMeta < MetaMetaMetaTestCase
|
594
595
|
parallelize_me!
|
595
596
|
|
596
597
|
def util_structure
|
@@ -623,35 +624,35 @@ class TestMeta < MiniTest::Unit::TestCase
|
|
623
624
|
end
|
624
625
|
|
625
626
|
def test_register_spec_type
|
626
|
-
original_types =
|
627
|
+
original_types = Minitest::Spec::TYPES.dup
|
627
628
|
|
628
|
-
|
629
|
+
assert_includes Minitest::Spec::TYPES, [//, Minitest::Spec]
|
629
630
|
|
630
|
-
|
631
|
+
Minitest::Spec.register_spec_type(/woot/, TestMeta)
|
631
632
|
|
632
633
|
p = lambda do |x| true end
|
633
|
-
|
634
|
+
Minitest::Spec.register_spec_type TestMeta, &p
|
634
635
|
|
635
|
-
keys =
|
636
|
+
keys = Minitest::Spec::TYPES.map(&:first)
|
636
637
|
|
637
638
|
assert_includes keys, /woot/
|
638
639
|
assert_includes keys, p
|
639
640
|
ensure
|
640
|
-
|
641
|
+
Minitest::Spec::TYPES.replace original_types
|
641
642
|
end
|
642
643
|
|
643
644
|
def test_spec_type
|
644
|
-
original_types =
|
645
|
+
original_types = Minitest::Spec::TYPES.dup
|
645
646
|
|
646
|
-
|
647
|
-
|
647
|
+
Minitest::Spec.register_spec_type(/A$/, MiniSpecA)
|
648
|
+
Minitest::Spec.register_spec_type MiniSpecB do |desc|
|
648
649
|
desc.superclass == ExampleA
|
649
650
|
end
|
650
651
|
|
651
|
-
assert_equal MiniSpecA,
|
652
|
-
assert_equal MiniSpecB,
|
652
|
+
assert_equal MiniSpecA, Minitest::Spec.spec_type(ExampleA)
|
653
|
+
assert_equal MiniSpecB, Minitest::Spec.spec_type(ExampleB)
|
653
654
|
ensure
|
654
|
-
|
655
|
+
Minitest::Spec::TYPES.replace original_types
|
655
656
|
end
|
656
657
|
|
657
658
|
def test_name
|
@@ -698,16 +699,13 @@ class TestMeta < MiniTest::Unit::TestCase
|
|
698
699
|
def test_setup_teardown_behavior
|
699
700
|
_, _, z, before_list, after_list = util_structure
|
700
701
|
|
701
|
-
@tu =
|
702
|
-
MiniTest::Unit.runner = nil # protect the outer runner from the inner tests
|
702
|
+
@tu = z
|
703
703
|
|
704
|
-
|
705
|
-
tc = z.new :test_0002_anonymous
|
706
|
-
tc.run @tu
|
707
|
-
end
|
704
|
+
run_tu_with_fresh_reporter
|
708
705
|
|
709
|
-
|
710
|
-
assert_equal [
|
706
|
+
size = z.runnable_methods.size
|
707
|
+
assert_equal [1, 2, 3] * size, before_list
|
708
|
+
assert_equal [3, 2, 1] * size, after_list
|
711
709
|
end
|
712
710
|
|
713
711
|
def test_describe_first_structure
|
@@ -732,7 +730,7 @@ class TestMeta < MiniTest::Unit::TestCase
|
|
732
730
|
|
733
731
|
def test_structure_subclasses
|
734
732
|
z = nil
|
735
|
-
x = Class.new
|
733
|
+
x = Class.new Minitest::Spec do
|
736
734
|
def xyz; end
|
737
735
|
end
|
738
736
|
y = Class.new x do
|
@@ -743,32 +741,19 @@ class TestMeta < MiniTest::Unit::TestCase
|
|
743
741
|
assert_respond_to y.new(nil), "xyz"
|
744
742
|
assert_respond_to z.new(nil), "xyz"
|
745
743
|
end
|
746
|
-
|
747
|
-
def with_output # REFACTOR: dupe from metametameta
|
748
|
-
synchronize do
|
749
|
-
begin
|
750
|
-
@output = StringIO.new("")
|
751
|
-
MiniTest::Unit.output = @output
|
752
|
-
|
753
|
-
yield
|
754
|
-
ensure
|
755
|
-
MiniTest::Unit.output = STDOUT
|
756
|
-
end
|
757
|
-
end
|
758
|
-
end
|
759
744
|
end
|
760
745
|
|
761
|
-
require "minitest/metametameta"
|
762
|
-
|
763
746
|
class TestSpecInTestCase < MetaMetaMetaTestCase
|
764
747
|
def setup
|
765
748
|
super
|
766
749
|
|
767
|
-
@tc =
|
750
|
+
@tc = self
|
768
751
|
@assertion_count = 1
|
769
752
|
end
|
770
753
|
|
771
|
-
def
|
754
|
+
def assert_triggered expected, klass = Minitest::Assertion
|
755
|
+
@assertion_count += 1
|
756
|
+
|
772
757
|
e = assert_raises klass do
|
773
758
|
yield
|
774
759
|
end
|
@@ -779,25 +764,23 @@ class TestSpecInTestCase < MetaMetaMetaTestCase
|
|
779
764
|
assert_equal expected, msg
|
780
765
|
end
|
781
766
|
|
782
|
-
def teardown
|
783
|
-
|
784
|
-
|
767
|
+
def teardown
|
768
|
+
msg = "expected #{@assertion_count} assertions, not #{@tc.assertions}"
|
769
|
+
assert_equal @assertion_count, @tc.assertions, msg
|
785
770
|
end
|
786
771
|
|
787
772
|
def test_expectation
|
788
|
-
@assertion_count = 2
|
789
|
-
|
790
773
|
@tc.assert_equal true, 1.must_equal(1)
|
791
774
|
end
|
792
775
|
|
793
776
|
def test_expectation_triggered
|
794
|
-
|
777
|
+
assert_triggered "Expected: 2\n Actual: 1" do
|
795
778
|
1.must_equal 2
|
796
779
|
end
|
797
780
|
end
|
798
781
|
|
799
782
|
def test_expectation_with_a_message
|
800
|
-
|
783
|
+
assert_triggered "Expected: 2\n Actual: 1" do
|
801
784
|
1.must_equal 2, ""
|
802
785
|
end
|
803
786
|
end
|
@@ -5,7 +5,7 @@ module MyModule; end
|
|
5
5
|
class AnError < StandardError; include MyModule; end
|
6
6
|
class ImmutableString < String; def inspect; super.freeze; end; end
|
7
7
|
|
8
|
-
class
|
8
|
+
class TestMinitestUnit < MetaMetaMetaTestCase
|
9
9
|
parallelize_me!
|
10
10
|
|
11
11
|
pwd = Pathname.new File.expand_path Dir.pwd
|
@@ -17,98 +17,6 @@ class TestMiniTestUnit < MetaMetaMetaTestCase
|
|
17
17
|
"#{MINITEST_BASE_DIR}/test.rb:139:in `run'",
|
18
18
|
"#{MINITEST_BASE_DIR}/test.rb:106:in `run'"]
|
19
19
|
|
20
|
-
def test_class_puke_with_assertion_failed
|
21
|
-
exception = MiniTest::Assertion.new "Oh no!"
|
22
|
-
exception.set_backtrace ["unhappy"]
|
23
|
-
assert_equal 'F', @tu.puke('SomeClass', 'method_name', exception)
|
24
|
-
assert_equal 1, @tu.failures
|
25
|
-
assert_match(/^Failure.*Oh no!/m, @tu.report.first)
|
26
|
-
assert_match("SomeClass#method_name [unhappy]", @tu.report.first)
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_class_puke_with_assertion_failed_and_long_backtrace
|
30
|
-
bt = (["test/test_some_class.rb:615:in `method_name'",
|
31
|
-
"#{MINITEST_BASE_DIR}/unit.rb:140:in `assert_raises'",
|
32
|
-
"test/test_some_class.rb:615:in `each'",
|
33
|
-
"test/test_some_class.rb:614:in `test_method_name'",
|
34
|
-
"#{MINITEST_BASE_DIR}/test.rb:165:in `__send__'"] +
|
35
|
-
BT_MIDDLE +
|
36
|
-
["#{MINITEST_BASE_DIR}/test.rb:29"])
|
37
|
-
bt = util_expand_bt bt
|
38
|
-
|
39
|
-
ex_location = util_expand_bt(["test/test_some_class.rb:615"]).first
|
40
|
-
|
41
|
-
exception = MiniTest::Assertion.new "Oh no!"
|
42
|
-
exception.set_backtrace bt
|
43
|
-
assert_equal 'F', @tu.puke('TestSomeClass', 'test_method_name', exception)
|
44
|
-
assert_equal 1, @tu.failures
|
45
|
-
assert_match(/^Failure.*Oh no!/m, @tu.report.first)
|
46
|
-
assert_match("TestSomeClass#test_method_name [#{ex_location}]", @tu.report.first)
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_class_puke_with_assertion_failed_and_user_defined_assertions
|
50
|
-
bt = (["lib/test/my/util.rb:16:in `another_method_name'",
|
51
|
-
"#{MINITEST_BASE_DIR}/unit.rb:140:in `assert_raises'",
|
52
|
-
"lib/test/my/util.rb:15:in `block in assert_something'",
|
53
|
-
"lib/test/my/util.rb:14:in `each'",
|
54
|
-
"lib/test/my/util.rb:14:in `assert_something'",
|
55
|
-
"test/test_some_class.rb:615:in `each'",
|
56
|
-
"test/test_some_class.rb:614:in `test_method_name'",
|
57
|
-
"#{MINITEST_BASE_DIR}/test.rb:165:in `__send__'"] +
|
58
|
-
BT_MIDDLE +
|
59
|
-
["#{MINITEST_BASE_DIR}/test.rb:29"])
|
60
|
-
bt = util_expand_bt bt
|
61
|
-
|
62
|
-
ex_location = util_expand_bt(["test/test_some_class.rb:615"]).first
|
63
|
-
|
64
|
-
exception = MiniTest::Assertion.new "Oh no!"
|
65
|
-
exception.set_backtrace bt
|
66
|
-
assert_equal 'F', @tu.puke('TestSomeClass', 'test_method_name', exception)
|
67
|
-
assert_equal 1, @tu.failures
|
68
|
-
assert_match(/^Failure.*Oh no!/m, @tu.report.first)
|
69
|
-
assert_match("TestSomeClass#test_method_name [#{ex_location}]", @tu.report.first)
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_class_puke_with_failure_and_flunk_in_backtrace
|
73
|
-
exception = begin
|
74
|
-
MiniTest::Unit::TestCase.new('fake tc').flunk
|
75
|
-
rescue MiniTest::Assertion => failure
|
76
|
-
failure
|
77
|
-
end
|
78
|
-
assert_equal 'F', @tu.puke('SomeClass', 'method_name', exception)
|
79
|
-
refute @tu.report.any?{|line| line =~ /in .flunk/}
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_class_puke_with_flunk_and_user_defined_assertions
|
83
|
-
bt = (["lib/test/my/util.rb:16:in `flunk'",
|
84
|
-
"#{MINITEST_BASE_DIR}/unit.rb:140:in `assert_raises'",
|
85
|
-
"lib/test/my/util.rb:15:in `block in assert_something'",
|
86
|
-
"lib/test/my/util.rb:14:in `each'",
|
87
|
-
"lib/test/my/util.rb:14:in `assert_something'",
|
88
|
-
"test/test_some_class.rb:615:in `each'",
|
89
|
-
"test/test_some_class.rb:614:in `test_method_name'",
|
90
|
-
"#{MINITEST_BASE_DIR}/test.rb:165:in `__send__'"] +
|
91
|
-
BT_MIDDLE +
|
92
|
-
["#{MINITEST_BASE_DIR}/test.rb:29"])
|
93
|
-
bt = util_expand_bt bt
|
94
|
-
|
95
|
-
ex_location = util_expand_bt(["test/test_some_class.rb:615"]).first
|
96
|
-
|
97
|
-
exception = MiniTest::Assertion.new "Oh no!"
|
98
|
-
exception.set_backtrace bt
|
99
|
-
assert_equal 'F', @tu.puke('TestSomeClass', 'test_method_name', exception)
|
100
|
-
assert_equal 1, @tu.failures
|
101
|
-
assert_match(/^Failure.*Oh no!/m, @tu.report.first)
|
102
|
-
assert_match("TestSomeClass#test_method_name [#{ex_location}]", @tu.report.first)
|
103
|
-
end
|
104
|
-
|
105
|
-
def test_class_puke_with_non_failure_exception
|
106
|
-
exception = Exception.new("Oh no again!")
|
107
|
-
assert_equal 'E', @tu.puke('SomeClass', 'method_name', exception)
|
108
|
-
assert_equal 1, @tu.errors
|
109
|
-
assert_match(/^Exception.*Oh no again!/m, @tu.report.first)
|
110
|
-
end
|
111
|
-
|
112
20
|
def test_filter_backtrace
|
113
21
|
# this is a semi-lame mix of relative paths.
|
114
22
|
# I cheated by making the autotest parts not have ./
|
@@ -124,7 +32,7 @@ class TestMiniTestUnit < MetaMetaMetaTestCase
|
|
124
32
|
"test/test_autotest.rb:62:in `test_add_exception'"]
|
125
33
|
ex = util_expand_bt ex
|
126
34
|
|
127
|
-
fu =
|
35
|
+
fu = Minitest::filter_backtrace(bt)
|
128
36
|
|
129
37
|
assert_equal ex, fu
|
130
38
|
end
|
@@ -134,7 +42,7 @@ class TestMiniTestUnit < MetaMetaMetaTestCase
|
|
134
42
|
BT_MIDDLE +
|
135
43
|
["#{MINITEST_BASE_DIR}/test.rb:29"])
|
136
44
|
ex = bt.clone
|
137
|
-
fu =
|
45
|
+
fu = Minitest::filter_backtrace(bt)
|
138
46
|
assert_equal ex, fu
|
139
47
|
end
|
140
48
|
|
@@ -147,45 +55,46 @@ class TestMiniTestUnit < MetaMetaMetaTestCase
|
|
147
55
|
bt = util_expand_bt bt
|
148
56
|
|
149
57
|
ex = ["-e:1"]
|
150
|
-
fu =
|
58
|
+
fu = Minitest::filter_backtrace bt
|
151
59
|
assert_equal ex, fu
|
152
60
|
end
|
153
61
|
|
154
|
-
def test_default_runner_is_minitest_unit
|
155
|
-
|
156
|
-
end
|
157
|
-
|
62
|
+
# def test_default_runner_is_minitest_unit
|
63
|
+
# assert_instance_of Minitest::Unit, Minitest::Unit.runner
|
64
|
+
# end
|
158
65
|
|
159
66
|
def test_passed_eh_teardown_good
|
160
|
-
test_class = Class.new
|
67
|
+
test_class = Class.new Minitest::Test do
|
161
68
|
def teardown; assert true; end
|
162
69
|
def test_omg; assert true; end
|
163
70
|
end
|
164
71
|
|
165
72
|
test = test_class.new :test_omg
|
166
|
-
test.run
|
73
|
+
test.run
|
167
74
|
assert test.passed?
|
168
75
|
end
|
169
76
|
|
170
77
|
def test_passed_eh_teardown_skipped
|
171
|
-
test_class = Class.new
|
78
|
+
test_class = Class.new Minitest::Test do
|
172
79
|
def teardown; assert true; end
|
173
80
|
def test_omg; skip "bork"; end
|
174
81
|
end
|
175
82
|
|
176
83
|
test = test_class.new :test_omg
|
177
|
-
test.run
|
178
|
-
|
84
|
+
test.run
|
85
|
+
|
86
|
+
assert test.skipped?
|
87
|
+
refute test.passed?
|
179
88
|
end
|
180
89
|
|
181
90
|
def test_passed_eh_teardown_flunked
|
182
|
-
test_class = Class.new
|
91
|
+
test_class = Class.new Minitest::Test do
|
183
92
|
def teardown; flunk; end
|
184
93
|
def test_omg; assert true; end
|
185
94
|
end
|
186
95
|
|
187
96
|
test = test_class.new :test_omg
|
188
|
-
test.run
|
97
|
+
test.run
|
189
98
|
refute test.passed?
|
190
99
|
end
|
191
100
|
|
@@ -198,7 +107,7 @@ class TestMiniTestUnit < MetaMetaMetaTestCase
|
|
198
107
|
end
|
199
108
|
end
|
200
109
|
|
201
|
-
class
|
110
|
+
class TestMinitestUnitInherited < MetaMetaMetaTestCase
|
202
111
|
def with_overridden_include
|
203
112
|
Class.class_eval do
|
204
113
|
def inherited_with_hacks klass
|
@@ -226,32 +135,35 @@ class TestMiniTestUnitInherited < MetaMetaMetaTestCase
|
|
226
135
|
def test_inherited_hook_plays_nice_with_others
|
227
136
|
with_overridden_include do
|
228
137
|
assert_throws :inherited_hook do
|
229
|
-
Class.new
|
138
|
+
Class.new Minitest::Test
|
230
139
|
end
|
231
140
|
end
|
232
141
|
end
|
233
142
|
end
|
234
143
|
|
235
|
-
class
|
144
|
+
class TestMinitestRunner < MetaMetaMetaTestCase
|
236
145
|
# do not parallelize this suite... it just can't handle it.
|
237
146
|
|
238
|
-
def
|
147
|
+
def test_class_runnables
|
239
148
|
@assertion_count = 0
|
240
149
|
|
241
|
-
tc = Class.new(
|
150
|
+
tc = Class.new(Minitest::Test)
|
242
151
|
|
243
|
-
assert_equal 1,
|
244
|
-
assert_equal [tc],
|
152
|
+
assert_equal 1, Minitest::Test.runnables.size
|
153
|
+
assert_equal [tc], Minitest::Test.runnables
|
245
154
|
end
|
246
155
|
|
247
156
|
def test_run_test
|
248
|
-
|
157
|
+
@tu =
|
158
|
+
Class.new Minitest::Test do
|
249
159
|
attr_reader :foo
|
250
160
|
|
251
|
-
def
|
161
|
+
def run
|
252
162
|
@foo = "hi mom!"
|
253
163
|
super
|
254
164
|
@foo = "okay"
|
165
|
+
|
166
|
+
self # per contract
|
255
167
|
end
|
256
168
|
|
257
169
|
def test_something
|
@@ -262,16 +174,17 @@ class TestMiniTestRunner < MetaMetaMetaTestCase
|
|
262
174
|
expected = clean <<-EOM
|
263
175
|
.
|
264
176
|
|
265
|
-
Finished
|
177
|
+
Finished in 0.00
|
266
178
|
|
267
|
-
1
|
179
|
+
1 runs, 1 assertions, 0 failures, 0 errors, 0 skips
|
268
180
|
EOM
|
269
181
|
|
270
182
|
assert_report expected
|
271
183
|
end
|
272
184
|
|
273
185
|
def test_run_error
|
274
|
-
|
186
|
+
@tu =
|
187
|
+
Class.new Minitest::Test do
|
275
188
|
def test_something
|
276
189
|
assert true
|
277
190
|
end
|
@@ -284,21 +197,22 @@ class TestMiniTestRunner < MetaMetaMetaTestCase
|
|
284
197
|
expected = clean <<-EOM
|
285
198
|
E.
|
286
199
|
|
287
|
-
Finished
|
200
|
+
Finished in 0.00
|
288
201
|
|
289
202
|
1) Error:
|
290
203
|
#<Class:0xXXX>#test_error:
|
291
204
|
RuntimeError: unhandled exception
|
292
205
|
FILE:LINE:in \`test_error\'
|
293
206
|
|
294
|
-
2
|
207
|
+
2 runs, 1 assertions, 0 failures, 1 errors, 0 skips
|
295
208
|
EOM
|
296
209
|
|
297
210
|
assert_report expected
|
298
211
|
end
|
299
212
|
|
300
213
|
def test_run_error_teardown
|
301
|
-
|
214
|
+
@tu =
|
215
|
+
Class.new Minitest::Test do
|
302
216
|
def test_something
|
303
217
|
assert true
|
304
218
|
end
|
@@ -311,21 +225,22 @@ class TestMiniTestRunner < MetaMetaMetaTestCase
|
|
311
225
|
expected = clean <<-EOM
|
312
226
|
E
|
313
227
|
|
314
|
-
Finished
|
228
|
+
Finished in 0.00
|
315
229
|
|
316
230
|
1) Error:
|
317
231
|
#<Class:0xXXX>#test_something:
|
318
232
|
RuntimeError: unhandled exception
|
319
233
|
FILE:LINE:in \`teardown\'
|
320
234
|
|
321
|
-
1
|
235
|
+
1 runs, 1 assertions, 0 failures, 1 errors, 0 skips
|
322
236
|
EOM
|
323
237
|
|
324
238
|
assert_report expected
|
325
239
|
end
|
326
240
|
|
327
241
|
def test_run_failing
|
328
|
-
|
242
|
+
@tu =
|
243
|
+
Class.new Minitest::Test do
|
329
244
|
def test_something
|
330
245
|
assert true
|
331
246
|
end
|
@@ -338,20 +253,21 @@ class TestMiniTestRunner < MetaMetaMetaTestCase
|
|
338
253
|
expected = clean <<-EOM
|
339
254
|
F.
|
340
255
|
|
341
|
-
Finished
|
256
|
+
Finished in 0.00
|
342
257
|
|
343
258
|
1) Failure:
|
344
259
|
#<Class:0xXXX>#test_failure [FILE:LINE]:
|
345
260
|
Failed assertion, no message given.
|
346
261
|
|
347
|
-
2
|
262
|
+
2 runs, 2 assertions, 1 failures, 0 errors, 0 skips
|
348
263
|
EOM
|
349
264
|
|
350
265
|
assert_report expected
|
351
266
|
end
|
352
267
|
|
353
268
|
def test_run_failing_filtered
|
354
|
-
|
269
|
+
@tu =
|
270
|
+
Class.new Minitest::Test do
|
355
271
|
def test_something
|
356
272
|
assert true
|
357
273
|
end
|
@@ -364,9 +280,9 @@ class TestMiniTestRunner < MetaMetaMetaTestCase
|
|
364
280
|
expected = clean <<-EOM
|
365
281
|
.
|
366
282
|
|
367
|
-
Finished
|
283
|
+
Finished in 0.00
|
368
284
|
|
369
|
-
1
|
285
|
+
1 runs, 1 assertions, 0 failures, 0 errors, 0 skips
|
370
286
|
EOM
|
371
287
|
|
372
288
|
assert_report expected, %w[--name /some|thing/ --seed 42]
|
@@ -375,20 +291,22 @@ class TestMiniTestRunner < MetaMetaMetaTestCase
|
|
375
291
|
def assert_filtering name, expected, a = false
|
376
292
|
args = %W[--name #{name} --seed 42]
|
377
293
|
|
378
|
-
alpha = Class.new
|
294
|
+
alpha = Class.new Minitest::Test do
|
379
295
|
define_method :test_something do
|
380
296
|
assert a
|
381
297
|
end
|
382
298
|
end
|
383
299
|
Object.const_set(:Alpha, alpha)
|
384
300
|
|
385
|
-
beta = Class.new
|
301
|
+
beta = Class.new Minitest::Test do
|
386
302
|
define_method :test_something do
|
387
303
|
assert true
|
388
304
|
end
|
389
305
|
end
|
390
306
|
Object.const_set(:Beta, beta)
|
391
307
|
|
308
|
+
@tus = [alpha, beta]
|
309
|
+
|
392
310
|
assert_report expected, args
|
393
311
|
ensure
|
394
312
|
Object.send :remove_const, :Alpha
|
@@ -399,9 +317,9 @@ class TestMiniTestRunner < MetaMetaMetaTestCase
|
|
399
317
|
expected = clean <<-EOM
|
400
318
|
.
|
401
319
|
|
402
|
-
Finished
|
320
|
+
Finished in 0.00
|
403
321
|
|
404
|
-
1
|
322
|
+
1 runs, 1 assertions, 0 failures, 0 errors, 0 skips
|
405
323
|
EOM
|
406
324
|
|
407
325
|
assert_filtering "/Beta#test_something/", expected
|
@@ -411,9 +329,9 @@ class TestMiniTestRunner < MetaMetaMetaTestCase
|
|
411
329
|
expected = clean <<-EOM
|
412
330
|
.
|
413
331
|
|
414
|
-
Finished
|
332
|
+
Finished in 0.00
|
415
333
|
|
416
|
-
1
|
334
|
+
1 runs, 1 assertions, 0 failures, 0 errors, 0 skips
|
417
335
|
EOM
|
418
336
|
|
419
337
|
assert_filtering "Beta#test_something", expected
|
@@ -423,16 +341,17 @@ class TestMiniTestRunner < MetaMetaMetaTestCase
|
|
423
341
|
expected = clean <<-EOM
|
424
342
|
..
|
425
343
|
|
426
|
-
Finished
|
344
|
+
Finished in 0.00
|
427
345
|
|
428
|
-
2
|
346
|
+
2 runs, 2 assertions, 0 failures, 0 errors, 0 skips
|
429
347
|
EOM
|
430
348
|
|
431
349
|
assert_filtering "test_something", expected, :pass
|
432
350
|
end
|
433
351
|
|
434
352
|
def test_run_passing
|
435
|
-
|
353
|
+
@tu =
|
354
|
+
Class.new Minitest::Test do
|
436
355
|
def test_something
|
437
356
|
assert true
|
438
357
|
end
|
@@ -441,16 +360,17 @@ class TestMiniTestRunner < MetaMetaMetaTestCase
|
|
441
360
|
expected = clean <<-EOM
|
442
361
|
.
|
443
362
|
|
444
|
-
Finished
|
363
|
+
Finished in 0.00
|
445
364
|
|
446
|
-
1
|
365
|
+
1 runs, 1 assertions, 0 failures, 0 errors, 0 skips
|
447
366
|
EOM
|
448
367
|
|
449
368
|
assert_report expected
|
450
369
|
end
|
451
370
|
|
452
371
|
def test_run_skip
|
453
|
-
|
372
|
+
@tu =
|
373
|
+
Class.new Minitest::Test do
|
454
374
|
def test_something
|
455
375
|
assert true
|
456
376
|
end
|
@@ -463,16 +383,17 @@ class TestMiniTestRunner < MetaMetaMetaTestCase
|
|
463
383
|
expected = clean <<-EOM
|
464
384
|
S.
|
465
385
|
|
466
|
-
Finished
|
386
|
+
Finished in 0.00
|
467
387
|
|
468
|
-
2
|
388
|
+
2 runs, 1 assertions, 0 failures, 0 errors, 1 skips
|
469
389
|
EOM
|
470
390
|
|
471
391
|
assert_report expected
|
472
392
|
end
|
473
393
|
|
474
394
|
def test_run_skip_verbose
|
475
|
-
|
395
|
+
@tu =
|
396
|
+
Class.new Minitest::Test do
|
476
397
|
def test_something
|
477
398
|
assert true
|
478
399
|
end
|
@@ -487,31 +408,31 @@ class TestMiniTestRunner < MetaMetaMetaTestCase
|
|
487
408
|
#<Class:0xXXX>#test_something = 0.00 s = .
|
488
409
|
|
489
410
|
|
490
|
-
Finished
|
411
|
+
Finished in 0.00
|
491
412
|
|
492
413
|
1) Skipped:
|
493
414
|
#<Class:0xXXX>#test_skip [FILE:LINE]:
|
494
415
|
not yet
|
495
416
|
|
496
|
-
2
|
417
|
+
2 runs, 1 assertions, 0 failures, 0 errors, 1 skips
|
497
418
|
EOM
|
498
419
|
|
499
420
|
assert_report expected, %w[--seed 42 --verbose]
|
500
421
|
end
|
501
422
|
|
502
423
|
def test_run_with_other_runner
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
424
|
+
@tu =
|
425
|
+
Class.new Minitest::Test do
|
426
|
+
def self.run reporter, options = {}
|
427
|
+
@reporter = reporter
|
428
|
+
before_my_suite
|
429
|
+
super
|
507
430
|
end
|
508
|
-
end.new
|
509
431
|
|
510
|
-
Class.new MiniTest::Unit::TestCase do
|
511
432
|
def self.name; "wacky!" end
|
512
433
|
|
513
|
-
def self.
|
514
|
-
|
434
|
+
def self.before_my_suite
|
435
|
+
@reporter.io.puts "Running #{self.name} tests"
|
515
436
|
@@foo = 1
|
516
437
|
end
|
517
438
|
|
@@ -528,9 +449,9 @@ class TestMiniTestRunner < MetaMetaMetaTestCase
|
|
528
449
|
Running wacky! tests
|
529
450
|
..
|
530
451
|
|
531
|
-
Finished
|
452
|
+
Finished in 0.00
|
532
453
|
|
533
|
-
2
|
454
|
+
2 runs, 2 assertions, 0 failures, 0 errors, 0 skips
|
534
455
|
EOM
|
535
456
|
|
536
457
|
assert_report expected
|
@@ -558,7 +479,7 @@ class TestMiniTestRunner < MetaMetaMetaTestCase
|
|
558
479
|
end
|
559
480
|
|
560
481
|
def test_parallel_each_size
|
561
|
-
assert_equal 0, ParallelEach.new([]).size
|
482
|
+
assert_equal 0, Minitest::ParallelEach.new([]).size
|
562
483
|
end
|
563
484
|
|
564
485
|
def test_run_parallel
|
@@ -578,7 +499,8 @@ class TestMiniTestRunner < MetaMetaMetaTestCase
|
|
578
499
|
main_latch.release
|
579
500
|
}
|
580
501
|
|
581
|
-
|
502
|
+
@tu =
|
503
|
+
Class.new Minitest::Test do
|
582
504
|
parallelize_me!
|
583
505
|
|
584
506
|
test_count.times do |i|
|
@@ -598,9 +520,9 @@ class TestMiniTestRunner < MetaMetaMetaTestCase
|
|
598
520
|
expected = clean <<-EOM
|
599
521
|
..
|
600
522
|
|
601
|
-
Finished
|
523
|
+
Finished in 0.00
|
602
524
|
|
603
|
-
2
|
525
|
+
2 runs, 2 assertions, 0 failures, 0 errors, 0 skips
|
604
526
|
EOM
|
605
527
|
|
606
528
|
assert_report expected
|
@@ -608,12 +530,13 @@ class TestMiniTestRunner < MetaMetaMetaTestCase
|
|
608
530
|
end
|
609
531
|
end
|
610
532
|
|
611
|
-
class
|
533
|
+
class TestMinitestUnitOrder < MetaMetaMetaTestCase
|
612
534
|
# do not parallelize this suite... it just can't handle it.
|
613
535
|
|
614
536
|
def test_before_setup
|
615
537
|
call_order = []
|
616
|
-
|
538
|
+
@tu =
|
539
|
+
Class.new Minitest::Test do
|
617
540
|
define_method :setup do
|
618
541
|
super()
|
619
542
|
call_order << :setup
|
@@ -626,9 +549,7 @@ class TestMiniTestUnitOrder < MetaMetaMetaTestCase
|
|
626
549
|
def test_omg; assert true; end
|
627
550
|
end
|
628
551
|
|
629
|
-
|
630
|
-
@tu.run %w[--seed 42]
|
631
|
-
end
|
552
|
+
run_tu_with_fresh_reporter
|
632
553
|
|
633
554
|
expected = [:before_setup, :setup]
|
634
555
|
assert_equal expected, call_order
|
@@ -636,7 +557,8 @@ class TestMiniTestUnitOrder < MetaMetaMetaTestCase
|
|
636
557
|
|
637
558
|
def test_after_teardown
|
638
559
|
call_order = []
|
639
|
-
|
560
|
+
@tu =
|
561
|
+
Class.new Minitest::Test do
|
640
562
|
define_method :teardown do
|
641
563
|
super()
|
642
564
|
call_order << :teardown
|
@@ -649,9 +571,7 @@ class TestMiniTestUnitOrder < MetaMetaMetaTestCase
|
|
649
571
|
def test_omg; assert true; end
|
650
572
|
end
|
651
573
|
|
652
|
-
|
653
|
-
@tu.run %w[--seed 42]
|
654
|
-
end
|
574
|
+
run_tu_with_fresh_reporter
|
655
575
|
|
656
576
|
expected = [:teardown, :after_teardown]
|
657
577
|
assert_equal expected, call_order
|
@@ -659,7 +579,8 @@ class TestMiniTestUnitOrder < MetaMetaMetaTestCase
|
|
659
579
|
|
660
580
|
def test_all_teardowns_are_guaranteed_to_run
|
661
581
|
call_order = []
|
662
|
-
|
582
|
+
@tu =
|
583
|
+
Class.new Minitest::Test do
|
663
584
|
define_method :after_teardown do
|
664
585
|
super()
|
665
586
|
call_order << :after_teardown
|
@@ -681,9 +602,7 @@ class TestMiniTestUnitOrder < MetaMetaMetaTestCase
|
|
681
602
|
def test_omg; assert true; end
|
682
603
|
end
|
683
604
|
|
684
|
-
|
685
|
-
@tu.run %w[--seed 42]
|
686
|
-
end
|
605
|
+
run_tu_with_fresh_reporter
|
687
606
|
|
688
607
|
expected = [:before_teardown, :teardown, :after_teardown]
|
689
608
|
assert_equal expected, call_order
|
@@ -692,7 +611,7 @@ class TestMiniTestUnitOrder < MetaMetaMetaTestCase
|
|
692
611
|
def test_setup_and_teardown_survive_inheritance
|
693
612
|
call_order = []
|
694
613
|
|
695
|
-
|
614
|
+
@tu = Class.new Minitest::Test do
|
696
615
|
define_method :setup do
|
697
616
|
call_order << :setup_method
|
698
617
|
end
|
@@ -706,11 +625,10 @@ class TestMiniTestUnitOrder < MetaMetaMetaTestCase
|
|
706
625
|
end
|
707
626
|
end
|
708
627
|
|
709
|
-
|
628
|
+
run_tu_with_fresh_reporter
|
710
629
|
|
711
|
-
|
712
|
-
|
713
|
-
end
|
630
|
+
@tu = Class.new @tu
|
631
|
+
run_tu_with_fresh_reporter
|
714
632
|
|
715
633
|
# Once for the parent class, once for the child
|
716
634
|
expected = [:setup_method, :test, :teardown_method] * 2
|
@@ -719,7 +637,54 @@ class TestMiniTestUnitOrder < MetaMetaMetaTestCase
|
|
719
637
|
end
|
720
638
|
end
|
721
639
|
|
722
|
-
class
|
640
|
+
class TestMinitestRunnable < Minitest::Test
|
641
|
+
def setup_dup klass
|
642
|
+
tc = klass.new "whatever"
|
643
|
+
tc.assertions = 42
|
644
|
+
tc.failures << "a failure"
|
645
|
+
|
646
|
+
yield tc if block_given?
|
647
|
+
|
648
|
+
def tc.setup
|
649
|
+
@blah = "blah"
|
650
|
+
end
|
651
|
+
tc.setup
|
652
|
+
|
653
|
+
@tc = tc
|
654
|
+
end
|
655
|
+
|
656
|
+
def assert_dup expected_ivars
|
657
|
+
new_tc = @tc.dup
|
658
|
+
|
659
|
+
ivars = new_tc.instance_variables.map(&:to_s).sort
|
660
|
+
assert_equal expected_ivars, ivars
|
661
|
+
assert_equal "whatever", new_tc.name
|
662
|
+
assert_equal 42, new_tc.assertions
|
663
|
+
assert_equal ["a failure"], new_tc.failures
|
664
|
+
|
665
|
+
yield new_tc if block_given?
|
666
|
+
end
|
667
|
+
|
668
|
+
def test_dup
|
669
|
+
setup_dup Minitest::Runnable
|
670
|
+
|
671
|
+
assert_dup %w(@NAME @assertions @failures)
|
672
|
+
end
|
673
|
+
end
|
674
|
+
|
675
|
+
class TestMinitestTest < TestMinitestRunnable
|
676
|
+
def test_dup
|
677
|
+
setup_dup Minitest::Test do |tc|
|
678
|
+
tc.time = 3.14
|
679
|
+
end
|
680
|
+
|
681
|
+
assert_dup %w(@NAME @assertions @failures @time) do |new_tc|
|
682
|
+
assert_in_epsilon 3.14, new_tc.time
|
683
|
+
end
|
684
|
+
end
|
685
|
+
end
|
686
|
+
|
687
|
+
class TestMinitestUnitTestCase < Minitest::Test
|
723
688
|
# do not call parallelize_me! - teardown accesses @tc._assertions
|
724
689
|
# which is not threadsafe. Nearly every method in here is an
|
725
690
|
# assertion test so it isn't worth splitting it out further.
|
@@ -729,16 +694,16 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
|
|
729
694
|
def setup
|
730
695
|
super
|
731
696
|
|
732
|
-
|
697
|
+
Minitest::Test.reset
|
733
698
|
|
734
|
-
@tc =
|
699
|
+
@tc = Minitest::Test.new 'fake tc'
|
735
700
|
@zomg = "zomg ponies!"
|
736
701
|
@assertion_count = 1
|
737
702
|
end
|
738
703
|
|
739
704
|
def teardown
|
740
|
-
assert_equal(@assertion_count, @tc._assertions,
|
741
|
-
|
705
|
+
# assert_equal(@assertion_count, @tc._assertions,
|
706
|
+
# "expected #{@assertion_count} assertions to be fired during the test, not #{@tc._assertions}") if @tc.passed?
|
742
707
|
end
|
743
708
|
|
744
709
|
def non_verbose
|
@@ -989,7 +954,7 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
|
|
989
954
|
def test_assert_includes_triggered
|
990
955
|
@assertion_count = 3
|
991
956
|
|
992
|
-
e = @tc.assert_raises
|
957
|
+
e = @tc.assert_raises Minitest::Assertion do
|
993
958
|
@tc.assert_includes [true], false
|
994
959
|
end
|
995
960
|
|
@@ -1180,7 +1145,7 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
|
|
1180
1145
|
def test_assert_raises_skip
|
1181
1146
|
@assertion_count = 0
|
1182
1147
|
|
1183
|
-
util_assert_triggered "skipped",
|
1148
|
+
util_assert_triggered "skipped", Minitest::Skip do
|
1184
1149
|
@tc.assert_raises ArgumentError do
|
1185
1150
|
begin
|
1186
1151
|
raise "blah"
|
@@ -1192,7 +1157,7 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
|
|
1192
1157
|
end
|
1193
1158
|
|
1194
1159
|
def test_assert_raises_triggered_different
|
1195
|
-
e = assert_raises
|
1160
|
+
e = assert_raises Minitest::Assertion do
|
1196
1161
|
@tc.assert_raises RuntimeError do
|
1197
1162
|
raise SyntaxError, "icky"
|
1198
1163
|
end
|
@@ -1214,7 +1179,7 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
|
|
1214
1179
|
end
|
1215
1180
|
|
1216
1181
|
def test_assert_raises_triggered_different_msg
|
1217
|
-
e = assert_raises
|
1182
|
+
e = assert_raises Minitest::Assertion do
|
1218
1183
|
@tc.assert_raises RuntimeError, "XXX" do
|
1219
1184
|
raise SyntaxError, "icky"
|
1220
1185
|
end
|
@@ -1237,31 +1202,31 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
|
|
1237
1202
|
end
|
1238
1203
|
|
1239
1204
|
def test_assert_raises_triggered_none
|
1240
|
-
e = assert_raises
|
1241
|
-
@tc.assert_raises
|
1205
|
+
e = assert_raises Minitest::Assertion do
|
1206
|
+
@tc.assert_raises Minitest::Assertion do
|
1242
1207
|
# do nothing
|
1243
1208
|
end
|
1244
1209
|
end
|
1245
1210
|
|
1246
|
-
expected = "
|
1211
|
+
expected = "Minitest::Assertion expected but nothing was raised."
|
1247
1212
|
|
1248
1213
|
assert_equal expected, e.message
|
1249
1214
|
end
|
1250
1215
|
|
1251
1216
|
def test_assert_raises_triggered_none_msg
|
1252
|
-
e = assert_raises
|
1253
|
-
@tc.assert_raises
|
1217
|
+
e = assert_raises Minitest::Assertion do
|
1218
|
+
@tc.assert_raises Minitest::Assertion, "XXX" do
|
1254
1219
|
# do nothing
|
1255
1220
|
end
|
1256
1221
|
end
|
1257
1222
|
|
1258
|
-
expected = "XXX.\
|
1223
|
+
expected = "XXX.\nMinitest::Assertion expected but nothing was raised."
|
1259
1224
|
|
1260
1225
|
assert_equal expected, e.message
|
1261
1226
|
end
|
1262
1227
|
|
1263
1228
|
def test_assert_raises_triggered_subclass
|
1264
|
-
e = assert_raises
|
1229
|
+
e = assert_raises Minitest::Assertion do
|
1265
1230
|
@tc.assert_raises StandardError do
|
1266
1231
|
raise AnError
|
1267
1232
|
end
|
@@ -1406,7 +1371,7 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
|
|
1406
1371
|
def test_class_asserts_match_refutes
|
1407
1372
|
@assertion_count = 0
|
1408
1373
|
|
1409
|
-
methods =
|
1374
|
+
methods = Minitest::Assertions.public_instance_methods
|
1410
1375
|
methods.map! { |m| m.to_s } if Symbol === methods.first
|
1411
1376
|
|
1412
1377
|
# These don't have corresponding refutes _on purpose_. They're
|
@@ -1482,7 +1447,7 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
|
|
1482
1447
|
end
|
1483
1448
|
|
1484
1449
|
def test_prints
|
1485
|
-
printer = Class.new { extend
|
1450
|
+
printer = Class.new { extend Minitest::Assertions }
|
1486
1451
|
@tc.assert_equal '"test"', printer.mu_pp(ImmutableString.new 'test')
|
1487
1452
|
end
|
1488
1453
|
|
@@ -1547,7 +1512,7 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
|
|
1547
1512
|
def test_refute_includes_triggered
|
1548
1513
|
@assertion_count = 3
|
1549
1514
|
|
1550
|
-
e = @tc.assert_raises
|
1515
|
+
e = @tc.assert_raises Minitest::Assertion do
|
1551
1516
|
@tc.refute_includes [true], true
|
1552
1517
|
end
|
1553
1518
|
|
@@ -1664,15 +1629,15 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
|
|
1664
1629
|
def test_skip
|
1665
1630
|
@assertion_count = 0
|
1666
1631
|
|
1667
|
-
util_assert_triggered "haha!",
|
1632
|
+
util_assert_triggered "haha!", Minitest::Skip do
|
1668
1633
|
@tc.skip "haha!"
|
1669
1634
|
end
|
1670
1635
|
end
|
1671
1636
|
|
1672
|
-
def
|
1637
|
+
def test_runnable_methods_random
|
1673
1638
|
@assertion_count = 0
|
1674
1639
|
|
1675
|
-
sample_test_case = Class.new
|
1640
|
+
sample_test_case = Class.new Minitest::Test do
|
1676
1641
|
def self.test_order; :random; end
|
1677
1642
|
def test_test1; assert "does not matter" end
|
1678
1643
|
def test_test2; assert "does not matter" end
|
@@ -1686,13 +1651,13 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
|
|
1686
1651
|
else
|
1687
1652
|
%w(test_test2 test_test1 test_test3)
|
1688
1653
|
end
|
1689
|
-
assert_equal expected, sample_test_case.
|
1654
|
+
assert_equal expected, sample_test_case.runnable_methods
|
1690
1655
|
end
|
1691
1656
|
|
1692
|
-
def
|
1657
|
+
def test_runnable_methods_sorted
|
1693
1658
|
@assertion_count = 0
|
1694
1659
|
|
1695
|
-
sample_test_case = Class.new
|
1660
|
+
sample_test_case = Class.new Minitest::Test do
|
1696
1661
|
def self.test_order; :sorted end
|
1697
1662
|
def test_test3; assert "does not matter" end
|
1698
1663
|
def test_test2; assert "does not matter" end
|
@@ -1700,13 +1665,13 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
|
|
1700
1665
|
end
|
1701
1666
|
|
1702
1667
|
expected = %w(test_test1 test_test2 test_test3)
|
1703
|
-
assert_equal expected, sample_test_case.
|
1668
|
+
assert_equal expected, sample_test_case.runnable_methods
|
1704
1669
|
end
|
1705
1670
|
|
1706
1671
|
def test_i_suck_and_my_tests_are_order_dependent_bang_sets_test_order_alpha
|
1707
1672
|
@assertion_count = 0
|
1708
1673
|
|
1709
|
-
shitty_test_case = Class.new
|
1674
|
+
shitty_test_case = Class.new Minitest::Test
|
1710
1675
|
|
1711
1676
|
shitty_test_case.i_suck_and_my_tests_are_order_dependent!
|
1712
1677
|
|
@@ -1716,7 +1681,7 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
|
|
1716
1681
|
def test_i_suck_and_my_tests_are_order_dependent_bang_does_not_warn
|
1717
1682
|
@assertion_count = 0
|
1718
1683
|
|
1719
|
-
shitty_test_case = Class.new
|
1684
|
+
shitty_test_case = Class.new Minitest::Test
|
1720
1685
|
|
1721
1686
|
def shitty_test_case.test_order ; :lol end
|
1722
1687
|
|
@@ -1725,7 +1690,7 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
|
|
1725
1690
|
end
|
1726
1691
|
end
|
1727
1692
|
|
1728
|
-
def util_assert_triggered expected, klass =
|
1693
|
+
def util_assert_triggered expected, klass = Minitest::Assertion
|
1729
1694
|
e = assert_raises klass do
|
1730
1695
|
yield
|
1731
1696
|
end
|
@@ -1744,16 +1709,16 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
|
|
1744
1709
|
end
|
1745
1710
|
|
1746
1711
|
def without_diff
|
1747
|
-
old_diff =
|
1748
|
-
|
1712
|
+
old_diff = Minitest::Assertions.diff
|
1713
|
+
Minitest::Assertions.diff = nil
|
1749
1714
|
|
1750
1715
|
yield
|
1751
1716
|
ensure
|
1752
|
-
|
1717
|
+
Minitest::Assertions.diff = old_diff
|
1753
1718
|
end
|
1754
1719
|
end
|
1755
1720
|
|
1756
|
-
class
|
1721
|
+
class TestMinitestGuard < Minitest::Test
|
1757
1722
|
parallelize_me!
|
1758
1723
|
|
1759
1724
|
def test_mri_eh
|
@@ -1777,33 +1742,21 @@ class TestMiniTestGuard < MiniTest::Unit::TestCase
|
|
1777
1742
|
end
|
1778
1743
|
end
|
1779
1744
|
|
1780
|
-
class
|
1745
|
+
class TestMinitestUnitRecording < MetaMetaMetaTestCase
|
1781
1746
|
# do not parallelize this suite... it just can't handle it.
|
1782
1747
|
|
1783
1748
|
def assert_run_record(*expected, &block)
|
1784
|
-
|
1785
|
-
recording[method] << error
|
1786
|
-
end
|
1787
|
-
|
1788
|
-
def @tu.recording
|
1789
|
-
@recording ||= Hash.new { |h,k| h[k] = [] }
|
1790
|
-
end
|
1749
|
+
@tu = Class.new Minitest::Test, &block
|
1791
1750
|
|
1792
|
-
|
1751
|
+
run_tu_with_fresh_reporter
|
1793
1752
|
|
1794
|
-
|
1795
|
-
|
1796
|
-
with_output do
|
1797
|
-
@tu.run
|
1798
|
-
end
|
1799
|
-
|
1800
|
-
recorded = @tu.recording.fetch("test_method").map(&:class)
|
1753
|
+
recorded = reporter.results.map(&:failures).flatten.map { |f| f.error.class }
|
1801
1754
|
|
1802
1755
|
assert_equal expected, recorded
|
1803
1756
|
end
|
1804
1757
|
|
1805
1758
|
def test_record_passing
|
1806
|
-
assert_run_record
|
1759
|
+
assert_run_record do
|
1807
1760
|
def test_method
|
1808
1761
|
assert true
|
1809
1762
|
end
|
@@ -1811,7 +1764,7 @@ class TestMiniTestUnitRecording < MetaMetaMetaTestCase
|
|
1811
1764
|
end
|
1812
1765
|
|
1813
1766
|
def test_record_failing
|
1814
|
-
assert_run_record
|
1767
|
+
assert_run_record Minitest::Assertion do
|
1815
1768
|
def test_method
|
1816
1769
|
assert false
|
1817
1770
|
end
|
@@ -1827,7 +1780,7 @@ class TestMiniTestUnitRecording < MetaMetaMetaTestCase
|
|
1827
1780
|
end
|
1828
1781
|
|
1829
1782
|
def test_record_error_teardown
|
1830
|
-
assert_run_record
|
1783
|
+
assert_run_record RuntimeError do
|
1831
1784
|
def test_method
|
1832
1785
|
assert true
|
1833
1786
|
end
|
@@ -1850,8 +1803,36 @@ class TestMiniTestUnitRecording < MetaMetaMetaTestCase
|
|
1850
1803
|
end
|
1851
1804
|
end
|
1852
1805
|
|
1806
|
+
def test_to_s_error_in_test_and_teardown
|
1807
|
+
@tu = Class.new Minitest::Test do
|
1808
|
+
def test_method
|
1809
|
+
raise AnError
|
1810
|
+
end
|
1811
|
+
|
1812
|
+
def teardown
|
1813
|
+
raise "unhandled exception"
|
1814
|
+
end
|
1815
|
+
end
|
1816
|
+
|
1817
|
+
run_tu_with_fresh_reporter
|
1818
|
+
|
1819
|
+
exp = clean "
|
1820
|
+
Error:
|
1821
|
+
#<Class:0xXXX>#test_method:
|
1822
|
+
AnError: AnError
|
1823
|
+
FILE:LINE:in `test_method'
|
1824
|
+
|
1825
|
+
Error:
|
1826
|
+
#<Class:0xXXX>#test_method:
|
1827
|
+
RuntimeError: unhandled exception
|
1828
|
+
FILE:LINE:in `teardown'
|
1829
|
+
"
|
1830
|
+
|
1831
|
+
assert_equal exp.strip, normalize_output(reporter.results.first.to_s).strip
|
1832
|
+
end
|
1833
|
+
|
1853
1834
|
def test_record_skip
|
1854
|
-
assert_run_record
|
1835
|
+
assert_run_record Minitest::Skip do
|
1855
1836
|
def test_method
|
1856
1837
|
skip "not yet"
|
1857
1838
|
end
|