minitest-reporters 0.10.2 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -3,6 +3,7 @@ rdoc
3
3
  pkg
4
4
  test/tmp
5
5
  test/version_tmp
6
+ test/reports
6
7
  tmp
7
8
  pkg
8
9
  *.gem
@@ -19,4 +20,4 @@ _yardoc
19
20
  doc/
20
21
 
21
22
  # Gem-specific
22
- Gemfile.lock
23
+ Gemfile.lock
data/Rakefile CHANGED
@@ -1,11 +1,34 @@
1
- require 'bundler'
2
- Bundler::GemHelper.install_tasks
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
3
 
4
4
  task :default => :test
5
-
6
- require 'rake/testtask'
7
5
  Rake::TestTask.new do |t|
8
- t.ruby_opts += ['-rubygems']
9
- t.libs << 'test'
10
- t.pattern = 'test/**/*_test.rb'
11
- end
6
+ t.pattern = "test/unit/**/*_test.rb"
7
+ t.verbose = true
8
+ end
9
+
10
+ Rake::TestTask.new("test:gallery") do |t|
11
+ t.pattern = "test/gallery/**/*_test.rb"
12
+ t.verbose = true
13
+ end
14
+
15
+ # The RubyMine reporter must be tested separately inside of RubyMine, and hence
16
+ # is not run in the gallery. The JUnit reporter writes to `test/reports` instead
17
+ # of having meaningful output. The guard reporter requires Guard, and I'm not
18
+ # really all that intersted in setting it up for automated testing for such a
19
+ # simple reporter.
20
+ task :gallery do
21
+ [
22
+ "DefaultReporter",
23
+ "JUnitReporter",
24
+ "ProgressReporter",
25
+ "RubyMateReporter",
26
+ "SpecReporter"
27
+ ].each do |reporter|
28
+ puts "Running gallery tests using #{reporter}..."
29
+ sh "rake test:gallery REPORTER=#{reporter}" do
30
+ # Ignore failures. They're expected when you are running the gallery
31
+ # test suite.
32
+ end
33
+ end
34
+ end
@@ -10,8 +10,23 @@ module MiniTest
10
10
  class DefaultReporter
11
11
  include Reporter
12
12
 
13
- def initialize(backtrace_filter = BacktraceFilter.default_filter)
14
- @backtrace_filter = backtrace_filter
13
+ def initialize(options = {})
14
+ if options.is_a?(Hash)
15
+ @backtrace_filter = options.fetch(:backtrace_filter, BacktraceFilter.default_filter)
16
+ @detailed_skip = options.fetch(:detailed_skip, true)
17
+ @color = options.fetch(:color) do
18
+ output.tty? && (
19
+ ENV["TERM"] == "screen" ||
20
+ ENV["TERM"] =~ /term(?:-(?:256)?color)?\z/ ||
21
+ ENV["EMACS"] == "t"
22
+ )
23
+ end
24
+ else
25
+ warn "Please use :backtrace_filter => filter instead of passing in the filter directly."
26
+ @backtrace_filter = options
27
+ @detailed_skip = true
28
+ @color = false
29
+ end
15
30
  end
16
31
 
17
32
  def before_suites(suites, type)
@@ -25,46 +40,75 @@ module MiniTest
25
40
  end
26
41
 
27
42
  def pass(suite, test, test_runner)
28
- after_test('.')
43
+ after_test(green { '.' })
29
44
  end
30
45
 
31
46
  def skip(suite, test, test_runner)
32
- after_test('S')
47
+ after_test(yellow { 'S' })
33
48
  end
34
49
 
35
50
  def failure(suite, test, test_runner)
36
- after_test('F')
51
+ after_test(red { 'F' })
37
52
  end
38
53
 
39
54
  def error(suite, test, test_runner)
40
- after_test('E')
55
+ after_test(red { 'E' })
41
56
  end
42
57
 
43
58
  def after_suites(suites, type)
44
59
  time = Time.now - runner.suites_start_time
60
+ status_line = colored_for(suite_result) do
61
+ "Finished %ss in %.6fs, %.4f tests/s, %.4f assertions/s." %
62
+ [type, time, runner.test_count / time, runner.assertion_count / time]
63
+ end
45
64
 
46
65
  puts
47
66
  puts
48
- puts "Finished #{type}s in %.6fs, %.4f tests/s, %.4f assertions/s." %
49
- [time, runner.test_count / time, runner.assertion_count / time]
67
+ puts status_line
50
68
 
51
- i = 0
52
69
  runner.test_results.each do |suite, tests|
53
70
  tests.each do |test, test_runner|
54
- message = message_for(test_runner)
55
- if message
56
- i += 1
57
- puts "\n%3d) %s" % [i, message]
71
+ if message = message_for(test_runner)
72
+ puts
73
+ print(colored_for(test_runner.result) { message })
58
74
  end
59
75
  end
60
76
  end
61
77
 
62
78
  puts
63
- puts status
79
+ puts(colored_for(suite_result) { status })
64
80
  end
65
81
 
66
82
  private
67
83
 
84
+ def green(&block)
85
+ @color ? ANSI::Code.green(&block) : yield
86
+ end
87
+
88
+ def yellow(&block)
89
+ @color ? ANSI::Code.yellow(&block) : yield
90
+ end
91
+
92
+ def red(&block)
93
+ @color ? ANSI::Code.red(&block) : yield
94
+ end
95
+
96
+ def colored_for(result, &block)
97
+ case result
98
+ when :failure, :error; red(&block)
99
+ when :skip; yellow(&block)
100
+ else green(&block)
101
+ end
102
+ end
103
+
104
+ def suite_result
105
+ if runner.failures > 0; :failure
106
+ elsif runner.errors > 0; :error
107
+ elsif runner.skips > 0; :skip
108
+ else :pass
109
+ end
110
+ end
111
+
68
112
  def after_test(result)
69
113
  time = Time.now - runner.test_start_time
70
114
 
@@ -91,7 +135,10 @@ module MiniTest
91
135
 
92
136
  case test_runner.result
93
137
  when :pass then nil
94
- when :skip then "Skipped:\n#{test}(#{suite}) [#{location(e)}]:\n#{e.message}\n"
138
+ when :skip
139
+ if @detailed_skip
140
+ "Skipped:\n#{test}(#{suite}) [#{location(e)}]:\n#{e.message}\n"
141
+ end
95
142
  when :failure then "Failure:\n#{test}(#{suite}) [#{location(e)}]:\n#{e.message}\n"
96
143
  when :error
97
144
  bt = @backtrace_filter.filter(test_runner.exception.backtrace).join "\n "
@@ -1,5 +1,5 @@
1
1
  module MiniTest
2
2
  module Reporters
3
- VERSION = "0.10.2"
3
+ VERSION = "0.11.0"
4
4
  end
5
5
  end
@@ -0,0 +1,25 @@
1
+ require_relative "../test_helper"
2
+
3
+ module MiniTestReportersTest
4
+ class BadTest < TestCase
5
+ def test_a
6
+ assert_equal 1, 2
7
+ end
8
+
9
+ def test_b
10
+ assert false # simple failure
11
+ end
12
+
13
+ def test_b
14
+ assert_equal "ab\nc", "ab\nd" # some nice diff
15
+ end
16
+
17
+ def test_boom
18
+ raise "A random exception"
19
+ end
20
+
21
+ def test_long_method_name
22
+ skip
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,14 @@
1
+ require_relative "../test_helper"
2
+
3
+ module MiniTestReportersTest
4
+ class GoodTest < TestCase
5
+ def test_a
6
+ assert_equal 1, 1
7
+ assert 1
8
+ end
9
+
10
+ def test_b
11
+ assert_equal 2, 2
12
+ end
13
+ end
14
+ end
data/test/test_helper.rb CHANGED
@@ -1,7 +1,7 @@
1
- require 'bundler/setup'
2
- require 'minitest/autorun'
3
- require 'rr'
4
- require 'minitest/reporters'
1
+ require "bundler/setup"
2
+ require "minitest/autorun"
3
+ require "rr"
4
+ require "minitest/reporters"
5
5
 
6
6
  module MiniTestReportersTest
7
7
  class TestCase < MiniTest::Unit::TestCase
@@ -10,15 +10,12 @@ module MiniTestReportersTest
10
10
  end
11
11
 
12
12
  # Testing the built-in reporters using automated unit testing would be extremely
13
- # brittle. Consequently, there are no unit tests for them. Instead, uncomment
14
- # the reporter that you'd like to test and run the full test suite. Make sure to
15
- # try them with skipped, failing, and error tests as well!
13
+ # brittle. Consequently, there are no unit tests for them. If you'd like to run
14
+ # all the reporters sequentially on a fake test suite, run `rake gallery`.
16
15
 
17
- MiniTest::Reporters.use!
18
- # MiniTest::Reporters.use! MiniTest::Reporters::DefaultReporter.new
19
- # MiniTest::Reporters.use! MiniTest::Reporters::SpecReporter.new
20
- # MiniTest::Reporters.use! MiniTest::Reporters::ProgressReporter.new(:detailed_skip => false)
21
- # MiniTest::Reporters.use! MiniTest::Reporters::RubyMateReporter.new
22
- # MiniTest::Reporters.use! MiniTest::Reporters::RubyMineReporter.new
23
- # MiniTest::Reporters.use! MiniTest::Reporters::GuardReporter.new
24
- # MiniTest::Reporters.use! MiniTest::Reporters::JUnitReporter.new
16
+ if ENV["REPORTER"]
17
+ reporter_klass = MiniTest::Reporters.const_get(ENV["REPORTER"])
18
+ MiniTest::Reporters.use! [reporter_klass.new]
19
+ else
20
+ MiniTest::Reporters.use!
21
+ end
@@ -1,4 +1,4 @@
1
- require "test_helper"
1
+ require_relative "../../test_helper"
2
2
 
3
3
  module MiniTestReportersTest
4
4
  class BacktraceFilterTest < TestCase
@@ -1,4 +1,4 @@
1
- require 'test_helper'
1
+ require_relative "../../test_helper"
2
2
 
3
3
  module MiniTestReportersTest
4
4
  class ReporterTest < TestCase
@@ -1,4 +1,4 @@
1
- require 'test_helper'
1
+ require_relative "../../test_helper"
2
2
 
3
3
  module MiniTestReportersTest
4
4
  class ReportersTest < TestCase
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minitest-reporters
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.2
4
+ version: 0.11.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-31 00:00:00.000000000 Z
12
+ date: 2012-09-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
@@ -158,10 +158,12 @@ files:
158
158
  - lib/minitest/reporters/version.rb
159
159
  - lib/minitest/test_runner.rb
160
160
  - minitest-reporters.gemspec
161
- - test/minitest/backtrace_filter_test.rb
162
- - test/minitest/reporter_test.rb
163
- - test/minitest/reporters_test.rb
161
+ - test/gallery/bad_test.rb
162
+ - test/gallery/good_test.rb
164
163
  - test/test_helper.rb
164
+ - test/unit/minitest/backtrace_filter_test.rb
165
+ - test/unit/minitest/reporter_test.rb
166
+ - test/unit/minitest/reporters_test.rb
165
167
  homepage: https://github.com/CapnKernul/minitest-reporters
166
168
  licenses: []
167
169
  post_install_message:
@@ -187,8 +189,10 @@ signing_key:
187
189
  specification_version: 3
188
190
  summary: Create customizable MiniTest output formats
189
191
  test_files:
190
- - test/minitest/backtrace_filter_test.rb
191
- - test/minitest/reporter_test.rb
192
- - test/minitest/reporters_test.rb
192
+ - test/gallery/bad_test.rb
193
+ - test/gallery/good_test.rb
193
194
  - test/test_helper.rb
195
+ - test/unit/minitest/backtrace_filter_test.rb
196
+ - test/unit/minitest/reporter_test.rb
197
+ - test/unit/minitest/reporters_test.rb
194
198
  has_rdoc: