minitest-reporters 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,22 @@
1
+ coverage
2
+ rdoc
3
+ pkg
4
+ test/tmp
5
+ test/version_tmp
6
+ tmp
7
+ pkg
8
+ *.gem
9
+ *.rbc
10
+ lib/bundler/man
11
+ spec/reports
12
+ .config
13
+ InstalledFiles
14
+ .bundle
15
+
16
+ # YARD artifacts
17
+ .yardoc
18
+ _yardoc
19
+ doc/
20
+
21
+ # Gem-specific
22
+ Gemfile.lock
@@ -0,0 +1,7 @@
1
+ script: 'rake test'
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - ree
6
+ - rbx
7
+ - jruby
@@ -0,0 +1,6 @@
1
+ --readme README.md
2
+ --markup markdown
3
+ --markup-provider maruku
4
+ --default-return ""
5
+ --title "Minitest-reporters Documentation"
6
+ --hide-void-return
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Alexander Kern
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,45 @@
1
+ # minitest-reporters - create customizable MiniTest output formats [![StillMaintained Status](http://stillmaintained.com/CapnKernul/minitest-reporters.png)](http://stillmaintained.com/CapnKernul/minitest-reporters) [![Build Status](http://travis-ci.org/CapnKernul/minitest-reporters.png)](http://travis-ci.org/CapnKernul/minitest-reporters) #
2
+
3
+ Death to haphazard monkey-patching! Extend MiniTest through simple hooks.
4
+
5
+ ## Installation ##
6
+
7
+ gem install minitest-reporters
8
+
9
+ ## Usage ##
10
+
11
+ In your `test_helper.rb` file, add the following lines:
12
+
13
+ require 'minitest/reporters'
14
+ MiniTest::Unit.runner = MiniTest::SuiteRunner.new
15
+ MiniTest::Unit.runner.reporters << MiniTest::Reporters::ProgressReporter.new
16
+
17
+ Now, just run your tests; the reporter you specified will be used and make your
18
+ output look absolutely gorgeous! If you feel the need to write your own
19
+ reporter, just `include MiniTest::Reporter` and override the methods you'd like.
20
+ Take a look at the provided reporters for examples.
21
+
22
+ The following reporters are provided:
23
+
24
+ MiniTest::Reporters::DefaultReporter # => Identical to the standard MiniTest reporter
25
+ MiniTest::Reporters::SpecReporter # => Turn-like output that reads like a spec
26
+ MiniTest::Reporters::ProgressReporter # => Fuubar-like output with a progress bar
27
+
28
+ I really like `ProgressReporter`.
29
+
30
+ ## Note on Patches/Pull Requests ##
31
+
32
+ * Fork the project.
33
+ * Make your feature addition or bug fix.
34
+ * Add tests for it. This is important so I don't break it in a future version unintentionally.
35
+ * Commit, but do not mess with the `Rakefile`. If you want to have your own version, that is fine but bump the version in a commit by itself in another branch so I can ignore it when I pull.
36
+ * Send me a pull request. Bonus points for git flow feature branches.
37
+
38
+ ## Resources ##
39
+
40
+ * [GitHub Repository](https://github.com/CapnKernul/minitest-reporters)
41
+ * [Documentation](http://rubydoc.info/github/CapnKernul/minitest-reporters)
42
+
43
+ ## License ##
44
+
45
+ Minitest-reporters is licensed under the MIT License. See `LICENSE` for details.
@@ -0,0 +1,11 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ task :default => :test
5
+
6
+ require 'rake/testtask'
7
+ Rake::TestTask.new do |t|
8
+ t.ruby_opts += ['-rubygems']
9
+ t.libs << 'test'
10
+ t.pattern = 'test/**/*_test.rb'
11
+ end
@@ -0,0 +1,33 @@
1
+ module MiniTest
2
+ module Reporter
3
+ def runner
4
+ MiniTest::Unit.runner
5
+ end
6
+
7
+ def output
8
+ runner.output
9
+ end
10
+
11
+ def verbose?
12
+ runner.verbose
13
+ end
14
+
15
+ def print(*args)
16
+ runner.output.print(*args)
17
+ end
18
+
19
+ def puts(*args)
20
+ runner.output.puts(*args)
21
+ end
22
+
23
+ def before_suites(suites, type); end
24
+ def after_suites(suites, type); end
25
+ def before_suite(suite); end
26
+ def after_suite(suite); end
27
+ def before_test(suite, test); end
28
+ def pass(suite, test, test_runner); end
29
+ def skip(suite, test, test_runner); end
30
+ def failure(suite, test, test_runner); end
31
+ def error(suite, test, test_runner); end
32
+ end
33
+ end
@@ -0,0 +1,15 @@
1
+ require 'minitest/unit'
2
+
3
+ module MiniTest
4
+ autoload :Reporter, 'minitest/reporter'
5
+ autoload :SuiteRunner, 'minitest/suite_runner'
6
+ autoload :TestRunner, 'minitest/test_runner'
7
+
8
+ module Reporters
9
+ require 'minitest/reporters/version'
10
+
11
+ autoload :DefaultReporter, 'minitest/reporters/default_reporter'
12
+ autoload :SpecReporter, 'minitest/reporters/spec_reporter'
13
+ autoload :ProgressReporter, 'minitest/reporters/progress_reporter'
14
+ end
15
+ end
@@ -0,0 +1,105 @@
1
+ require 'ansi'
2
+
3
+ module MiniTest
4
+ module Reporters
5
+ # A reporter identical to the standard MiniTest reporter.
6
+ #
7
+ # Based upon Ryan Davis of Seattle.rb's MiniTest (MIT License).
8
+ #
9
+ # @see https://github.com/seattlerb/minitest MiniTest
10
+ class DefaultReporter
11
+ include MiniTest::Reporter
12
+
13
+ def before_suites(suites, type)
14
+ puts
15
+ puts "# Running #{type}s:"
16
+ puts
17
+ end
18
+
19
+ def before_test(suite, test)
20
+ print "#{suite}##{method} = " if verbose?
21
+ end
22
+
23
+ def pass(suite, test, test_runner)
24
+ after_test('.')
25
+ end
26
+
27
+ def skip(suite, test, test_runner)
28
+ after_test('S')
29
+ end
30
+
31
+ def failure(suite, test, test_runner)
32
+ after_test('F')
33
+ end
34
+
35
+ def error(suite, test, test_runner)
36
+ after_test('E')
37
+ end
38
+
39
+ def after_suites(suites, type)
40
+ time = Time.now - runner.start_time
41
+
42
+ puts
43
+ puts
44
+ puts "Finished #{type}s in %.6fs, %.4f tests/s, %.4f assertions/s." %
45
+ [time, runner.test_count / time, runner.assertion_count / time]
46
+
47
+ i = 0
48
+ runner.report.each do |suite, tests|
49
+ tests.each do |test, test_runner|
50
+ message = message_for(test_runner)
51
+ if message
52
+ i += 1
53
+ puts "\n%3d) %s" % [i, message]
54
+ end
55
+ end
56
+ end
57
+
58
+ puts
59
+
60
+ puts status
61
+ end
62
+
63
+ private
64
+
65
+ def after_test(result)
66
+ time = Time.now - runner.test_start_time
67
+
68
+ print '%.2f s = ' % time if verbose?
69
+ print result
70
+ puts if verbose?
71
+ end
72
+
73
+ def location(exception)
74
+ last_before_assertion = ''
75
+
76
+ exception.backtrace.reverse_each do |s|
77
+ break if s =~ /in .(assert|refute|flunk|pass|fail|raise|must|wont)/
78
+ last_before_assertion = s
79
+ end
80
+
81
+ last_before_assertion.sub(/:in .*$/, '')
82
+ end
83
+
84
+ def message_for(test_runner)
85
+ suite = test_runner.suite
86
+ test = test_runner.test
87
+ e = test_runner.exception
88
+
89
+ case test_runner.result
90
+ when :pass then nil
91
+ when :skip then "Skipped:\n#{test}(#{suite}) [#{location(e)}]:\n#{e.message}\n"
92
+ when :failure then "Failure:\n#{test}(#{suite}) [#{location(e)}]:\n#{e.message}\n"
93
+ when :error
94
+ bt = MiniTest::filter_backtrace(test_runner.exception.backtrace).join "\n "
95
+ "Error:\n#{test}(#{suite}):\n#{e.class}: #{e.message}\n #{bt}\n"
96
+ end
97
+ end
98
+
99
+ def status
100
+ '%d tests, %d assertions, %d failures, %d errors, %d skips' %
101
+ [runner.test_count, runner.assertion_count, runner.failures, runner.errors, runner.skips]
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,108 @@
1
+ require 'ansi'
2
+ require 'progressbar'
3
+
4
+ module MiniTest
5
+ module Reporters
6
+ # Fuubar-like reporter with a progress bar.
7
+ #
8
+ # Based upon Jeff Kreefmeijer's Fuubar (MIT License) and paydro's
9
+ # monkey-patch.
10
+ #
11
+ # @see https://github.com/jeffkreeftmeijer/fuubar Fuubar
12
+ # @see https://gist.github.com/356945 paydro's monkey-patch
13
+ class ProgressReporter
14
+ include MiniTest::Reporter
15
+ include ANSI::Code
16
+
17
+ INFO_PADDING = 2
18
+
19
+ def before_suites(suites, type)
20
+ puts 'Started'
21
+ puts
22
+
23
+ @color = GREEN
24
+ @finished_count = 0
25
+ @progress = ProgressBar.new("0/#{runner.test_count}", runner.test_count, runner.output)
26
+ @progress.bar_mark = '='
27
+ end
28
+
29
+ def increment
30
+ with_color do
31
+ @finished_count += 1
32
+ @progress.instance_variable_set('@title', "#{@finished_count}/#{runner.test_count}")
33
+ @progress.inc
34
+ end
35
+ end
36
+
37
+ def pass(suite, test, test_runner)
38
+ increment
39
+ end
40
+
41
+ def skip(suite, test, test_runner)
42
+ @color = YELLOW unless @color == RED
43
+ print(yellow { 'SKIP' })
44
+ print_test_with_time(suite, test)
45
+ puts
46
+ puts
47
+ increment
48
+ end
49
+
50
+ def failure(suite, test, test_runner)
51
+ @color = RED
52
+ print(red { 'FAIL' })
53
+ print_test_with_time(suite, test)
54
+ puts
55
+ print_info(test_runner.exception)
56
+ puts
57
+ increment
58
+ end
59
+
60
+ def error(suite, test, test_runner)
61
+ @color = RED
62
+ print(red { 'ERROR' })
63
+ print_test_with_time(suite, test)
64
+ puts
65
+ print_info(test_runner.exception)
66
+ puts
67
+ increment
68
+ end
69
+
70
+ def after_suites(suites, type)
71
+ with_color { @progress.finish }
72
+
73
+ total_time = Time.now - runner.start_time
74
+
75
+ puts
76
+ puts('Finished in %.5fs' % total_time)
77
+ print('%d tests, %d assertions, ' % [runner.test_count, runner.assertion_count])
78
+ print(red { '%d failures, %d errors, ' } % [runner.failures, runner.errors])
79
+ print(yellow { '%d skips' } % runner.skips)
80
+ puts
81
+ end
82
+
83
+ private
84
+
85
+ def print_test_with_time(suite, test)
86
+ total_time = Time.now - runner.test_start_time
87
+ print(" #{suite}##{test} (%.2fs)#{clr}" % total_time)
88
+ end
89
+
90
+ def print_info(e)
91
+ e.message.each_line { |line| puts pad(line) }
92
+
93
+ trace = MiniTest.filter_backtrace(e.backtrace)
94
+ trace.each { |line| puts pad(line) }
95
+ end
96
+
97
+ def pad(str)
98
+ ' ' * INFO_PADDING + str
99
+ end
100
+
101
+ def with_color
102
+ print @color
103
+ yield
104
+ print CLEAR
105
+ end
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,93 @@
1
+ require 'ansi'
2
+
3
+ module MiniTest
4
+ module Reporters
5
+ # Turn-like reporter that reads like a spec.
6
+ #
7
+ # Based upon TwP's turn (MIT License) and paydro's monkey-patch.
8
+ #
9
+ # @see https://github.com/TwP/turn turn
10
+ # @see https://gist.github.com/356945 paydro's monkey-patch
11
+ class SpecReporter
12
+ include MiniTest::Reporter
13
+ include ANSI::Code
14
+
15
+ TEST_PADDING = 2
16
+ INFO_PADDING = 8
17
+ MARK_SIZE = 5
18
+
19
+ def before_suites(suites, type)
20
+ puts 'Started'
21
+ puts
22
+ end
23
+
24
+ def after_suites(suites, type)
25
+ total_time = Time.now - runner.start_time
26
+
27
+ puts('Finished in %.5fs' % total_time)
28
+ print('%d tests, %d assertions, ' % [runner.test_count, runner.assertion_count])
29
+ print(red { '%d failures, %d errors, ' } % [runner.failures, runner.errors])
30
+ print(yellow { '%d skips' } % runner.skips)
31
+ puts
32
+ end
33
+
34
+ def before_suite(suite)
35
+ puts suite
36
+ end
37
+
38
+ def after_suite(suite)
39
+ puts
40
+ end
41
+
42
+ def pass(suite, test, test_runner)
43
+ print(green { pad_mark('PASS') })
44
+ print_test_with_time(test)
45
+ puts
46
+ end
47
+
48
+ def skip(suite, test, test_runner)
49
+ print(yellow { pad_mark('SKIP') })
50
+ print_test_with_time(test)
51
+ puts
52
+ end
53
+
54
+ def failure(suite, test, test_runner)
55
+ print(red { pad_mark('FAIL') })
56
+ print_test_with_time(test)
57
+ puts
58
+ print_info(test_runner.exception)
59
+ puts
60
+ end
61
+
62
+ def error(suite, test, test_runner)
63
+ print(red { pad_mark('ERROR') })
64
+ print_test_with_time(test)
65
+ puts
66
+ print_info(test_runner.exception)
67
+ puts
68
+ end
69
+
70
+ private
71
+
72
+ def print_test_with_time(test)
73
+ total_time = Time.now - runner.test_start_time
74
+ print(" #{test} (%.2fs)" % total_time)
75
+ end
76
+
77
+ def print_info(e)
78
+ e.message.each_line { |line| puts pad(line, INFO_PADDING) }
79
+
80
+ trace = MiniTest.filter_backtrace(e.backtrace)
81
+ trace.each { |line| puts pad(line, INFO_PADDING) }
82
+ end
83
+
84
+ def pad(str, size)
85
+ ' ' * size + str
86
+ end
87
+
88
+ def pad_mark(str)
89
+ pad("%#{MARK_SIZE}s" % str, TEST_PADDING)
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,5 @@
1
+ module MiniTest
2
+ module Reporters
3
+ VERSION = '0.3.0'
4
+ end
5
+ end
@@ -0,0 +1,110 @@
1
+ module MiniTest
2
+ # Runner for MiniTest suites.
3
+ #
4
+ # This is a heavily refactored version of the built-in MiniTest runner. It's
5
+ # about the same speed, from what I can tell, but is significantly easier to
6
+ # extend.
7
+ #
8
+ # Based upon Ryan Davis of Seattle.rb's MiniTest (MIT License).
9
+ #
10
+ # @see https://github.com/seattlerb/minitest MiniTest
11
+ class SuiteRunner < MiniTest::Unit
12
+ attr_accessor :suite_start_time, :test_start_time, :reporters
13
+
14
+ def initialize
15
+ self.report = {}
16
+ self.errors = 0
17
+ self.failures = 0
18
+ self.skips = 0
19
+ self.test_count = 0
20
+ self.assertion_count = 0
21
+ self.verbose = false
22
+ self.reporters = []
23
+ end
24
+
25
+ def _run_anything(type)
26
+ self.start_time = Time.now
27
+
28
+ suites = suites_of_type(type)
29
+ tests = suites.inject({}) do |acc, suite|
30
+ acc[suite] = filtered_tests(suite, type)
31
+ acc
32
+ end
33
+
34
+ self.test_count = tests.inject(0) { |acc, suite| acc + suite[1].length }
35
+
36
+ if test_count > 0
37
+ trigger(:before_suites, suites, type)
38
+
39
+ fix_sync do
40
+ suites.each { |suite| _run_suite(suite, tests[suite]) }
41
+ end
42
+
43
+ trigger(:after_suites, suites, type)
44
+ end
45
+ end
46
+
47
+ def _run_suite(suite, tests)
48
+ unless tests.empty?
49
+ begin
50
+ self.suite_start_time = Time.now
51
+
52
+ trigger(:before_suite, suite)
53
+ suite.startup if suite.respond_to?(:startup)
54
+
55
+ tests.each { |test| _run_test(suite, test) }
56
+ ensure
57
+ suite.shutdown if suite.respond_to?(:shutdown)
58
+ trigger(:after_suite, suite)
59
+ end
60
+ end
61
+ end
62
+
63
+ def _run_test(suite, test)
64
+ self.test_start_time = Time.now
65
+ trigger(:before_test, suite, test)
66
+
67
+ test_runner = TestRunner.new(suite, test)
68
+ test_runner.run
69
+ add_test_result(suite, test, test_runner)
70
+
71
+ trigger(test_runner.result, suite, test, test_runner)
72
+ end
73
+
74
+ def trigger(callback, *args)
75
+ reporters.each { |reporter| reporter.send(callback, *args) }
76
+ end
77
+
78
+ private
79
+
80
+ def filtered_tests(suite, type)
81
+ filter = options[:filter] || '/./'
82
+ filter = Regexp.new($1) if filter =~ /\/(.*)\//
83
+ suite.send("#{type}_methods").grep(filter)
84
+ end
85
+
86
+ def suites_of_type(type)
87
+ TestCase.send("#{type}_suites")
88
+ end
89
+
90
+ def add_test_result(suite, test, test_runner)
91
+ self.report[suite] ||= {}
92
+ self.report[suite][test.to_sym] = test_runner
93
+
94
+ self.assertion_count += test_runner.assertions
95
+
96
+ case test_runner.result
97
+ when :skip then self.skips += 1
98
+ when :failure then self.failures += 1
99
+ when :error then self.errors += 1
100
+ end
101
+ end
102
+
103
+ def fix_sync
104
+ sync = output.respond_to?(:'sync=') # stupid emacs
105
+ old_sync, output.sync = output.sync, true if sync
106
+ yield
107
+ output.sync = old_sync if sync
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,39 @@
1
+ module MiniTest
2
+ # Runner for individual MiniTest tests.
3
+ #
4
+ # You *should not* create instances of this class directly. Instances of
5
+ # {SuiteRunner} will create these and send them to the reporters.
6
+ #
7
+ # Based upon Ryan Davis of Seattle.rb's MiniTest (MIT License).
8
+ #
9
+ # @see https://github.com/seattlerb/minitest MiniTest
10
+ class TestRunner
11
+ attr_reader :suite, :test, :assertions, :result, :exception
12
+
13
+ def initialize(suite, test)
14
+ @suite = suite
15
+ @test = test
16
+ @assertions = 0
17
+ end
18
+
19
+ def run
20
+ suite_instance = suite.new(test)
21
+ @result, @exception = fix_result(suite_instance.run(self))
22
+ @assertions = suite_instance._assertions
23
+ end
24
+
25
+ def puke(suite, test, exception)
26
+ case exception
27
+ when MiniTest::Skip then [:skip, exception]
28
+ when MiniTest::Assertion then [:failure, exception]
29
+ else [:error, exception]
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def fix_result(result)
36
+ result == '.' ? [:pass, nil] : result
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'minitest/reporters/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'minitest-reporters'
7
+ s.version = MiniTest::Reporters::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ['Alexander Kern']
10
+ s.email = ['alex@kernul.com']
11
+ s.homepage = 'https://github.com/CapnKernul/minitest-reporters'
12
+ s.summary = %q{Create customizable MiniTest output formats}
13
+ s.description = %q{Death to haphazard monkey-patching! Extend MiniTest through simple hooks.}
14
+
15
+ s.rubyforge_project = 'minitest-reporters'
16
+
17
+ s.add_dependency 'minitest', '~> 2.0'
18
+ s.add_dependency 'ansi'
19
+ s.add_dependency 'ruby-progressbar'
20
+
21
+ s.add_development_dependency 'mocha'
22
+ s.add_development_dependency 'maruku'
23
+ s.add_development_dependency 'test_declarative'
24
+
25
+ s.files = `git ls-files`.split("\n")
26
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
27
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
28
+ s.require_paths = ['lib']
29
+ end
@@ -0,0 +1,49 @@
1
+ require 'test_helper'
2
+
3
+ module MiniTestReportersTest
4
+ class ReporterTest < TestCase
5
+ def setup
6
+ klass = Class.new do
7
+ include MiniTest::Reporter
8
+ end
9
+
10
+ @reporter = klass.new
11
+ end
12
+
13
+ test 'callbacks' do
14
+ [
15
+ :before_suites, :after_suite, :before_suite, :after_suite, :before_test,
16
+ :pass, :skip, :failure, :error
17
+ ].each { |method| assert_respond_to @reporter, method }
18
+ end
19
+
20
+ test '#runner' do
21
+ assert_kind_of MiniTest::Unit, @reporter.runner
22
+ end
23
+
24
+ test '#output' do
25
+ assert_equal MiniTest::Unit.output, @reporter.output
26
+ end
27
+
28
+ test '#verbose?' do
29
+ refute @reporter.verbose?
30
+
31
+ begin
32
+ @reporter.runner.verbose = true
33
+ assert @reporter.verbose?
34
+ ensure
35
+ @reporter.runner.verbose = false
36
+ end
37
+ end
38
+
39
+ test '#print' do
40
+ @reporter.output.expects(:print).with('foo')
41
+ @reporter.print('foo')
42
+ end
43
+
44
+ test '#puts' do
45
+ @reporter.output.expects(:puts).with('foo')
46
+ @reporter.puts('foo')
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,164 @@
1
+ require 'test_helper'
2
+
3
+ module MiniTestReportersTest
4
+ class SuiteRunnerTest < TestCase
5
+ def setup
6
+ @runner = MiniTest::SuiteRunner.new
7
+ @reporter = add_reporter
8
+ end
9
+
10
+ test '#report' do
11
+ assert_equal({}, @runner.report)
12
+ end
13
+
14
+ test '#reporters' do
15
+ assert_equal [@reporter], @runner.reporters
16
+
17
+ reporter2 = add_reporter
18
+ assert_equal [@reporter, reporter2], @runner.reporters
19
+ end
20
+
21
+ test '#_run_anything with no suites' do
22
+ stub_suites([])
23
+
24
+ @reporter.expects(:before_suites).never
25
+ @reporter.expects(:after_suites).never
26
+
27
+ @runner._run_anything(:test)
28
+
29
+ assert_equal 0, @runner.test_count
30
+ assert_equal 0, @runner.assertion_count
31
+ assert_instance_of Time, @runner.start_time
32
+ assert_equal({}, @runner.report)
33
+ end
34
+
35
+ test '#_run_anything with suites' do
36
+ suites = [Fixtures::PassTestFixture, Fixtures::SkipTestFixture]
37
+ stub_suites(suites)
38
+
39
+ @reporter.expects(:before_suites).with(suites, :test)
40
+ @reporter.expects(:after_suites).with(suites, :test)
41
+
42
+ @runner._run_anything(:test)
43
+
44
+ assert_equal 3, @runner.test_count
45
+ assert_equal 3, @runner.assertion_count
46
+ assert_instance_of Time, @runner.start_time
47
+ assert_equal :pass, @runner.report[Fixtures::PassTestFixture][:test_pass].result
48
+ assert_equal :pass, @runner.report[Fixtures::PassTestFixture][:test_foo].result
49
+ assert_equal :skip, @runner.report[Fixtures::SkipTestFixture][:test_skip].result
50
+ end
51
+
52
+ test '#_run_anything with a filter' do
53
+ @runner.options[:filter] = '/foo/'
54
+ stub_suites([Fixtures::PassTestFixture])
55
+
56
+ @runner._run_anything(:test)
57
+ assert_equal 2, @runner.assertion_count
58
+ end
59
+
60
+ test '#_run_suite without tests' do
61
+ @reporter.expects(:before_suite).never
62
+ @reporter.expects(:after_suite).never
63
+
64
+ @runner._run_suite(Fixtures::EmptyTestFixture, [])
65
+ end
66
+
67
+ test '#_run_suite with tests' do
68
+ @reporter.expects(:before_suite).with(Fixtures::PassTestFixture)
69
+ @reporter.expects(:after_suite).with(Fixtures::PassTestFixture)
70
+
71
+ @runner._run_suite(Fixtures::PassTestFixture, [:test_pass, :test_foo])
72
+
73
+ assert_equal 3, @runner.assertion_count
74
+ assert_instance_of Time, @runner.suite_start_time
75
+ end
76
+
77
+ test '#_run_suite with a suite .startup and .shutdown' do
78
+ suite = Fixtures::SuiteCallbackTestFixture
79
+ suite.expects(:startup)
80
+ suite.expects(:shutdown)
81
+ @runner._run_suite(suite, [:test_foo])
82
+ end
83
+
84
+ test '#_run_test with a passing test' do
85
+ suite = Fixtures::PassTestFixture
86
+ test = :test_pass
87
+
88
+ @reporter.expects(:before_test).with(suite, test)
89
+ @reporter.expects(:pass).with(suite, test, instance_of(MiniTest::TestRunner))
90
+
91
+ @runner._run_test(suite, test)
92
+
93
+ assert_equal 1, @runner.assertion_count
94
+ assert_instance_of Time, @runner.test_start_time
95
+ assert_equal :pass, @runner.report[suite][test].result
96
+ end
97
+
98
+ test '#_run_test with a skipped test' do
99
+ suite = Fixtures::SkipTestFixture
100
+ test = :test_skip
101
+
102
+ @reporter.expects(:before_test).with(suite, test)
103
+ @reporter.expects(:skip).with(suite, test, instance_of(MiniTest::TestRunner))
104
+
105
+ @runner._run_test(suite, test)
106
+
107
+ assert_equal 0, @runner.assertion_count
108
+ assert_instance_of Time, @runner.test_start_time
109
+ assert_equal :skip, @runner.report[suite][test].result
110
+ end
111
+
112
+ test '#_run_test with a failing test' do
113
+ suite = Fixtures::FailureTestFixture
114
+ test = :test_failure
115
+
116
+ @reporter.expects(:before_test).with(suite, test)
117
+ @reporter.expects(:failure).with(suite, test, instance_of(MiniTest::TestRunner))
118
+
119
+ @runner._run_test(suite, test)
120
+
121
+ assert_equal 0, @runner.assertion_count
122
+ assert_instance_of Time, @runner.test_start_time
123
+ assert_equal :failure, @runner.report[suite][test].result
124
+ end
125
+
126
+ test '#_run_test with an error test' do
127
+ suite = Fixtures::ErrorTestFixture
128
+ test = :test_error
129
+
130
+ @reporter.expects(:before_test).with(suite, test)
131
+ @reporter.expects(:error).with(suite, test, instance_of(MiniTest::TestRunner))
132
+
133
+ @runner._run_test(suite, test)
134
+
135
+ assert_equal 0, @runner.assertion_count
136
+ assert_instance_of Time, @runner.test_start_time
137
+ assert_equal :error, @runner.report[suite][test].result
138
+ end
139
+
140
+ test '#trigger' do
141
+ reporter2 = add_reporter
142
+ @reporter.expects(:before_suite).with(Fixtures::PassTestFixture)
143
+ reporter2.expects(:before_suite).with(Fixtures::PassTestFixture)
144
+
145
+ @runner.trigger(:before_suite, Fixtures::PassTestFixture)
146
+ end
147
+
148
+ private
149
+
150
+ def add_reporter
151
+ klass = Class.new do
152
+ include MiniTest::Reporter
153
+ end
154
+
155
+ reporter = klass.new
156
+ @runner.reporters << reporter
157
+ reporter
158
+ end
159
+
160
+ def stub_suites(suites)
161
+ MiniTest::Unit::TestCase.stubs(:test_suites).returns(suites)
162
+ end
163
+ end
164
+ end
@@ -0,0 +1,91 @@
1
+ require 'test_helper'
2
+
3
+ module MiniTestReportersTest
4
+ class TestRunnerTest < TestCase
5
+ def setup
6
+ @suite = stub
7
+ @test = :test_foo
8
+ @runner = MiniTest::TestRunner.new(@suite, @test)
9
+ end
10
+
11
+ test '#suite' do
12
+ assert_equal @suite, @runner.suite
13
+ end
14
+
15
+ test '#test' do
16
+ assert_equal @test, @runner.test
17
+ end
18
+
19
+ test '#run with a passing test' do
20
+ suite_instance = stub(:_assertions => 3)
21
+ suite_instance.expects(:run).with(@runner).returns('.')
22
+ @suite.stubs(:new).with(@test).returns(suite_instance)
23
+
24
+ @runner.run
25
+
26
+ assert_equal :pass, @runner.result
27
+ assert_nil @runner.exception
28
+ assert_equal 3, @runner.assertions
29
+ end
30
+
31
+ test '#run with an skipped test' do
32
+ error = stub
33
+ suite_instance = stub(:_assertions => 3)
34
+ suite_instance.expects(:run).with(@runner).returns([:skip, error])
35
+ @suite.stubs(:new).with(@test).returns(suite_instance)
36
+
37
+ @runner.run
38
+
39
+ assert_equal :skip, @runner.result
40
+ assert_equal error, @runner.exception
41
+ assert_equal 3, @runner.assertions
42
+ end
43
+
44
+ test '#run with a failing test' do
45
+ error = stub
46
+ suite_instance = stub(:_assertions => 3)
47
+ suite_instance.expects(:run).with(@runner).returns([:failure, error])
48
+ @suite.stubs(:new).with(@test).returns(suite_instance)
49
+
50
+ @runner.run
51
+
52
+ assert_equal :failure, @runner.result
53
+ assert_equal error, @runner.exception
54
+ assert_equal 3, @runner.assertions
55
+ end
56
+
57
+ test '#run with an errored test' do
58
+ error = stub
59
+ suite_instance = stub(:_assertions => 3)
60
+ suite_instance.expects(:run).with(@runner).returns([:error, error])
61
+ @suite.stubs(:new).with(@test).returns(suite_instance)
62
+
63
+ @runner.run
64
+
65
+ assert_equal :error, @runner.result
66
+ assert_equal error, @runner.exception
67
+ assert_equal 3, @runner.assertions
68
+ end
69
+
70
+ test '#puke with a skip' do
71
+ skip = MiniTest::Skip.new
72
+ result = @runner.puke(@suite, @test, skip)
73
+
74
+ assert_equal [:skip, skip], result
75
+ end
76
+
77
+ test '#puke with a failure' do
78
+ failure = MiniTest::Assertion.new
79
+ result = @runner.puke(@suite, @test, failure)
80
+
81
+ assert_equal [:failure, failure], result
82
+ end
83
+
84
+ test '#puke with an error' do
85
+ error = RuntimeError.new
86
+ result = @runner.puke(@suite, @test, error)
87
+
88
+ assert_equal [:error, error], result
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,5 @@
1
+ module MiniTestReportersTest
2
+ module Fixtures
3
+ class EmptyTestFixture < TestCaseFixture; end
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ module MiniTestReportersTest
2
+ module Fixtures
3
+ class ErrorTestFixture < TestCaseFixture
4
+ def test_error
5
+ raise RuntimeError.new
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module MiniTestReportersTest
2
+ module Fixtures
3
+ class FailureTestFixture < TestCaseFixture
4
+ def test_failure
5
+ flunk
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ module MiniTestReportersTest
2
+ module Fixtures
3
+ class PassTestFixture < TestCaseFixture
4
+ def test_pass
5
+ assert true
6
+ end
7
+
8
+ def test_foo
9
+ assert true
10
+ assert true
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ module MiniTestReportersTest
2
+ module Fixtures
3
+ class SkipTestFixture < TestCaseFixture
4
+ def test_skip
5
+ skip
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module MiniTestReportersTest
2
+ module Fixtures
3
+ class SuiteCallbackTestFixture < TestCaseFixture
4
+ def self.startup; end
5
+ def self.shutdown; end
6
+ def test_foo; end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,38 @@
1
+ module MiniTestReportersTest
2
+ module Fixtures
3
+ class TestCaseFixture
4
+ attr_writer :_assertions
5
+
6
+ def self.test_methods
7
+ public_instance_methods(true).grep(/^test/)
8
+ end
9
+
10
+ def initialize(test)
11
+ @test = test
12
+ end
13
+
14
+ def run(runner)
15
+ send(@test)
16
+ '.'
17
+ rescue MiniTest::Assertion, RuntimeError => e
18
+ runner.puke(self, @test, e)
19
+ end
20
+
21
+ def skip
22
+ raise MiniTest::Skip.new
23
+ end
24
+
25
+ def flunk
26
+ raise MiniTest::Assertion.new
27
+ end
28
+
29
+ def assert(value)
30
+ self._assertions += 1
31
+ end
32
+
33
+ def _assertions
34
+ @_assertions ||= 0
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,4 @@
1
+ module MiniTestReportersTest
2
+ class TestCase < MiniTest::Unit::TestCase
3
+ end
4
+ end
@@ -0,0 +1,33 @@
1
+ require 'bundler/setup'
2
+ require 'minitest/autorun'
3
+ require 'mocha'
4
+ require 'test_declarative'
5
+ require 'minitest/reporters'
6
+
7
+ module MiniTestReportersTest
8
+ require File.expand_path('../support/test_case', __FILE__)
9
+
10
+ module Fixtures
11
+ require File.expand_path('../support/fixtures/test_case_fixture', __FILE__)
12
+ require File.expand_path('../support/fixtures/empty_test_fixture', __FILE__)
13
+ require File.expand_path('../support/fixtures/error_test_fixture', __FILE__)
14
+ require File.expand_path('../support/fixtures/failure_test_fixture', __FILE__)
15
+ require File.expand_path('../support/fixtures/pass_test_fixture', __FILE__)
16
+ require File.expand_path('../support/fixtures/skip_test_fixture', __FILE__)
17
+ require File.expand_path('../support/fixtures/suite_callback_test_fixture', __FILE__)
18
+ end
19
+ end
20
+
21
+ MiniTest::Unit.runner = MiniTest::SuiteRunner.new
22
+
23
+ # Testing the built-in reporters using automated unit testing would be extremely
24
+ # brittle. Consequently, there are no unit tests for them. Instead, uncomment
25
+ # the reporter that you'd like to test and run the full test suite. Make sure to
26
+ # try them with skipped, failing, and error tests as well!
27
+ #
28
+ # Personally, I like the progress reporter. Make sure you don't change that line
29
+ # when you commit.
30
+ #
31
+ # MiniTest::Unit.runner.reporters << MiniTest::Reporters::DefaultReporter.new
32
+ # MiniTest::Unit.runner.reporters << MiniTest::Reporters::SpecReporter.new
33
+ MiniTest::Unit.runner.reporters << MiniTest::Reporters::ProgressReporter.new
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: minitest-reporters
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alexander Kern
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-08-27 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: minitest
16
+ requirement: &2156845360 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2156845360
25
+ - !ruby/object:Gem::Dependency
26
+ name: ansi
27
+ requirement: &2156875140 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2156875140
36
+ - !ruby/object:Gem::Dependency
37
+ name: ruby-progressbar
38
+ requirement: &2156874680 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *2156874680
47
+ - !ruby/object:Gem::Dependency
48
+ name: mocha
49
+ requirement: &2156874260 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *2156874260
58
+ - !ruby/object:Gem::Dependency
59
+ name: maruku
60
+ requirement: &2156873840 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *2156873840
69
+ - !ruby/object:Gem::Dependency
70
+ name: test_declarative
71
+ requirement: &2156873420 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *2156873420
80
+ description: Death to haphazard monkey-patching! Extend MiniTest through simple hooks.
81
+ email:
82
+ - alex@kernul.com
83
+ executables: []
84
+ extensions: []
85
+ extra_rdoc_files: []
86
+ files:
87
+ - .gitignore
88
+ - .travis.yml
89
+ - .yardopts
90
+ - Gemfile
91
+ - LICENSE
92
+ - README.md
93
+ - Rakefile
94
+ - lib/minitest/reporter.rb
95
+ - lib/minitest/reporters.rb
96
+ - lib/minitest/reporters/default_reporter.rb
97
+ - lib/minitest/reporters/progress_reporter.rb
98
+ - lib/minitest/reporters/spec_reporter.rb
99
+ - lib/minitest/reporters/version.rb
100
+ - lib/minitest/suite_runner.rb
101
+ - lib/minitest/test_runner.rb
102
+ - minitest-reporters.gemspec
103
+ - test/journo/reporter_test.rb
104
+ - test/journo/suite_runner_test.rb
105
+ - test/journo/test_runner_test.rb
106
+ - test/support/fixtures/empty_test_fixture.rb
107
+ - test/support/fixtures/error_test_fixture.rb
108
+ - test/support/fixtures/failure_test_fixture.rb
109
+ - test/support/fixtures/pass_test_fixture.rb
110
+ - test/support/fixtures/skip_test_fixture.rb
111
+ - test/support/fixtures/suite_callback_test_fixture.rb
112
+ - test/support/fixtures/test_case_fixture.rb
113
+ - test/support/test_case.rb
114
+ - test/test_helper.rb
115
+ homepage: https://github.com/CapnKernul/minitest-reporters
116
+ licenses: []
117
+ post_install_message:
118
+ rdoc_options: []
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ! '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project: minitest-reporters
135
+ rubygems_version: 1.8.6
136
+ signing_key:
137
+ specification_version: 3
138
+ summary: Create customizable MiniTest output formats
139
+ test_files:
140
+ - test/journo/reporter_test.rb
141
+ - test/journo/suite_runner_test.rb
142
+ - test/journo/test_runner_test.rb
143
+ - test/support/fixtures/empty_test_fixture.rb
144
+ - test/support/fixtures/error_test_fixture.rb
145
+ - test/support/fixtures/failure_test_fixture.rb
146
+ - test/support/fixtures/pass_test_fixture.rb
147
+ - test/support/fixtures/skip_test_fixture.rb
148
+ - test/support/fixtures/suite_callback_test_fixture.rb
149
+ - test/support/fixtures/test_case_fixture.rb
150
+ - test/support/test_case.rb
151
+ - test/test_helper.rb