Browse files

Add RubyMateReporter.

  • Loading branch information...
1 parent cae59b9 commit 6a6087dc781a080b8523a20331bcc2c7da0ced9b Alexander Kern committed Aug 28, 2011
Showing with 95 additions and 5 deletions.
  1. +17 −1 README.md
  2. +1 −0 lib/minitest/reporters.rb
  3. +70 −0 lib/minitest/reporters/ruby_mate_reporter.rb
  4. +7 −4 test/test_helper.rb
View
18 README.md
@@ -24,8 +24,24 @@ The following reporters are provided:
MiniTest::Reporters::DefaultReporter # => Identical to the standard MiniTest reporter
MiniTest::Reporters::SpecReporter # => Turn-like output that reads like a spec
MiniTest::Reporters::ProgressReporter # => Fuubar-like output with a progress bar
+ MiniTest::Reporters::RubyMateReporter # => Simple reporter designed for RubyMate; see below
-I really like `ProgressReporter`.
+I really like `ProgressReporter` for my everyday terminal usage, but I like
+using `RubyMateReporter` when I'm executing test suites from TextMate. My usual
+set up looks like this:
+
+ require 'minitest/reporters'
+ MiniTest::Unit.runner = MiniTest::SuiteRunner.new
+ if ENV['TM_PID']
+ MiniTest::Unit.runner.reporters << MiniTest::Reporters::RubyMateReporter.new
+ else
+ MiniTest::Unit.runner.reporters << MiniTest::Reporters::ProgressReporter.new
+ end
+
+## TODO ##
+
+* Make the boilerplate code look prettier. Something like a one-line require for the general use-case would be nice.
+* Add some example images of the reporters.
## Note on Patches/Pull Requests ##
View
1 lib/minitest/reporters.rb
@@ -11,5 +11,6 @@ module Reporters
autoload :DefaultReporter, 'minitest/reporters/default_reporter'
autoload :SpecReporter, 'minitest/reporters/spec_reporter'
autoload :ProgressReporter, 'minitest/reporters/progress_reporter'
+ autoload :RubyMateReporter, 'minitest/reporters/ruby_mate_reporter'
end
end
View
70 lib/minitest/reporters/ruby_mate_reporter.rb
@@ -0,0 +1,70 @@
+require 'ansi'
+require 'progressbar'
+
+module MiniTest
+ module Reporters
+ # Simple reporter designed for RubyMate.
+ class RubyMateReporter
+ include MiniTest::Reporter
+
+ INFO_PADDING = 2
+
+ def before_suites(suites, type)
+ puts 'Started'
+ puts
+ end
+
+ def skip(suite, test, test_runner)
+ print 'SKIP'
+ print_test_with_time(suite, test)
+ puts
+ puts
+ end
+
+ def failure(suite, test, test_runner)
+ print 'FAIL'
+ print_test_with_time(suite, test)
+ puts
+ print_info(test_runner.exception)
+ puts
+ end
+
+ def error(suite, test, test_runner)
+ print 'ERROR'
+ print_test_with_time(suite, test)
+ puts
+ print_info(test_runner.exception)
+ puts
+ end
+
+ def after_suites(suites, type)
+ total_time = Time.now - runner.start_time
+
+ puts
+ puts('Finished in %.5fs' % total_time)
+ print('%d tests, %d assertions, ' % [runner.test_count, runner.assertion_count])
+ print('%d failures, %d errors, ' % [runner.failures, runner.errors])
+ print('%d skips' % runner.skips)
+ puts
+ end
+
+ private
+
+ def print_test_with_time(suite, test)
+ total_time = Time.now - runner.test_start_time
+ print(" #{suite}##{test} (%.2fs)" % total_time)
+ end
+
+ def print_info(e)
+ e.message.each_line { |line| puts pad(line) }
+
+ trace = MiniTest.filter_backtrace(e.backtrace)
+ trace.each { |line| puts pad(line) }
+ end
+
+ def pad(str)
+ ' ' * INFO_PADDING + str
+ end
+ end
+ end
+end
View
11 test/test_helper.rb
@@ -27,7 +27,10 @@ module Fixtures
#
# Personally, I like the progress reporter. Make sure you don't change that line
# when you commit.
-#
-# MiniTest::Unit.runner.reporters << MiniTest::Reporters::DefaultReporter.new
-# MiniTest::Unit.runner.reporters << MiniTest::Reporters::SpecReporter.new
-MiniTest::Unit.runner.reporters << MiniTest::Reporters::ProgressReporter.new
+if ENV['TM_PID']
+ MiniTest::Unit.runner.reporters << MiniTest::Reporters::RubyMateReporter.new
+else
+ # MiniTest::Unit.runner.reporters << MiniTest::Reporters::DefaultReporter.new
+ # MiniTest::Unit.runner.reporters << MiniTest::Reporters::SpecReporter.new
+ MiniTest::Unit.runner.reporters << MiniTest::Reporters::ProgressReporter.new
+end

0 comments on commit 6a6087d

Please sign in to comment.