minitest-reporters 0.7.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -10,14 +10,18 @@ Death to haphazard monkey-patching! Extend MiniTest through simple hooks.
10
10
 
11
11
  In your `test_helper.rb` file, add the following lines:
12
12
 
13
- require 'minitest/reporters'
14
- MiniTest::Unit.runner = MiniTest::SuiteRunner.new
15
- MiniTest::Unit.runner.reporters << MiniTest::Reporters::ProgressReporter.new
13
+ require "minitest/reporters"
14
+ MiniTest::Reporters.use!
16
15
 
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.
16
+ This will swap out the MiniTest runner to the custom one used by minitest-reporters and use the correct reporters for Textmate, Rubymine, and the console. If you would like to write your own reporter, just `include MiniTest::Reporter` and override the methods you'd like. Take a look at the provided reporters for examples.
17
+
18
+ Don't like the default progress bar reporter?
19
+
20
+ MiniTest::Reporters.use! MiniTest::Reporters::SpecReporter.new
21
+
22
+ Want to use multiple reporters?
23
+
24
+ MiniTest::Reporters.use! [MiniTest::Reporters::SpecReporter.new, MiniTest::Reporters::GuardReporter.new]
21
25
 
22
26
  The following reporters are provided:
23
27
 
@@ -28,29 +32,8 @@ The following reporters are provided:
28
32
  MiniTest::Reporters::RubyMineReporter # => Reporter designed for RubyMine IDE and TeamCity CI server; see below
29
33
  MiniTest::Reporters::GuardReporter # => Integrates with guard-minitest to provide on-screen notifications
30
34
 
31
- I really like `ProgressReporter` for my everyday terminal usage, but I like
32
- using `RubyMateReporter` when I'm executing test suites from TextMate. My usual
33
- set up looks like this:
34
-
35
- require 'minitest/reporters'
36
- MiniTest::Unit.runner = MiniTest::SuiteRunner.new
37
- if ENV['TM_PID']
38
- MiniTest::Unit.runner.reporters << MiniTest::Reporters::RubyMateReporter.new
39
- else
40
- MiniTest::Unit.runner.reporters << MiniTest::Reporters::ProgressReporter.new
41
- end
42
-
43
- If you prefer integration with RubyMine test runner or TeamCity CI server you'll need:
44
-
45
- if ENV["RM_INFO"] || ENV["TEAMCITY_VERSION"]
46
- MiniTest::Unit.runner.reporters << MiniTest::Reporters::RubyMineReporter.new
47
- else
48
- ...
49
- end
50
-
51
35
  ## TODO ##
52
36
 
53
- * Make the boilerplate code look prettier. Something like a one-line require for the general use-case would be nice.
54
37
  * Add some example images of the reporters.
55
38
 
56
39
  ## Note on Patches/Pull Requests ##
@@ -1,7 +1,7 @@
1
1
  module MiniTest
2
2
  module Reporter
3
3
  def runner
4
- MiniTest::Unit.runner
4
+ Unit.runner
5
5
  end
6
6
 
7
7
  def output
@@ -30,4 +30,4 @@ module MiniTest
30
30
  def failure(suite, test, test_runner); end
31
31
  def error(suite, test, test_runner); end
32
32
  end
33
- end
33
+ end
@@ -16,5 +16,21 @@ module MiniTest
16
16
  autoload :RubyMineReporter, "minitest/reporters/rubymine_reporter"
17
17
  autoload :GuardReporter, "minitest/reporters/guard_reporter"
18
18
  autoload :JUnitReporter, "minitest/reporters/junit_reporter"
19
+
20
+ def self.use!(console_reporters = ProgressReporter.new, env = ENV)
21
+ runner = SuiteRunner.new
22
+ runner.reporters = choose_reporters(console_reporters, env)
23
+ Unit.runner = runner
24
+ end
25
+
26
+ def self.choose_reporters(console_reporters, env)
27
+ if env["TM_PID"]
28
+ [RubyMateReporter.new]
29
+ elsif env["RM_INFO"] || env["TEAMCITY_VERSION"]
30
+ [RubyMineReporter.new]
31
+ else
32
+ Array(console_reporters)
33
+ end
34
+ end
19
35
  end
20
36
  end
@@ -8,9 +8,9 @@ module MiniTest
8
8
  #
9
9
  # @see https://github.com/seattlerb/minitest MiniTest
10
10
  class DefaultReporter
11
- include MiniTest::Reporter
11
+ include Reporter
12
12
 
13
- def initialize(backtrace_filter = MiniTest::BacktraceFilter.default_filter)
13
+ def initialize(backtrace_filter = BacktraceFilter.default_filter)
14
14
  @backtrace_filter = backtrace_filter
15
15
  end
16
16
 
@@ -1,15 +1,14 @@
1
1
  begin
2
- require 'guard/minitest/notifier'
2
+ require "guard/minitest/notifier"
3
3
  rescue LoadError
4
- puts "You need guard-minitest to use this reporter"
4
+ puts "You need guard-minitest to use this reporter."
5
5
  exit 1
6
6
  end
7
7
 
8
8
  module MiniTest
9
9
  module Reporters
10
-
11
10
  class GuardReporter
12
- include MiniTest::Reporter
11
+ include Reporter
13
12
 
14
13
  def after_suites(*args)
15
14
  duration = Time.now - runner.start_time
@@ -10,9 +10,9 @@ module MiniTest
10
10
  # Also inspired by Marc Seeger's attempt at producing a JUnitReporter (see https://github.com/rb2k/minitest-reporters/commit/e13d95b5f884453a9c77f62bc5cba3fa1df30ef5)
11
11
  # Also inspired by minitest-ci (see https://github.com/bhenderson/minitest-ci)
12
12
  class JUnitReporter
13
- include MiniTest::Reporter
13
+ include Reporter
14
14
 
15
- def initialize(reports_dir = "test/reports", backtrace_filter = MiniTest::BacktraceFilter.default_filter)
15
+ def initialize(reports_dir = "test/reports", backtrace_filter = BacktraceFilter.default_filter)
16
16
  @backtrace_filter = backtrace_filter
17
17
  @reports_path = File.join(Dir.getwd, reports_dir)
18
18
  p "Emptying #{@reports_path}"
@@ -11,13 +11,20 @@ module MiniTest
11
11
  # @see https://github.com/jeffkreeftmeijer/fuubar Fuubar
12
12
  # @see https://gist.github.com/356945 paydro's monkey-patch
13
13
  class ProgressReporter
14
- include MiniTest::Reporter
14
+ include Reporter
15
15
  include ANSI::Code
16
16
 
17
17
  INFO_PADDING = 2
18
18
 
19
- def initialize(backtrace_filter = MiniTest::BacktraceFilter.default_filter)
20
- @backtrace_filter = backtrace_filter
19
+ def initialize(options = {})
20
+ if options.is_a?(Hash)
21
+ @backtrace_filter = options.fetch(:backtrace_filter, BacktraceFilter.default_filter)
22
+ @detailed_skip = options.fetch(:detailed_skip, true)
23
+ else
24
+ warn "Please use :backtrace_filter => filter instead of passing in the filter directly."
25
+ @backtrace_filter = options
26
+ @detailed_skip = true
27
+ end
21
28
  end
22
29
 
23
30
  def before_suites(suites, type)
@@ -44,10 +51,14 @@ module MiniTest
44
51
 
45
52
  def skip(suite, test, test_runner)
46
53
  @color = YELLOW unless @color == RED
47
- print(yellow { 'SKIP' })
48
- print_test_with_time(suite, test)
49
- puts
50
- puts
54
+
55
+ if @detailed_skip
56
+ print(yellow { 'SKIP' })
57
+ print_test_with_time(suite, test)
58
+ puts
59
+ puts
60
+ end
61
+
51
62
  increment
52
63
  end
53
64
 
@@ -5,11 +5,11 @@ module MiniTest
5
5
  module Reporters
6
6
  # Simple reporter designed for RubyMate.
7
7
  class RubyMateReporter
8
- include MiniTest::Reporter
8
+ include Reporter
9
9
 
10
10
  INFO_PADDING = 2
11
11
 
12
- def initialize(backtrace_filter = MiniTest::BacktraceFilter.default_filter)
12
+ def initialize(backtrace_filter = BacktraceFilter.default_filter)
13
13
  @backtrace_filter = backtrace_filter
14
14
  end
15
15
 
@@ -27,7 +27,7 @@ rescue LoadError
27
27
  # delegate to default reporter
28
28
  module MiniTest
29
29
  module Reporters
30
- class RubyMineReporter < MiniTest::Reporters::DefaultReporter
30
+ class RubyMineReporter < DefaultReporter
31
31
  end
32
32
  end
33
33
  end
@@ -35,7 +35,7 @@ else
35
35
  module MiniTest
36
36
  module Reporters
37
37
  class RubyMineReporter
38
- include MiniTest::Reporter
38
+ include Reporter
39
39
  include ANSI::Code
40
40
 
41
41
  include ::Rake::TeamCity::RunnerCommon
@@ -9,14 +9,14 @@ module MiniTest
9
9
  # @see https://github.com/TwP/turn turn
10
10
  # @see https://gist.github.com/356945 paydro's monkey-patch
11
11
  class SpecReporter
12
- include MiniTest::Reporter
12
+ include Reporter
13
13
  include ANSI::Code
14
14
 
15
15
  TEST_PADDING = 2
16
16
  INFO_PADDING = 8
17
17
  MARK_SIZE = 5
18
18
 
19
- def initialize(backtrace_filter = MiniTest::BacktraceFilter.default_filter)
19
+ def initialize(backtrace_filter = BacktraceFilter.default_filter)
20
20
  @backtrace_filter = backtrace_filter
21
21
  end
22
22
 
@@ -1,5 +1,5 @@
1
1
  module MiniTest
2
2
  module Reporters
3
- VERSION = '0.7.1'
3
+ VERSION = "0.8.0"
4
4
  end
5
5
  end
@@ -8,7 +8,7 @@ module MiniTest
8
8
  # Based upon Ryan Davis of Seattle.rb's MiniTest (MIT License).
9
9
  #
10
10
  # @see https://github.com/seattlerb/minitest MiniTest
11
- class SuiteRunner < MiniTest::Unit
11
+ class SuiteRunner < Unit
12
12
  attr_accessor :suite_start_time, :test_start_time, :reporters
13
13
 
14
14
  def initialize
@@ -107,4 +107,4 @@ module MiniTest
107
107
  output.sync = old_sync if sync
108
108
  end
109
109
  end
110
- end
110
+ end
@@ -24,8 +24,8 @@ module MiniTest
24
24
 
25
25
  def puke(suite, test, exception)
26
26
  case exception
27
- when MiniTest::Skip then [:skip, exception]
28
- when MiniTest::Assertion then [:failure, exception]
27
+ when Skip then [:skip, exception]
28
+ when Assertion then [:failure, exception]
29
29
  else [:error, exception]
30
30
  end
31
31
  end
@@ -46,4 +46,4 @@ module MiniTestReportersTest
46
46
  @reporter.puts('foo')
47
47
  end
48
48
  end
49
- end
49
+ end
@@ -0,0 +1,27 @@
1
+ require 'test_helper'
2
+
3
+ module MiniTestReportersTest
4
+ class ReportersTest < TestCase
5
+ test "chooses the Rubymine reporter when necessary" do
6
+ # Rubymine reporter complains when RubyMine libs are not available, so
7
+ # stub its #puts method out.
8
+ MiniTest::Unit.runner.output.stubs(:puts)
9
+
10
+ reporters = Minitest::Reporters.choose_reporters [], { "RM_INFO" => "x" }
11
+ assert_instance_of MiniTest::Reporters::RubyMineReporter, reporters[0]
12
+
13
+ reporters = Minitest::Reporters.choose_reporters [], { "TEAMCITY_VERSION" => "x" }
14
+ assert_instance_of MiniTest::Reporters::RubyMineReporter, reporters[0]
15
+ end
16
+
17
+ test "chooses the TextMate reporter when necessary" do
18
+ reporters = Minitest::Reporters.choose_reporters [], {"TM_PID" => "x"}
19
+ assert_instance_of MiniTest::Reporters::RubyMateReporter, reporters[0]
20
+ end
21
+
22
+ test "chooses the console reporters when necessary" do
23
+ reporters = Minitest::Reporters.choose_reporters [MiniTest::Reporters::SpecReporter.new], {}
24
+ assert_instance_of MiniTest::Reporters::SpecReporter, reporters[0]
25
+ end
26
+ end
27
+ end
@@ -18,21 +18,16 @@ module MiniTestReportersTest
18
18
  end
19
19
  end
20
20
 
21
- MiniTest::Unit.runner = MiniTest::SuiteRunner.new
22
-
23
21
  # Testing the built-in reporters using automated unit testing would be extremely
24
22
  # brittle. Consequently, there are no unit tests for them. Instead, uncomment
25
23
  # the reporter that you'd like to test and run the full test suite. Make sure to
26
24
  # 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
- if ENV["TM_PID"]
31
- MiniTest::Unit.runner.reporters << MiniTest::Reporters::RubyMateReporter.new
32
- elsif ENV["RM_INFO"]
33
- MiniTest::Unit.runner.reporters << MiniTest::Reporters::RubyMineReporter.new
34
- else
35
- # MiniTest::Unit.runner.reporters << MiniTest::Reporters::DefaultReporter.new
36
- # MiniTest::Unit.runner.reporters << MiniTest::Reporters::SpecReporter.new
37
- MiniTest::Unit.runner.reporters << MiniTest::Reporters::ProgressReporter.new
38
- end
25
+
26
+ MiniTest::Reporters.use!
27
+ # MiniTest::Reporters.use! MiniTest::Reporters::DefaultReporter.new
28
+ # MiniTest::Reporters.use! MiniTest::Reporters::SpecReporter.new
29
+ # MiniTest::Reporters.use! MiniTest::Reporters::ProgressReporter.new(:detailed_skip => false)
30
+ # MiniTest::Reporters.use! MiniTest::Reporters::RubyMateReporter.new
31
+ # MiniTest::Reporters.use! MiniTest::Reporters::RubyMineReporter.new
32
+ # MiniTest::Reporters.use! MiniTest::Reporters::GuardReporter.new
33
+ # MiniTest::Reporters.use! MiniTest::Reporters::JUnitReporter.new
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.7.1
4
+ version: 0.8.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-05-17 00:00:00.000000000 Z
12
+ date: 2012-06-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
@@ -175,6 +175,7 @@ files:
175
175
  - minitest-reporters.gemspec
176
176
  - test/minitest/backtrace_filter_test.rb
177
177
  - test/minitest/reporter_test.rb
178
+ - test/minitest/reporters_test.rb
178
179
  - test/minitest/suite_runner_test.rb
179
180
  - test/minitest/test_runner_test.rb
180
181
  - test/support/fixtures/empty_test_fixture.rb
@@ -200,7 +201,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
200
201
  version: '0'
201
202
  segments:
202
203
  - 0
203
- hash: 596014274367585046
204
+ hash: -2178815342268569310
204
205
  required_rubygems_version: !ruby/object:Gem::Requirement
205
206
  none: false
206
207
  requirements:
@@ -209,7 +210,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
209
210
  version: '0'
210
211
  segments:
211
212
  - 0
212
- hash: 596014274367585046
213
+ hash: -2178815342268569310
213
214
  requirements: []
214
215
  rubyforge_project: minitest-reporters
215
216
  rubygems_version: 1.8.24
@@ -219,6 +220,7 @@ summary: Create customizable MiniTest output formats
219
220
  test_files:
220
221
  - test/minitest/backtrace_filter_test.rb
221
222
  - test/minitest/reporter_test.rb
223
+ - test/minitest/reporters_test.rb
222
224
  - test/minitest/suite_runner_test.rb
223
225
  - test/minitest/test_runner_test.rb
224
226
  - test/support/fixtures/empty_test_fixture.rb