minitest 5.0.3 → 5.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data.tar.gz.sig +0 -0
- data/History.txt +10 -0
- data/README.txt +43 -2
- data/lib/minitest.rb +130 -77
- data/lib/minitest/spec.rb +1 -1
- data/lib/minitest/test.rb +2 -2
- data/test/minitest/metametameta.rb +9 -1
- data/test/minitest/test_minitest_reporter.rb +25 -1
- data/test/minitest/test_minitest_unit.rb +3 -3
- metadata +4 -4
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
Binary file
|
data/History.txt
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
=== 5.0.4 / 2013-06-07
|
2
|
+
|
3
|
+
* 5 minor enhancements:
|
4
|
+
|
5
|
+
* Added AbstractReporter, defining required Reporter API to quack properly.
|
6
|
+
* Added doco for writing reporters.
|
7
|
+
* Refactored Reporter into ProgressReporter and SummaryReporter. (idea: phiggins, code:me+scotch)
|
8
|
+
* Refactored SummaryReporter pushing up to StatisticsReporter. (phiggins)
|
9
|
+
* Removed Reporter#run_and_report... cleaner, but doesn't "fit" in the API.
|
10
|
+
|
1
11
|
=== 5.0.3 / 2013-05-29
|
2
12
|
|
3
13
|
* 4 minor enhancements:
|
data/README.txt
CHANGED
@@ -245,12 +245,52 @@ bogus example:
|
|
245
245
|
def self.plugin_bogus_options(opts, options)
|
246
246
|
opts.on "--myci", "Report results to my CI" do
|
247
247
|
options[:myci] = true
|
248
|
+
options[:myci_addr] = get_myci_addr
|
249
|
+
options[:myci_port] = get_myci_port
|
248
250
|
end
|
249
251
|
end
|
250
252
|
|
251
253
|
def self.plugin_bogus_init(options)
|
252
|
-
|
253
|
-
|
254
|
+
self.reporter << MyCI.new(options) if options[:myci]
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
=== Adding custom reporters
|
259
|
+
|
260
|
+
Minitest uses composite reporter to output test results using multiple
|
261
|
+
reporter instances. You can add new reporters to the composite during
|
262
|
+
the init_plugins phase. As we saw in +plugin_bonus_init+ above, you
|
263
|
+
simply add your reporter instance to the composite via +<<+.
|
264
|
+
|
265
|
+
+AbstractReporter+ defines the API for reporters. You may subclass it
|
266
|
+
and override any method you want to achieve your desired behavior.
|
267
|
+
|
268
|
+
start :: Called when the run has started.
|
269
|
+
record :: Called for each result, passed or otherwise.
|
270
|
+
report :: Called at the end of the run.
|
271
|
+
passed? :: Called to see if you detected any problems.
|
272
|
+
|
273
|
+
Using our example above, here is how we might implement MyCI:
|
274
|
+
|
275
|
+
# minitest/bogus_plugin.rb
|
276
|
+
|
277
|
+
module Minitest
|
278
|
+
class MyCI < AbstractReporter
|
279
|
+
attr_accessor :results, :addr, :port
|
280
|
+
|
281
|
+
def initialize options
|
282
|
+
self.results = []
|
283
|
+
self.addr = options[:myci_addr]
|
284
|
+
self.port = options[:myci_port]
|
285
|
+
end
|
286
|
+
|
287
|
+
def record result
|
288
|
+
self.results << result
|
289
|
+
end
|
290
|
+
|
291
|
+
def report
|
292
|
+
CI.connect(addr, port).send_results self.results
|
293
|
+
end
|
254
294
|
end
|
255
295
|
end
|
256
296
|
|
@@ -356,6 +396,7 @@ minitest-instrument :: Instrument ActiveSupport::Notifications when
|
|
356
396
|
minitest-instrument-db :: Store information about speed of test
|
357
397
|
execution provided by minitest-instrument in database
|
358
398
|
minitest-libnotify :: Test notifier for minitest via libnotify.
|
399
|
+
minitest-line :: Run test at line number
|
359
400
|
minitest-macruby :: Provides extensions to minitest for macruby UI testing.
|
360
401
|
minitest-matchers :: Adds support for RSpec-style matchers to minitest.
|
361
402
|
minitest-metadata :: Annotate tests with metadata (key-value).
|
data/lib/minitest.rb
CHANGED
@@ -4,7 +4,7 @@ require "optparse"
|
|
4
4
|
# :include: README.txt
|
5
5
|
|
6
6
|
module Minitest
|
7
|
-
VERSION = "5.0.
|
7
|
+
VERSION = "5.0.4" # :nodoc:
|
8
8
|
|
9
9
|
@@installed_at_exit ||= false
|
10
10
|
@@after_run = []
|
@@ -94,7 +94,7 @@ module Minitest
|
|
94
94
|
# Runnable.runnables.each
|
95
95
|
# runnable.run(reporter, options)
|
96
96
|
# self.runnable_methods.each
|
97
|
-
# self.new.run
|
97
|
+
# self.new(runnable_method).run
|
98
98
|
|
99
99
|
def self.run args = []
|
100
100
|
self.load_plugins
|
@@ -102,15 +102,16 @@ module Minitest
|
|
102
102
|
options = process_args args
|
103
103
|
|
104
104
|
reporter = CompositeReporter.new
|
105
|
-
reporter <<
|
105
|
+
reporter << ProgressReporter.new(options[:io], options)
|
106
|
+
reporter << SummaryReporter.new(options[:io], options)
|
106
107
|
|
107
108
|
self.reporter = reporter # this makes it available to plugins
|
108
109
|
self.init_plugins options
|
109
110
|
self.reporter = nil # runnables shouldn't depend on the reporter, ever
|
110
111
|
|
111
|
-
reporter.
|
112
|
-
|
113
|
-
|
112
|
+
reporter.start
|
113
|
+
__run reporter, options
|
114
|
+
reporter.report
|
114
115
|
|
115
116
|
reporter.passed?
|
116
117
|
end
|
@@ -362,19 +363,38 @@ module Minitest
|
|
362
363
|
end
|
363
364
|
|
364
365
|
##
|
365
|
-
#
|
366
|
+
# Defines the API for Reporters. Subclass this and override whatever
|
367
|
+
# you want. Go nuts.
|
366
368
|
|
367
|
-
class
|
369
|
+
class AbstractReporter
|
368
370
|
##
|
369
|
-
#
|
371
|
+
# Starts reporting on the run.
|
370
372
|
|
371
|
-
|
373
|
+
def start
|
374
|
+
end
|
372
375
|
|
373
376
|
##
|
374
|
-
#
|
377
|
+
# Record a result and output the Runnable#result_code. Stores the
|
378
|
+
# result of the run if the run did not pass.
|
375
379
|
|
376
|
-
|
380
|
+
def record result
|
381
|
+
end
|
377
382
|
|
383
|
+
##
|
384
|
+
# Outputs the summary of the run.
|
385
|
+
|
386
|
+
def report
|
387
|
+
end
|
388
|
+
|
389
|
+
##
|
390
|
+
# Did this run pass?
|
391
|
+
|
392
|
+
def passed?
|
393
|
+
true
|
394
|
+
end
|
395
|
+
end
|
396
|
+
|
397
|
+
class Reporter < AbstractReporter # :nodoc:
|
378
398
|
##
|
379
399
|
# The IO used to report.
|
380
400
|
|
@@ -385,118 +405,151 @@ module Minitest
|
|
385
405
|
|
386
406
|
attr_accessor :options
|
387
407
|
|
388
|
-
|
389
|
-
|
408
|
+
def initialize io = $stdout, options = {} # :nodoc:
|
409
|
+
self.io = io
|
410
|
+
self.options = options
|
411
|
+
end
|
412
|
+
end
|
390
413
|
|
391
|
-
|
414
|
+
##
|
415
|
+
# A very simple reporter that prints the "dots" during the run.
|
416
|
+
#
|
417
|
+
# This is added to the top-level CompositeReporter at the start of
|
418
|
+
# the run. If you want to change the output of minitest via a
|
419
|
+
# plugin, pull this out of the composite and replace it with your
|
420
|
+
# own.
|
392
421
|
|
393
|
-
|
394
|
-
|
422
|
+
class ProgressReporter < Reporter
|
423
|
+
def record result # :nodoc:
|
424
|
+
io.print "%s#%s = %.2f s = " % [result.class, result.name, result.time] if
|
425
|
+
options[:verbose]
|
426
|
+
io.print result.result_code
|
427
|
+
io.puts if options[:verbose]
|
428
|
+
end
|
429
|
+
end
|
395
430
|
|
396
|
-
|
431
|
+
##
|
432
|
+
# A reporter that gathers statistics about a test run. Does not do
|
433
|
+
# any IO because meant to be used as a parent class for a reporter
|
434
|
+
# that does.
|
435
|
+
#
|
436
|
+
# If you want to create an entirely different type of output (eg,
|
437
|
+
# CI, HTML, etc), this is the place to start.
|
397
438
|
|
398
|
-
|
439
|
+
class StatisticsReporter < Reporter
|
440
|
+
# :stopdoc:
|
441
|
+
attr_accessor :assertions
|
442
|
+
attr_accessor :count
|
443
|
+
attr_accessor :results
|
444
|
+
attr_accessor :start_time
|
445
|
+
attr_accessor :total_time
|
446
|
+
attr_accessor :failures
|
447
|
+
attr_accessor :errors
|
448
|
+
attr_accessor :skips
|
449
|
+
# :startdoc:
|
399
450
|
|
400
451
|
def initialize io = $stdout, options = {} # :nodoc:
|
401
|
-
|
402
|
-
self.options = options
|
452
|
+
super
|
403
453
|
|
404
454
|
self.assertions = 0
|
405
455
|
self.count = 0
|
406
456
|
self.results = []
|
407
457
|
self.start_time = nil
|
458
|
+
self.total_time = nil
|
459
|
+
self.failures = nil
|
460
|
+
self.errors = nil
|
461
|
+
self.skips = nil
|
408
462
|
end
|
409
463
|
|
410
|
-
|
411
|
-
# Did this run pass?
|
412
|
-
|
413
|
-
def passed?
|
464
|
+
def passed? # :nodoc:
|
414
465
|
results.all?(&:skipped?)
|
415
466
|
end
|
416
467
|
|
417
|
-
|
418
|
-
|
419
|
-
|
468
|
+
def start # :nodoc:
|
469
|
+
self.start_time = Time.now
|
470
|
+
end
|
420
471
|
|
421
|
-
def
|
422
|
-
|
472
|
+
def record result # :nodoc:
|
473
|
+
self.count += 1
|
474
|
+
self.assertions += result.assertions
|
423
475
|
|
424
|
-
|
476
|
+
results << result if not result.passed? or result.skipped?
|
477
|
+
end
|
425
478
|
|
426
|
-
|
427
|
-
|
479
|
+
def report # :nodoc:
|
480
|
+
aggregate = results.group_by { |r| r.failure.class }
|
481
|
+
aggregate.default = [] # dumb. group_by should provide this
|
482
|
+
|
483
|
+
self.total_time = Time.now - start_time
|
484
|
+
self.failures = aggregate[Assertion].size
|
485
|
+
self.errors = aggregate[UnexpectedError].size
|
486
|
+
self.skips = aggregate[Skip].size
|
428
487
|
end
|
488
|
+
end
|
429
489
|
|
430
|
-
|
431
|
-
|
490
|
+
##
|
491
|
+
# A reporter that prints the header, summary, and failure details at
|
492
|
+
# the end of the run.
|
493
|
+
#
|
494
|
+
# This is added to the top-level CompositeReporter at the start of
|
495
|
+
# the run. If you want to change the output of minitest via a
|
496
|
+
# plugin, pull this out of the composite and replace it with your
|
497
|
+
# own.
|
432
498
|
|
433
|
-
|
434
|
-
|
435
|
-
|
499
|
+
class SummaryReporter < StatisticsReporter
|
500
|
+
# :stopdoc:
|
501
|
+
attr_accessor :sync
|
502
|
+
attr_accessor :old_sync
|
503
|
+
# :startdoc:
|
436
504
|
|
437
|
-
|
505
|
+
def start # :nodoc:
|
506
|
+
super
|
438
507
|
|
439
508
|
io.puts "Run options: #{options[:args]}"
|
440
509
|
io.puts
|
441
510
|
io.puts "# Running:"
|
442
511
|
io.puts
|
443
|
-
end
|
444
|
-
|
445
|
-
##
|
446
|
-
# Record a result and output the Runnable#result_code. Stores the
|
447
|
-
# result of the run if the run did not pass.
|
448
512
|
|
449
|
-
|
450
|
-
self.
|
451
|
-
self.assertions += result.assertions
|
452
|
-
|
453
|
-
io.print "%s#%s = %.2f s = " % [result.class, result.name, result.time] if
|
454
|
-
options[:verbose]
|
455
|
-
io.print result.result_code
|
456
|
-
io.puts if options[:verbose]
|
457
|
-
|
458
|
-
results << result if not result.passed? or result.skipped?
|
513
|
+
self.sync = io.respond_to? :"sync=" # stupid emacs
|
514
|
+
self.old_sync, io.sync = io.sync, true if self.sync
|
459
515
|
end
|
460
516
|
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
def report
|
465
|
-
aggregate = results.group_by { |r| r.failure.class }
|
466
|
-
aggregate.default = [] # dumb. group_by should provide this
|
517
|
+
def report # :nodoc:
|
518
|
+
super
|
467
519
|
|
468
|
-
|
469
|
-
e = aggregate[UnexpectedError].size
|
470
|
-
s = aggregate[Skip].size
|
471
|
-
t = Time.now - start_time
|
520
|
+
io.sync = self.old_sync
|
472
521
|
|
473
522
|
io.puts # finish the dots
|
474
523
|
io.puts
|
475
|
-
io.puts
|
476
|
-
|
477
|
-
|
478
|
-
format = "%d runs, %d assertions, %d failures, %d errors, %d skips"
|
479
|
-
summary = format % [count, self.assertions, f, e, s]
|
480
|
-
|
481
|
-
io.print self
|
482
|
-
io.puts
|
524
|
+
io.puts statistics
|
525
|
+
io.puts aggregated_results
|
483
526
|
io.puts summary
|
484
527
|
end
|
485
528
|
|
486
|
-
def
|
529
|
+
def statistics # :nodoc:
|
530
|
+
"Finished in %.6fs, %.4f runs/s, %.4f assertions/s." %
|
531
|
+
[total_time, count / total_time, assertions / total_time]
|
532
|
+
end
|
533
|
+
|
534
|
+
def aggregated_results # :nodoc:
|
487
535
|
filtered_results = results.dup
|
488
536
|
filtered_results.reject!(&:skipped?) unless options[:verbose]
|
489
537
|
|
490
538
|
filtered_results.each_with_index.map do |result, i|
|
491
539
|
"\n%3d) %s" % [i+1, result]
|
492
|
-
end.join "\n"
|
540
|
+
end.join("\n") + "\n"
|
541
|
+
end
|
542
|
+
|
543
|
+
def summary # :nodoc:
|
544
|
+
"%d runs, %d assertions, %d failures, %d errors, %d skips" %
|
545
|
+
[count, assertions, failures, errors, skips]
|
493
546
|
end
|
494
547
|
end
|
495
548
|
|
496
549
|
##
|
497
550
|
# Dispatch to multiple reporters as one.
|
498
551
|
|
499
|
-
class CompositeReporter <
|
552
|
+
class CompositeReporter < AbstractReporter
|
500
553
|
##
|
501
554
|
# The list of reporters to dispatch to.
|
502
555
|
|
@@ -602,7 +655,7 @@ module Minitest
|
|
602
655
|
##
|
603
656
|
# Provides a simple set of guards that you can use in your tests
|
604
657
|
# to skip execution if it is not applicable. These methods are
|
605
|
-
# mixed into
|
658
|
+
# mixed into Test as both instance and class methods so you
|
606
659
|
# can use them inside or outside of the test methods.
|
607
660
|
#
|
608
661
|
# def test_something_for_mri
|
@@ -624,7 +677,7 @@ module Minitest
|
|
624
677
|
end
|
625
678
|
|
626
679
|
##
|
627
|
-
# Is this running on
|
680
|
+
# Is this running on maglev?
|
628
681
|
|
629
682
|
def maglev? platform = defined?(RUBY_ENGINE) && RUBY_ENGINE
|
630
683
|
"maglev" == platform
|
data/lib/minitest/spec.rb
CHANGED
@@ -197,7 +197,7 @@ class Minitest::Spec < Minitest::Test
|
|
197
197
|
#
|
198
198
|
# This is also aliased to #specify and doesn't require a +desc+ arg.
|
199
199
|
#
|
200
|
-
# Hint: If you _do_ want inheritence, use minitest/
|
200
|
+
# Hint: If you _do_ want inheritence, use minitest/test. You can mix
|
201
201
|
# and match between assertions and expectations as much as you want.
|
202
202
|
|
203
203
|
def it desc = "anonymous", &block
|
data/lib/minitest/test.rb
CHANGED
@@ -25,8 +25,8 @@ module Minitest
|
|
25
25
|
end
|
26
26
|
|
27
27
|
##
|
28
|
-
# Make diffs for this
|
29
|
-
# in assert_equal can
|
28
|
+
# Make diffs for this Test use #pretty_inspect so that diff
|
29
|
+
# in assert_equal can have more details. NOTE: this is much slower
|
30
30
|
# than the regular inspect but much more usable for complex
|
31
31
|
# objects.
|
32
32
|
|
@@ -15,7 +15,11 @@ class MetaMetaMetaTestCase < Minitest::Test
|
|
15
15
|
options = Minitest.process_args flags
|
16
16
|
|
17
17
|
@output = StringIO.new("")
|
18
|
-
|
18
|
+
|
19
|
+
self.reporter = Minitest::CompositeReporter.new
|
20
|
+
reporter << Minitest::SummaryReporter.new(@output, options)
|
21
|
+
reporter << Minitest::ProgressReporter.new(@output, options)
|
22
|
+
|
19
23
|
reporter.start
|
20
24
|
|
21
25
|
@tus ||= [@tu]
|
@@ -28,6 +32,10 @@ class MetaMetaMetaTestCase < Minitest::Test
|
|
28
32
|
reporter.report
|
29
33
|
end
|
30
34
|
|
35
|
+
def first_reporter
|
36
|
+
reporter.reporters.first
|
37
|
+
end
|
38
|
+
|
31
39
|
def assert_report expected, flags = %w[--seed 42]
|
32
40
|
header = clean <<-EOM
|
33
41
|
Run options: #{flags.map { |s| s =~ /\|/ ? s.inspect : s }.join " "}
|
@@ -5,9 +5,33 @@ class TestMinitestReporter < Minitest::Test
|
|
5
5
|
|
6
6
|
attr_accessor :r, :io
|
7
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
|
+
|
8
32
|
def setup
|
9
33
|
self.io = StringIO.new("")
|
10
|
-
self.r =
|
34
|
+
self.r = new_composite_reporter
|
11
35
|
end
|
12
36
|
|
13
37
|
def error_test
|
@@ -432,7 +432,7 @@ class TestMinitestRunner < MetaMetaMetaTestCase
|
|
432
432
|
def self.name; "wacky!" end
|
433
433
|
|
434
434
|
def self.before_my_suite
|
435
|
-
@reporter.io.puts "Running #{self.name} tests"
|
435
|
+
@reporter.reporters.first.io.puts "Running #{self.name} tests"
|
436
436
|
@@foo = 1
|
437
437
|
end
|
438
438
|
|
@@ -1750,7 +1750,7 @@ class TestMinitestUnitRecording < MetaMetaMetaTestCase
|
|
1750
1750
|
|
1751
1751
|
run_tu_with_fresh_reporter
|
1752
1752
|
|
1753
|
-
recorded =
|
1753
|
+
recorded = first_reporter.results.map(&:failures).flatten.map { |f| f.error.class }
|
1754
1754
|
|
1755
1755
|
assert_equal expected, recorded
|
1756
1756
|
end
|
@@ -1828,7 +1828,7 @@ class TestMinitestUnitRecording < MetaMetaMetaTestCase
|
|
1828
1828
|
FILE:LINE:in `teardown'
|
1829
1829
|
"
|
1830
1830
|
|
1831
|
-
assert_equal exp.strip, normalize_output(
|
1831
|
+
assert_equal exp.strip, normalize_output(first_reporter.results.first.to_s).strip
|
1832
1832
|
end
|
1833
1833
|
|
1834
1834
|
def test_record_skip
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minitest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 63
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 5
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 5.0.
|
9
|
+
- 4
|
10
|
+
version: 5.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ryan Davis
|
@@ -36,7 +36,7 @@ cert_chain:
|
|
36
36
|
FBHgymkyj/AOSqKRIpXPhjC6
|
37
37
|
-----END CERTIFICATE-----
|
38
38
|
|
39
|
-
date: 2013-
|
39
|
+
date: 2013-06-07 00:00:00 Z
|
40
40
|
dependencies:
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rdoc
|
metadata.gz.sig
CHANGED
Binary file
|