minitest 4.7.5 → 5.0.7
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.
- data/.autotest +21 -8
- data/History.txt +132 -12
- data/Manifest.txt +6 -0
- data/README.txt +109 -59
- data/Rakefile +3 -31
- data/design_rationale.rb +2 -2
- data/lib/hoe/minitest.rb +9 -5
- data/lib/minitest/assertions.rb +649 -0
- data/lib/minitest/autorun.rb +6 -6
- data/lib/minitest/benchmark.rb +92 -85
- data/lib/minitest/expectations.rb +281 -0
- data/lib/minitest/hell.rb +3 -5
- data/lib/minitest/mock.rb +40 -13
- 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 +45 -312
- data/lib/minitest/test.rb +287 -0
- data/lib/minitest/unit.rb +32 -1402
- data/lib/minitest.rb +733 -0
- data/test/minitest/metametameta.rb +41 -30
- data/test/minitest/test_minitest_benchmark.rb +11 -9
- data/test/minitest/test_minitest_mock.rb +116 -32
- data/test/minitest/test_minitest_reporter.rb +313 -0
- data/test/minitest/test_minitest_spec.rb +52 -63
- data/test/minitest/test_minitest_unit.rb +231 -235
- data.tar.gz.sig +0 -0
- metadata +17 -10
- metadata.gz.sig +2 -1
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
require "minitest/autorun"
|
|
2
|
+
require "minitest/metametameta"
|
|
3
|
+
|
|
4
|
+
class TestMinitestReporter < Minitest::Test
|
|
5
|
+
|
|
6
|
+
attr_accessor :r, :io
|
|
7
|
+
|
|
8
|
+
def new_composite_reporter
|
|
9
|
+
reporter = Minitest::CompositeReporter.new
|
|
10
|
+
reporter << Minitest::SummaryReporter.new(self.io)
|
|
11
|
+
reporter << Minitest::ProgressReporter.new(self.io)
|
|
12
|
+
|
|
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
|
|
28
|
+
|
|
29
|
+
reporter
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def setup
|
|
33
|
+
self.io = StringIO.new("")
|
|
34
|
+
self.r = new_composite_reporter
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def error_test
|
|
38
|
+
unless defined? @et then
|
|
39
|
+
@et = Minitest::Test.new(:woot)
|
|
40
|
+
@et.failures << Minitest::UnexpectedError.new(begin
|
|
41
|
+
raise "no"
|
|
42
|
+
rescue => e
|
|
43
|
+
e
|
|
44
|
+
end)
|
|
45
|
+
end
|
|
46
|
+
@et
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def fail_test
|
|
50
|
+
unless defined? @ft then
|
|
51
|
+
@ft = Minitest::Test.new(:woot)
|
|
52
|
+
@ft.failures << begin
|
|
53
|
+
raise Minitest::Assertion, "boo"
|
|
54
|
+
rescue Minitest::Assertion => e
|
|
55
|
+
e
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
@ft
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def passing_test
|
|
62
|
+
@pt ||= Minitest::Test.new(:woot)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def skip_test
|
|
66
|
+
unless defined? @st then
|
|
67
|
+
@st = Minitest::Test.new(:woot)
|
|
68
|
+
@st.failures << begin
|
|
69
|
+
raise Minitest::Skip
|
|
70
|
+
rescue Minitest::Assertion => e
|
|
71
|
+
e
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
@st
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def test_passed_eh_empty
|
|
78
|
+
assert r.passed?
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def test_passed_eh_failure
|
|
82
|
+
r.results << fail_test
|
|
83
|
+
|
|
84
|
+
refute r.passed?
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
SKIP_MSG = "\n\nYou have skipped tests. Run with --verbose for details."
|
|
88
|
+
|
|
89
|
+
def test_passed_eh_error
|
|
90
|
+
r.start
|
|
91
|
+
|
|
92
|
+
r.results << error_test
|
|
93
|
+
|
|
94
|
+
refute r.passed?
|
|
95
|
+
|
|
96
|
+
r.report
|
|
97
|
+
|
|
98
|
+
refute_match SKIP_MSG, io.string
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def test_passed_eh_skipped
|
|
102
|
+
r.start
|
|
103
|
+
r.results << skip_test
|
|
104
|
+
assert r.passed?
|
|
105
|
+
|
|
106
|
+
restore_env do
|
|
107
|
+
r.report
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
assert_match SKIP_MSG, io.string
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def test_passed_eh_skipped_verbose
|
|
114
|
+
r.first.options[:verbose] = true
|
|
115
|
+
|
|
116
|
+
r.start
|
|
117
|
+
r.results << skip_test
|
|
118
|
+
assert r.passed?
|
|
119
|
+
r.report
|
|
120
|
+
|
|
121
|
+
refute_match SKIP_MSG, io.string
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def test_start
|
|
125
|
+
r.start
|
|
126
|
+
|
|
127
|
+
exp = "Run options: \n\n# Running:\n\n"
|
|
128
|
+
|
|
129
|
+
assert_equal exp, io.string
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def test_record_pass
|
|
133
|
+
r.record passing_test
|
|
134
|
+
|
|
135
|
+
assert_equal ".", io.string
|
|
136
|
+
assert_empty r.results
|
|
137
|
+
assert_equal 1, r.count
|
|
138
|
+
assert_equal 0, r.assertions
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def test_record_fail
|
|
142
|
+
r.record fail_test
|
|
143
|
+
|
|
144
|
+
assert_equal "F", io.string
|
|
145
|
+
assert_equal [fail_test], r.results
|
|
146
|
+
assert_equal 1, r.count
|
|
147
|
+
assert_equal 0, r.assertions
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def test_record_error
|
|
151
|
+
r.record error_test
|
|
152
|
+
|
|
153
|
+
assert_equal "E", io.string
|
|
154
|
+
assert_equal [error_test], r.results
|
|
155
|
+
assert_equal 1, r.count
|
|
156
|
+
assert_equal 0, r.assertions
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def test_record_skip
|
|
160
|
+
r.record skip_test
|
|
161
|
+
|
|
162
|
+
assert_equal "S", io.string
|
|
163
|
+
assert_equal [skip_test], r.results
|
|
164
|
+
assert_equal 1, r.count
|
|
165
|
+
assert_equal 0, r.assertions
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def normalize_output output
|
|
169
|
+
output.sub!(/Finished in .*/, "Finished in 0.00")
|
|
170
|
+
output.sub!(/Loaded suite .*/, 'Loaded suite blah')
|
|
171
|
+
|
|
172
|
+
output.gsub!(/ = \d+.\d\d s = /, ' = 0.00 s = ')
|
|
173
|
+
output.gsub!(/0x[A-Fa-f0-9]+/, '0xXXX')
|
|
174
|
+
output.gsub!(/ +$/, '')
|
|
175
|
+
|
|
176
|
+
if windows? then
|
|
177
|
+
output.gsub!(/\[(?:[A-Za-z]:)?[^\]:]+:\d+\]/, '[FILE:LINE]')
|
|
178
|
+
output.gsub!(/^(\s+)(?:[A-Za-z]:)?[^:]+:\d+:in/, '\1FILE:LINE:in')
|
|
179
|
+
else
|
|
180
|
+
output.gsub!(/\[[^\]:]+:\d+\]/, '[FILE:LINE]')
|
|
181
|
+
output.gsub!(/^(\s+)[^:]+:\d+:in/, '\1FILE:LINE:in')
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
output
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
def test_report_empty
|
|
188
|
+
r.start
|
|
189
|
+
r.report
|
|
190
|
+
|
|
191
|
+
exp = clean <<-EOM
|
|
192
|
+
Run options:
|
|
193
|
+
|
|
194
|
+
# Running:
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
Finished in 0.00
|
|
199
|
+
|
|
200
|
+
0 runs, 0 assertions, 0 failures, 0 errors, 0 skips
|
|
201
|
+
EOM
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
assert_equal exp, normalize_output(io.string)
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
def test_report_passing
|
|
208
|
+
r.start
|
|
209
|
+
r.record passing_test
|
|
210
|
+
r.report
|
|
211
|
+
|
|
212
|
+
exp = clean <<-EOM
|
|
213
|
+
Run options:
|
|
214
|
+
|
|
215
|
+
# Running:
|
|
216
|
+
|
|
217
|
+
.
|
|
218
|
+
|
|
219
|
+
Finished in 0.00
|
|
220
|
+
|
|
221
|
+
1 runs, 0 assertions, 0 failures, 0 errors, 0 skips
|
|
222
|
+
EOM
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
assert_equal exp, normalize_output(io.string)
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
def test_report_failure
|
|
229
|
+
r.start
|
|
230
|
+
r.record fail_test
|
|
231
|
+
r.report
|
|
232
|
+
|
|
233
|
+
exp = clean <<-EOM
|
|
234
|
+
Run options:
|
|
235
|
+
|
|
236
|
+
# Running:
|
|
237
|
+
|
|
238
|
+
F
|
|
239
|
+
|
|
240
|
+
Finished in 0.00
|
|
241
|
+
|
|
242
|
+
1) Failure:
|
|
243
|
+
Minitest::Test#woot [FILE:LINE]:
|
|
244
|
+
boo
|
|
245
|
+
|
|
246
|
+
1 runs, 0 assertions, 1 failures, 0 errors, 0 skips
|
|
247
|
+
EOM
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
assert_equal exp, normalize_output(io.string)
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
def test_report_error
|
|
254
|
+
r.start
|
|
255
|
+
r.record error_test
|
|
256
|
+
r.report
|
|
257
|
+
|
|
258
|
+
exp = clean <<-EOM
|
|
259
|
+
Run options:
|
|
260
|
+
|
|
261
|
+
# Running:
|
|
262
|
+
|
|
263
|
+
E
|
|
264
|
+
|
|
265
|
+
Finished in 0.00
|
|
266
|
+
|
|
267
|
+
1) Error:
|
|
268
|
+
Minitest::Test#woot:
|
|
269
|
+
RuntimeError: no
|
|
270
|
+
FILE:LINE:in `error_test'
|
|
271
|
+
FILE:LINE:in `test_report_error'
|
|
272
|
+
|
|
273
|
+
1 runs, 0 assertions, 0 failures, 1 errors, 0 skips
|
|
274
|
+
EOM
|
|
275
|
+
|
|
276
|
+
assert_equal exp, normalize_output(io.string)
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
def restore_env
|
|
280
|
+
old_value = ENV["MT_NO_SKIP_MSG"]
|
|
281
|
+
ENV.delete "MT_NO_SKIP_MSG"
|
|
282
|
+
|
|
283
|
+
yield
|
|
284
|
+
ensure
|
|
285
|
+
ENV["MT_NO_SKIP_MSG"] = old_value
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
def test_report_skipped
|
|
290
|
+
r.start
|
|
291
|
+
r.record skip_test
|
|
292
|
+
|
|
293
|
+
restore_env do
|
|
294
|
+
r.report
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
exp = clean <<-EOM
|
|
298
|
+
Run options:
|
|
299
|
+
|
|
300
|
+
# Running:
|
|
301
|
+
|
|
302
|
+
S
|
|
303
|
+
|
|
304
|
+
Finished in 0.00
|
|
305
|
+
|
|
306
|
+
1 runs, 0 assertions, 0 failures, 0 errors, 1 skips
|
|
307
|
+
|
|
308
|
+
You have skipped tests. Run with --verbose for details.
|
|
309
|
+
EOM
|
|
310
|
+
|
|
311
|
+
assert_equal exp, normalize_output(io.string)
|
|
312
|
+
end
|
|
313
|
+
end
|
|
@@ -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
|
|
@@ -552,9 +551,15 @@ describe MiniTest::Spec, :let do
|
|
|
552
551
|
|
|
553
552
|
_count.must_equal 2
|
|
554
553
|
end
|
|
554
|
+
|
|
555
|
+
it 'raises an error if the name begins with "test"' do
|
|
556
|
+
describe "let" do
|
|
557
|
+
proc { let(:test_value) { true } }.must_raise ArgumentError
|
|
558
|
+
end
|
|
559
|
+
end
|
|
555
560
|
end
|
|
556
561
|
|
|
557
|
-
describe
|
|
562
|
+
describe Minitest::Spec, :subject do
|
|
558
563
|
attr_reader :subject_evaluation_count
|
|
559
564
|
|
|
560
565
|
subject do
|
|
@@ -570,9 +575,9 @@ describe MiniTest::Spec, :subject do
|
|
|
570
575
|
end
|
|
571
576
|
end
|
|
572
577
|
|
|
573
|
-
class TestMetaStatic <
|
|
578
|
+
class TestMetaStatic < Minitest::Test
|
|
574
579
|
def test_children
|
|
575
|
-
|
|
580
|
+
Minitest::Spec.children.clear # prevents parallel run
|
|
576
581
|
|
|
577
582
|
x = y = z = nil
|
|
578
583
|
x = describe "top-level thingy" do
|
|
@@ -583,14 +588,16 @@ class TestMetaStatic < MiniTest::Unit::TestCase
|
|
|
583
588
|
z = describe "second thingy" do end
|
|
584
589
|
end
|
|
585
590
|
|
|
586
|
-
assert_equal [x],
|
|
591
|
+
assert_equal [x], Minitest::Spec.children
|
|
587
592
|
assert_equal [y, z], x.children
|
|
588
593
|
assert_equal [], y.children
|
|
589
594
|
assert_equal [], z.children
|
|
590
595
|
end
|
|
591
596
|
end
|
|
592
597
|
|
|
593
|
-
|
|
598
|
+
require "minitest/metametameta"
|
|
599
|
+
|
|
600
|
+
class TestMeta < MetaMetaMetaTestCase
|
|
594
601
|
parallelize_me!
|
|
595
602
|
|
|
596
603
|
def util_structure
|
|
@@ -623,35 +630,35 @@ class TestMeta < MiniTest::Unit::TestCase
|
|
|
623
630
|
end
|
|
624
631
|
|
|
625
632
|
def test_register_spec_type
|
|
626
|
-
original_types =
|
|
633
|
+
original_types = Minitest::Spec::TYPES.dup
|
|
627
634
|
|
|
628
|
-
|
|
635
|
+
assert_includes Minitest::Spec::TYPES, [//, Minitest::Spec]
|
|
629
636
|
|
|
630
|
-
|
|
637
|
+
Minitest::Spec.register_spec_type(/woot/, TestMeta)
|
|
631
638
|
|
|
632
639
|
p = lambda do |x| true end
|
|
633
|
-
|
|
640
|
+
Minitest::Spec.register_spec_type TestMeta, &p
|
|
634
641
|
|
|
635
|
-
keys =
|
|
642
|
+
keys = Minitest::Spec::TYPES.map(&:first)
|
|
636
643
|
|
|
637
644
|
assert_includes keys, /woot/
|
|
638
645
|
assert_includes keys, p
|
|
639
646
|
ensure
|
|
640
|
-
|
|
647
|
+
Minitest::Spec::TYPES.replace original_types
|
|
641
648
|
end
|
|
642
649
|
|
|
643
650
|
def test_spec_type
|
|
644
|
-
original_types =
|
|
651
|
+
original_types = Minitest::Spec::TYPES.dup
|
|
645
652
|
|
|
646
|
-
|
|
647
|
-
|
|
653
|
+
Minitest::Spec.register_spec_type(/A$/, MiniSpecA)
|
|
654
|
+
Minitest::Spec.register_spec_type MiniSpecB do |desc|
|
|
648
655
|
desc.superclass == ExampleA
|
|
649
656
|
end
|
|
650
657
|
|
|
651
|
-
assert_equal MiniSpecA,
|
|
652
|
-
assert_equal MiniSpecB,
|
|
658
|
+
assert_equal MiniSpecA, Minitest::Spec.spec_type(ExampleA)
|
|
659
|
+
assert_equal MiniSpecB, Minitest::Spec.spec_type(ExampleB)
|
|
653
660
|
ensure
|
|
654
|
-
|
|
661
|
+
Minitest::Spec::TYPES.replace original_types
|
|
655
662
|
end
|
|
656
663
|
|
|
657
664
|
def test_name
|
|
@@ -698,16 +705,13 @@ class TestMeta < MiniTest::Unit::TestCase
|
|
|
698
705
|
def test_setup_teardown_behavior
|
|
699
706
|
_, _, z, before_list, after_list = util_structure
|
|
700
707
|
|
|
701
|
-
@tu =
|
|
702
|
-
MiniTest::Unit.runner = nil # protect the outer runner from the inner tests
|
|
708
|
+
@tu = z
|
|
703
709
|
|
|
704
|
-
|
|
705
|
-
tc = z.new :test_0002_anonymous
|
|
706
|
-
tc.run @tu
|
|
707
|
-
end
|
|
710
|
+
run_tu_with_fresh_reporter
|
|
708
711
|
|
|
709
|
-
|
|
710
|
-
assert_equal [
|
|
712
|
+
size = z.runnable_methods.size
|
|
713
|
+
assert_equal [1, 2, 3] * size, before_list
|
|
714
|
+
assert_equal [3, 2, 1] * size, after_list
|
|
711
715
|
end
|
|
712
716
|
|
|
713
717
|
def test_describe_first_structure
|
|
@@ -732,7 +736,7 @@ class TestMeta < MiniTest::Unit::TestCase
|
|
|
732
736
|
|
|
733
737
|
def test_structure_subclasses
|
|
734
738
|
z = nil
|
|
735
|
-
x = Class.new
|
|
739
|
+
x = Class.new Minitest::Spec do
|
|
736
740
|
def xyz; end
|
|
737
741
|
end
|
|
738
742
|
y = Class.new x do
|
|
@@ -743,32 +747,19 @@ class TestMeta < MiniTest::Unit::TestCase
|
|
|
743
747
|
assert_respond_to y.new(nil), "xyz"
|
|
744
748
|
assert_respond_to z.new(nil), "xyz"
|
|
745
749
|
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
750
|
end
|
|
760
751
|
|
|
761
|
-
require "minitest/metametameta"
|
|
762
|
-
|
|
763
752
|
class TestSpecInTestCase < MetaMetaMetaTestCase
|
|
764
753
|
def setup
|
|
765
754
|
super
|
|
766
755
|
|
|
767
|
-
@tc =
|
|
756
|
+
@tc = self
|
|
768
757
|
@assertion_count = 1
|
|
769
758
|
end
|
|
770
759
|
|
|
771
|
-
def
|
|
760
|
+
def assert_triggered expected, klass = Minitest::Assertion
|
|
761
|
+
@assertion_count += 1
|
|
762
|
+
|
|
772
763
|
e = assert_raises klass do
|
|
773
764
|
yield
|
|
774
765
|
end
|
|
@@ -779,25 +770,23 @@ class TestSpecInTestCase < MetaMetaMetaTestCase
|
|
|
779
770
|
assert_equal expected, msg
|
|
780
771
|
end
|
|
781
772
|
|
|
782
|
-
def teardown
|
|
783
|
-
|
|
784
|
-
|
|
773
|
+
def teardown
|
|
774
|
+
msg = "expected #{@assertion_count} assertions, not #{@tc.assertions}"
|
|
775
|
+
assert_equal @assertion_count, @tc.assertions, msg
|
|
785
776
|
end
|
|
786
777
|
|
|
787
778
|
def test_expectation
|
|
788
|
-
@assertion_count = 2
|
|
789
|
-
|
|
790
779
|
@tc.assert_equal true, 1.must_equal(1)
|
|
791
780
|
end
|
|
792
781
|
|
|
793
782
|
def test_expectation_triggered
|
|
794
|
-
|
|
783
|
+
assert_triggered "Expected: 2\n Actual: 1" do
|
|
795
784
|
1.must_equal 2
|
|
796
785
|
end
|
|
797
786
|
end
|
|
798
787
|
|
|
799
788
|
def test_expectation_with_a_message
|
|
800
|
-
|
|
789
|
+
assert_triggered "Expected: 2\n Actual: 1" do
|
|
801
790
|
1.must_equal 2, ""
|
|
802
791
|
end
|
|
803
792
|
end
|