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.
@@ -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 TestMiniTestUnit < MetaMetaMetaTestCase
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 = MiniTest::filter_backtrace(bt)
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 = MiniTest::filter_backtrace(bt)
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 = MiniTest::filter_backtrace bt
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
- assert_instance_of MiniTest::Unit, MiniTest::Unit.runner
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 MiniTest::Unit::TestCase do
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 @tu
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 MiniTest::Unit::TestCase do
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 @tu
178
- assert test.passed?
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 MiniTest::Unit::TestCase do
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 @tu
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 TestMiniTestUnitInherited < MetaMetaMetaTestCase
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 MiniTest::Unit::TestCase
138
+ Class.new Minitest::Test
230
139
  end
231
140
  end
232
141
  end
233
142
  end
234
143
 
235
- class TestMiniTestRunner < MetaMetaMetaTestCase
144
+ class TestMinitestRunner < MetaMetaMetaTestCase
236
145
  # do not parallelize this suite... it just can't handle it.
237
146
 
238
- def test_class_test_suites
147
+ def test_class_runnables
239
148
  @assertion_count = 0
240
149
 
241
- tc = Class.new(MiniTest::Unit::TestCase)
150
+ tc = Class.new(Minitest::Test)
242
151
 
243
- assert_equal 1, MiniTest::Unit::TestCase.test_suites.size
244
- assert_equal [tc], MiniTest::Unit::TestCase.test_suites
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
- Class.new MiniTest::Unit::TestCase do
157
+ @tu =
158
+ Class.new Minitest::Test do
249
159
  attr_reader :foo
250
160
 
251
- def run_test name
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 tests in 0.00
177
+ Finished in 0.00
266
178
 
267
- 1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
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
- Class.new MiniTest::Unit::TestCase do
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 tests in 0.00
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 tests, 1 assertions, 0 failures, 1 errors, 0 skips
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
- Class.new MiniTest::Unit::TestCase do
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 tests in 0.00
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 tests, 1 assertions, 0 failures, 1 errors, 0 skips
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
- Class.new MiniTest::Unit::TestCase do
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 tests in 0.00
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 tests, 2 assertions, 1 failures, 0 errors, 0 skips
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
- Class.new MiniTest::Unit::TestCase do
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 tests in 0.00
283
+ Finished in 0.00
368
284
 
369
- 1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
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 MiniTest::Unit::TestCase do
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 MiniTest::Unit::TestCase do
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 tests in 0.00
320
+ Finished in 0.00
403
321
 
404
- 1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
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 tests in 0.00
332
+ Finished in 0.00
415
333
 
416
- 1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
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 tests in 0.00
344
+ Finished in 0.00
427
345
 
428
- 2 tests, 2 assertions, 0 failures, 0 errors, 0 skips
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
- Class.new MiniTest::Unit::TestCase do
353
+ @tu =
354
+ Class.new Minitest::Test do
436
355
  def test_something
437
356
  assert true
438
357
  end
@@ -441,16 +360,26 @@ class TestMiniTestRunner < MetaMetaMetaTestCase
441
360
  expected = clean <<-EOM
442
361
  .
443
362
 
444
- Finished tests in 0.00
363
+ Finished in 0.00
445
364
 
446
- 1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
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
 
371
+ def restore_env
372
+ old_value = ENV["MT_NO_SKIP_MSG"]
373
+ ENV.delete "MT_NO_SKIP_MSG"
374
+
375
+ yield
376
+ ensure
377
+ ENV["MT_NO_SKIP_MSG"] = old_value
378
+ end
379
+
452
380
  def test_run_skip
453
- Class.new MiniTest::Unit::TestCase do
381
+ @tu =
382
+ Class.new Minitest::Test do
454
383
  def test_something
455
384
  assert true
456
385
  end
@@ -463,16 +392,21 @@ class TestMiniTestRunner < MetaMetaMetaTestCase
463
392
  expected = clean <<-EOM
464
393
  S.
465
394
 
466
- Finished tests in 0.00
395
+ Finished in 0.00
396
+
397
+ 2 runs, 1 assertions, 0 failures, 0 errors, 1 skips
467
398
 
468
- 2 tests, 1 assertions, 0 failures, 0 errors, 1 skips
399
+ You have skipped tests. Run with --verbose for details.
469
400
  EOM
470
401
 
471
- assert_report expected
402
+ restore_env do
403
+ assert_report expected
404
+ end
472
405
  end
473
406
 
474
407
  def test_run_skip_verbose
475
- Class.new MiniTest::Unit::TestCase do
408
+ @tu =
409
+ Class.new Minitest::Test do
476
410
  def test_something
477
411
  assert true
478
412
  end
@@ -486,32 +420,31 @@ class TestMiniTestRunner < MetaMetaMetaTestCase
486
420
  #<Class:0xXXX>#test_skip = 0.00 s = S
487
421
  #<Class:0xXXX>#test_something = 0.00 s = .
488
422
 
489
-
490
- Finished tests in 0.00
423
+ Finished in 0.00
491
424
 
492
425
  1) Skipped:
493
426
  #<Class:0xXXX>#test_skip [FILE:LINE]:
494
427
  not yet
495
428
 
496
- 2 tests, 1 assertions, 0 failures, 0 errors, 1 skips
429
+ 2 runs, 1 assertions, 0 failures, 0 errors, 1 skips
497
430
  EOM
498
431
 
499
432
  assert_report expected, %w[--seed 42 --verbose]
500
433
  end
501
434
 
502
435
  def test_run_with_other_runner
503
- MiniTest::Unit.runner = Class.new MiniTest::Unit do
504
- def _run_suite suite, type
505
- suite.before_suite # Run once before each suite
506
- super suite, type
436
+ @tu =
437
+ Class.new Minitest::Test do
438
+ def self.run reporter, options = {}
439
+ @reporter = reporter
440
+ before_my_suite
441
+ super
507
442
  end
508
- end.new
509
443
 
510
- Class.new MiniTest::Unit::TestCase do
511
444
  def self.name; "wacky!" end
512
445
 
513
- def self.before_suite
514
- MiniTest::Unit.output.puts "Running #{self.name} tests"
446
+ def self.before_my_suite
447
+ @reporter.reporters.first.io.puts "Running #{self.name} tests"
515
448
  @@foo = 1
516
449
  end
517
450
 
@@ -528,9 +461,9 @@ class TestMiniTestRunner < MetaMetaMetaTestCase
528
461
  Running wacky! tests
529
462
  ..
530
463
 
531
- Finished tests in 0.00
464
+ Finished in 0.00
532
465
 
533
- 2 tests, 2 assertions, 0 failures, 0 errors, 0 skips
466
+ 2 runs, 2 assertions, 0 failures, 0 errors, 0 skips
534
467
  EOM
535
468
 
536
469
  assert_report expected
@@ -558,7 +491,7 @@ class TestMiniTestRunner < MetaMetaMetaTestCase
558
491
  end
559
492
 
560
493
  def test_parallel_each_size
561
- assert_equal 0, ParallelEach.new([]).size
494
+ assert_equal 0, Minitest::ParallelEach.new([]).size
562
495
  end
563
496
 
564
497
  def test_run_parallel
@@ -578,7 +511,8 @@ class TestMiniTestRunner < MetaMetaMetaTestCase
578
511
  main_latch.release
579
512
  }
580
513
 
581
- Class.new MiniTest::Unit::TestCase do
514
+ @tu =
515
+ Class.new Minitest::Test do
582
516
  parallelize_me!
583
517
 
584
518
  test_count.times do |i|
@@ -598,9 +532,9 @@ class TestMiniTestRunner < MetaMetaMetaTestCase
598
532
  expected = clean <<-EOM
599
533
  ..
600
534
 
601
- Finished tests in 0.00
535
+ Finished in 0.00
602
536
 
603
- 2 tests, 2 assertions, 0 failures, 0 errors, 0 skips
537
+ 2 runs, 2 assertions, 0 failures, 0 errors, 0 skips
604
538
  EOM
605
539
 
606
540
  assert_report expected
@@ -608,12 +542,13 @@ class TestMiniTestRunner < MetaMetaMetaTestCase
608
542
  end
609
543
  end
610
544
 
611
- class TestMiniTestUnitOrder < MetaMetaMetaTestCase
545
+ class TestMinitestUnitOrder < MetaMetaMetaTestCase
612
546
  # do not parallelize this suite... it just can't handle it.
613
547
 
614
548
  def test_before_setup
615
549
  call_order = []
616
- Class.new MiniTest::Unit::TestCase do
550
+ @tu =
551
+ Class.new Minitest::Test do
617
552
  define_method :setup do
618
553
  super()
619
554
  call_order << :setup
@@ -626,9 +561,7 @@ class TestMiniTestUnitOrder < MetaMetaMetaTestCase
626
561
  def test_omg; assert true; end
627
562
  end
628
563
 
629
- with_output do
630
- @tu.run %w[--seed 42]
631
- end
564
+ run_tu_with_fresh_reporter
632
565
 
633
566
  expected = [:before_setup, :setup]
634
567
  assert_equal expected, call_order
@@ -636,7 +569,8 @@ class TestMiniTestUnitOrder < MetaMetaMetaTestCase
636
569
 
637
570
  def test_after_teardown
638
571
  call_order = []
639
- Class.new MiniTest::Unit::TestCase do
572
+ @tu =
573
+ Class.new Minitest::Test do
640
574
  define_method :teardown do
641
575
  super()
642
576
  call_order << :teardown
@@ -649,9 +583,7 @@ class TestMiniTestUnitOrder < MetaMetaMetaTestCase
649
583
  def test_omg; assert true; end
650
584
  end
651
585
 
652
- with_output do
653
- @tu.run %w[--seed 42]
654
- end
586
+ run_tu_with_fresh_reporter
655
587
 
656
588
  expected = [:teardown, :after_teardown]
657
589
  assert_equal expected, call_order
@@ -659,7 +591,8 @@ class TestMiniTestUnitOrder < MetaMetaMetaTestCase
659
591
 
660
592
  def test_all_teardowns_are_guaranteed_to_run
661
593
  call_order = []
662
- Class.new MiniTest::Unit::TestCase do
594
+ @tu =
595
+ Class.new Minitest::Test do
663
596
  define_method :after_teardown do
664
597
  super()
665
598
  call_order << :after_teardown
@@ -681,9 +614,7 @@ class TestMiniTestUnitOrder < MetaMetaMetaTestCase
681
614
  def test_omg; assert true; end
682
615
  end
683
616
 
684
- with_output do
685
- @tu.run %w[--seed 42]
686
- end
617
+ run_tu_with_fresh_reporter
687
618
 
688
619
  expected = [:before_teardown, :teardown, :after_teardown]
689
620
  assert_equal expected, call_order
@@ -692,7 +623,7 @@ class TestMiniTestUnitOrder < MetaMetaMetaTestCase
692
623
  def test_setup_and_teardown_survive_inheritance
693
624
  call_order = []
694
625
 
695
- parent = Class.new MiniTest::Unit::TestCase do
626
+ @tu = Class.new Minitest::Test do
696
627
  define_method :setup do
697
628
  call_order << :setup_method
698
629
  end
@@ -706,11 +637,10 @@ class TestMiniTestUnitOrder < MetaMetaMetaTestCase
706
637
  end
707
638
  end
708
639
 
709
- _ = Class.new parent
640
+ run_tu_with_fresh_reporter
710
641
 
711
- with_output do
712
- @tu.run %w[--seed 42]
713
- end
642
+ @tu = Class.new @tu
643
+ run_tu_with_fresh_reporter
714
644
 
715
645
  # Once for the parent class, once for the child
716
646
  expected = [:setup_method, :test, :teardown_method] * 2
@@ -719,7 +649,54 @@ class TestMiniTestUnitOrder < MetaMetaMetaTestCase
719
649
  end
720
650
  end
721
651
 
722
- class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
652
+ class TestMinitestRunnable < Minitest::Test
653
+ def setup_marshal klass
654
+ tc = klass.new "whatever"
655
+ tc.assertions = 42
656
+ tc.failures << "a failure"
657
+
658
+ yield tc if block_given?
659
+
660
+ def tc.setup
661
+ @blah = "blah"
662
+ end
663
+ tc.setup
664
+
665
+ @tc = tc
666
+ end
667
+
668
+ def assert_marshal expected_ivars
669
+ new_tc = Marshal.load Marshal.dump @tc
670
+
671
+ ivars = new_tc.instance_variables.map(&:to_s).sort
672
+ assert_equal expected_ivars, ivars
673
+ assert_equal "whatever", new_tc.name
674
+ assert_equal 42, new_tc.assertions
675
+ assert_equal ["a failure"], new_tc.failures
676
+
677
+ yield new_tc if block_given?
678
+ end
679
+
680
+ def test_marshal
681
+ setup_marshal Minitest::Runnable
682
+
683
+ assert_marshal %w(@NAME @assertions @failures)
684
+ end
685
+ end
686
+
687
+ class TestMinitestTest < TestMinitestRunnable
688
+ def test_dup
689
+ setup_marshal Minitest::Test do |tc|
690
+ tc.time = 3.14
691
+ end
692
+
693
+ assert_marshal %w(@NAME @assertions @failures @time) do |new_tc|
694
+ assert_in_epsilon 3.14, new_tc.time
695
+ end
696
+ end
697
+ end
698
+
699
+ class TestMinitestUnitTestCase < Minitest::Test
723
700
  # do not call parallelize_me! - teardown accesses @tc._assertions
724
701
  # which is not threadsafe. Nearly every method in here is an
725
702
  # assertion test so it isn't worth splitting it out further.
@@ -729,16 +706,16 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
729
706
  def setup
730
707
  super
731
708
 
732
- MiniTest::Unit::TestCase.reset
709
+ Minitest::Test.reset
733
710
 
734
- @tc = MiniTest::Unit::TestCase.new 'fake tc'
711
+ @tc = Minitest::Test.new 'fake tc'
735
712
  @zomg = "zomg ponies!"
736
713
  @assertion_count = 1
737
714
  end
738
715
 
739
716
  def teardown
740
- assert_equal(@assertion_count, @tc._assertions,
741
- "expected #{@assertion_count} assertions to be fired during the test, not #{@tc._assertions}") if @tc.passed?
717
+ assert_equal(@assertion_count, @tc.assertions,
718
+ "expected #{@assertion_count} assertions to be fired during the test, not #{@tc.assertions}") if @tc.passed?
742
719
  end
743
720
 
744
721
  def non_verbose
@@ -926,6 +903,8 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
926
903
  end
927
904
 
928
905
  def test_delta_consistency
906
+ @assertion_count = 2
907
+
929
908
  @tc.assert_in_delta 0, 1, 1
930
909
 
931
910
  util_assert_triggered "Expected |0 - 1| (1) to not be <= 1." do
@@ -958,6 +937,8 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
958
937
  end
959
938
 
960
939
  def test_epsilon_consistency
940
+ @assertion_count = 2
941
+
961
942
  @tc.assert_in_epsilon 1.0, 1.001
962
943
 
963
944
  msg = "Expected |1.0 - 1.001| (0.000999xxx) to not be <= 0.001."
@@ -989,7 +970,7 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
989
970
  def test_assert_includes_triggered
990
971
  @assertion_count = 3
991
972
 
992
- e = @tc.assert_raises MiniTest::Assertion do
973
+ e = @tc.assert_raises Minitest::Assertion do
993
974
  @tc.assert_includes [true], false
994
975
  end
995
976
 
@@ -1180,7 +1161,7 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
1180
1161
  def test_assert_raises_skip
1181
1162
  @assertion_count = 0
1182
1163
 
1183
- util_assert_triggered "skipped", MiniTest::Skip do
1164
+ util_assert_triggered "skipped", Minitest::Skip do
1184
1165
  @tc.assert_raises ArgumentError do
1185
1166
  begin
1186
1167
  raise "blah"
@@ -1192,7 +1173,7 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
1192
1173
  end
1193
1174
 
1194
1175
  def test_assert_raises_triggered_different
1195
- e = assert_raises MiniTest::Assertion do
1176
+ e = assert_raises Minitest::Assertion do
1196
1177
  @tc.assert_raises RuntimeError do
1197
1178
  raise SyntaxError, "icky"
1198
1179
  end
@@ -1214,7 +1195,7 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
1214
1195
  end
1215
1196
 
1216
1197
  def test_assert_raises_triggered_different_msg
1217
- e = assert_raises MiniTest::Assertion do
1198
+ e = assert_raises Minitest::Assertion do
1218
1199
  @tc.assert_raises RuntimeError, "XXX" do
1219
1200
  raise SyntaxError, "icky"
1220
1201
  end
@@ -1237,31 +1218,31 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
1237
1218
  end
1238
1219
 
1239
1220
  def test_assert_raises_triggered_none
1240
- e = assert_raises MiniTest::Assertion do
1241
- @tc.assert_raises MiniTest::Assertion do
1221
+ e = assert_raises Minitest::Assertion do
1222
+ @tc.assert_raises Minitest::Assertion do
1242
1223
  # do nothing
1243
1224
  end
1244
1225
  end
1245
1226
 
1246
- expected = "MiniTest::Assertion expected but nothing was raised."
1227
+ expected = "Minitest::Assertion expected but nothing was raised."
1247
1228
 
1248
1229
  assert_equal expected, e.message
1249
1230
  end
1250
1231
 
1251
1232
  def test_assert_raises_triggered_none_msg
1252
- e = assert_raises MiniTest::Assertion do
1253
- @tc.assert_raises MiniTest::Assertion, "XXX" do
1233
+ e = assert_raises Minitest::Assertion do
1234
+ @tc.assert_raises Minitest::Assertion, "XXX" do
1254
1235
  # do nothing
1255
1236
  end
1256
1237
  end
1257
1238
 
1258
- expected = "XXX.\nMiniTest::Assertion expected but nothing was raised."
1239
+ expected = "XXX.\nMinitest::Assertion expected but nothing was raised."
1259
1240
 
1260
1241
  assert_equal expected, e.message
1261
1242
  end
1262
1243
 
1263
1244
  def test_assert_raises_triggered_subclass
1264
- e = assert_raises MiniTest::Assertion do
1245
+ e = assert_raises Minitest::Assertion do
1265
1246
  @tc.assert_raises StandardError do
1266
1247
  raise AnError
1267
1248
  end
@@ -1390,7 +1371,6 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
1390
1371
 
1391
1372
  def test_capture_subprocess_io
1392
1373
  @assertion_count = 0
1393
- skip "Dunno why but the parallel run of this fails"
1394
1374
 
1395
1375
  non_verbose do
1396
1376
  out, err = capture_subprocess_io do
@@ -1406,7 +1386,7 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
1406
1386
  def test_class_asserts_match_refutes
1407
1387
  @assertion_count = 0
1408
1388
 
1409
- methods = MiniTest::Assertions.public_instance_methods
1389
+ methods = Minitest::Assertions.public_instance_methods
1410
1390
  methods.map! { |m| m.to_s } if Symbol === methods.first
1411
1391
 
1412
1392
  # These don't have corresponding refutes _on purpose_. They're
@@ -1482,7 +1462,7 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
1482
1462
  end
1483
1463
 
1484
1464
  def test_prints
1485
- printer = Class.new { extend MiniTest::Assertions }
1465
+ printer = Class.new { extend Minitest::Assertions }
1486
1466
  @tc.assert_equal '"test"', printer.mu_pp(ImmutableString.new 'test')
1487
1467
  end
1488
1468
 
@@ -1547,7 +1527,7 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
1547
1527
  def test_refute_includes_triggered
1548
1528
  @assertion_count = 3
1549
1529
 
1550
- e = @tc.assert_raises MiniTest::Assertion do
1530
+ e = @tc.assert_raises Minitest::Assertion do
1551
1531
  @tc.refute_includes [true], true
1552
1532
  end
1553
1533
 
@@ -1664,15 +1644,15 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
1664
1644
  def test_skip
1665
1645
  @assertion_count = 0
1666
1646
 
1667
- util_assert_triggered "haha!", MiniTest::Skip do
1647
+ util_assert_triggered "haha!", Minitest::Skip do
1668
1648
  @tc.skip "haha!"
1669
1649
  end
1670
1650
  end
1671
1651
 
1672
- def test_test_methods_random
1652
+ def test_runnable_methods_random
1673
1653
  @assertion_count = 0
1674
1654
 
1675
- sample_test_case = Class.new MiniTest::Unit::TestCase do
1655
+ sample_test_case = Class.new Minitest::Test do
1676
1656
  def self.test_order; :random; end
1677
1657
  def test_test1; assert "does not matter" end
1678
1658
  def test_test2; assert "does not matter" end
@@ -1686,13 +1666,13 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
1686
1666
  else
1687
1667
  %w(test_test2 test_test1 test_test3)
1688
1668
  end
1689
- assert_equal expected, sample_test_case.test_methods
1669
+ assert_equal expected, sample_test_case.runnable_methods
1690
1670
  end
1691
1671
 
1692
- def test_test_methods_sorted
1672
+ def test_runnable_methods_sorted
1693
1673
  @assertion_count = 0
1694
1674
 
1695
- sample_test_case = Class.new MiniTest::Unit::TestCase do
1675
+ sample_test_case = Class.new Minitest::Test do
1696
1676
  def self.test_order; :sorted end
1697
1677
  def test_test3; assert "does not matter" end
1698
1678
  def test_test2; assert "does not matter" end
@@ -1700,13 +1680,13 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
1700
1680
  end
1701
1681
 
1702
1682
  expected = %w(test_test1 test_test2 test_test3)
1703
- assert_equal expected, sample_test_case.test_methods
1683
+ assert_equal expected, sample_test_case.runnable_methods
1704
1684
  end
1705
1685
 
1706
1686
  def test_i_suck_and_my_tests_are_order_dependent_bang_sets_test_order_alpha
1707
1687
  @assertion_count = 0
1708
1688
 
1709
- shitty_test_case = Class.new MiniTest::Unit::TestCase
1689
+ shitty_test_case = Class.new Minitest::Test
1710
1690
 
1711
1691
  shitty_test_case.i_suck_and_my_tests_are_order_dependent!
1712
1692
 
@@ -1716,7 +1696,7 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
1716
1696
  def test_i_suck_and_my_tests_are_order_dependent_bang_does_not_warn
1717
1697
  @assertion_count = 0
1718
1698
 
1719
- shitty_test_case = Class.new MiniTest::Unit::TestCase
1699
+ shitty_test_case = Class.new Minitest::Test
1720
1700
 
1721
1701
  def shitty_test_case.test_order ; :lol end
1722
1702
 
@@ -1725,7 +1705,7 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
1725
1705
  end
1726
1706
  end
1727
1707
 
1728
- def util_assert_triggered expected, klass = MiniTest::Assertion
1708
+ def util_assert_triggered expected, klass = Minitest::Assertion
1729
1709
  e = assert_raises klass do
1730
1710
  yield
1731
1711
  end
@@ -1744,16 +1724,16 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
1744
1724
  end
1745
1725
 
1746
1726
  def without_diff
1747
- old_diff = MiniTest::Assertions.diff
1748
- MiniTest::Assertions.diff = nil
1727
+ old_diff = Minitest::Assertions.diff
1728
+ Minitest::Assertions.diff = nil
1749
1729
 
1750
1730
  yield
1751
1731
  ensure
1752
- MiniTest::Assertions.diff = old_diff
1732
+ Minitest::Assertions.diff = old_diff
1753
1733
  end
1754
1734
  end
1755
1735
 
1756
- class TestMiniTestGuard < MiniTest::Unit::TestCase
1736
+ class TestMinitestGuard < Minitest::Test
1757
1737
  parallelize_me!
1758
1738
 
1759
1739
  def test_mri_eh
@@ -1777,33 +1757,21 @@ class TestMiniTestGuard < MiniTest::Unit::TestCase
1777
1757
  end
1778
1758
  end
1779
1759
 
1780
- class TestMiniTestUnitRecording < MetaMetaMetaTestCase
1760
+ class TestMinitestUnitRecording < MetaMetaMetaTestCase
1781
1761
  # do not parallelize this suite... it just can't handle it.
1782
1762
 
1783
1763
  def assert_run_record(*expected, &block)
1784
- def @tu.record suite, method, assertions, time, error
1785
- recording[method] << error
1786
- end
1787
-
1788
- def @tu.recording
1789
- @recording ||= Hash.new { |h,k| h[k] = [] }
1790
- end
1791
-
1792
- MiniTest::Unit.runner = @tu
1793
-
1794
- Class.new MiniTest::Unit::TestCase, &block
1764
+ @tu = Class.new Minitest::Test, &block
1795
1765
 
1796
- with_output do
1797
- @tu.run
1798
- end
1766
+ run_tu_with_fresh_reporter
1799
1767
 
1800
- recorded = @tu.recording.fetch("test_method").map(&:class)
1768
+ recorded = first_reporter.results.map(&:failures).flatten.map { |f| f.error.class }
1801
1769
 
1802
1770
  assert_equal expected, recorded
1803
1771
  end
1804
1772
 
1805
1773
  def test_record_passing
1806
- assert_run_record NilClass do
1774
+ assert_run_record do
1807
1775
  def test_method
1808
1776
  assert true
1809
1777
  end
@@ -1811,7 +1779,7 @@ class TestMiniTestUnitRecording < MetaMetaMetaTestCase
1811
1779
  end
1812
1780
 
1813
1781
  def test_record_failing
1814
- assert_run_record MiniTest::Assertion do
1782
+ assert_run_record Minitest::Assertion do
1815
1783
  def test_method
1816
1784
  assert false
1817
1785
  end
@@ -1827,7 +1795,7 @@ class TestMiniTestUnitRecording < MetaMetaMetaTestCase
1827
1795
  end
1828
1796
 
1829
1797
  def test_record_error_teardown
1830
- assert_run_record NilClass, RuntimeError do
1798
+ assert_run_record RuntimeError do
1831
1799
  def test_method
1832
1800
  assert true
1833
1801
  end
@@ -1850,8 +1818,36 @@ class TestMiniTestUnitRecording < MetaMetaMetaTestCase
1850
1818
  end
1851
1819
  end
1852
1820
 
1821
+ def test_to_s_error_in_test_and_teardown
1822
+ @tu = Class.new Minitest::Test do
1823
+ def test_method
1824
+ raise AnError
1825
+ end
1826
+
1827
+ def teardown
1828
+ raise "unhandled exception"
1829
+ end
1830
+ end
1831
+
1832
+ run_tu_with_fresh_reporter
1833
+
1834
+ exp = clean "
1835
+ Error:
1836
+ #<Class:0xXXX>#test_method:
1837
+ AnError: AnError
1838
+ FILE:LINE:in `test_method'
1839
+
1840
+ Error:
1841
+ #<Class:0xXXX>#test_method:
1842
+ RuntimeError: unhandled exception
1843
+ FILE:LINE:in `teardown'
1844
+ "
1845
+
1846
+ assert_equal exp.strip, normalize_output(first_reporter.results.first.to_s).strip
1847
+ end
1848
+
1853
1849
  def test_record_skip
1854
- assert_run_record MiniTest::Skip do
1850
+ assert_run_record Minitest::Skip do
1855
1851
  def test_method
1856
1852
  skip "not yet"
1857
1853
  end