Permalink
Browse files

Add in a short README and attributions

  • Loading branch information...
Alexander Kern
Alexander Kern committed May 25, 2011
1 parent 8a606be commit 0f70765c1f23bf1cd74623c09ff9d71beccd747f
View
@@ -1,4 +1,22 @@
+coverage
+rdoc
+pkg
+test/tmp
+test/version_tmp
+tmp
+pkg
*.gem
+*.rbc
+lib/bundler/man
+spec/reports
+.config
+InstalledFiles
.bundle
-Gemfile.lock
-pkg/*
+
+# YARD artifacts
+.yardoc
+_yardoc
+doc/
+
+# Gem-specific
+Gemfile.lock
View
@@ -0,0 +1,6 @@
+--readme README.md
+--markup markdown
+--markup-provider maruku
+--default-return ""
+--title "Minitest-reporter Documentation"
+--hide-void-return
View
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2011 Alexander Kern
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
@@ -0,0 +1,44 @@
+# minitest-reporter - reporters for MiniTest [![StillMaintained Status](http://stillmaintained.com/CapnKernul/minitest-reporter.png)](http://stillmaintained.com/CapnKernul/minitest-reporter) [![Build Status](http://travis-ci.org/CapnKernul/minitest-reporter.png)](http://travis-ci.org/CapnKernul/minitest-reporter) #
+
+Allows you to extend MiniTest using reporters rather than monkey-patching.
+
+## Installation ##
+
+ gem install minitest-reporter
+
+## Usage ##
+
+Then, in your `test_helper.rb` file, add the following lines:
+
+ MiniTest::Unit.runner = MiniTest::SuiteRunner.new
+ MiniTest::Unit.runner.reporters << MiniTest::Reporters::ProgressReporter.new
+
+Now, just run your tests; the reporter you specified will be used and make your
+output look absolutely gorgeous! If you feel the need to write your own
+reporter, just subclass `MiniTest::Reporter` and override the methods you'd
+like. Take a look at the provided reporters for examples.
+
+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
+
+I really like `ProgressReporter`.
+
+## Note on Patches/Pull Requests ##
+
+* Fork the project.
+* Make your feature addition or bug fix.
+* Add tests for it. This is important so I don't break it in a future version unintentionally.
+* 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.
+* Send me a pull request. Bonus points for git flow feature branches.
+
+## Resources ##
+
+* [GitHub Repository](https://github.com/CapnKernul/minitest-reporter)
+* [Documentation](http://rubydoc.info/github/CapnKernul/minitest-reporter)
+
+## License ##
+
+Minitest-reporter is licensed under the MIT License. See `LICENSE` for details.
View
@@ -2,7 +2,14 @@
module MiniTest
require 'minitest-reporter/reporter'
- require 'minitest-reporter/suite_runner'
- require 'minitest-reporter/test_runner'
require 'minitest-reporter/version'
+
+ autoload :SuiteRunner, 'minitest-reporter/suite_runner'
+ autoload :TestRunner, 'minitest-reporter/test_runner'
+
+ module Reporters
+ autoload :DefaultReporter, 'minitest-reporter/reporters/default_reporter'
+ autoload :SpecReporter, 'minitest-reporter/reporters/spec_reporter'
+ autoload :ProgressReporter, 'minitest-reporter/reporters/progress_reporter'
+ end
end
@@ -8,6 +8,10 @@ def output
runner.output
end
+ def verbose?
+ runner.verbose
+ end
+
def print(*args)
runner.output.print(*args)
end
@@ -16,14 +20,14 @@ def puts(*args)
runner.output.puts(*args)
end
- def before_suites(suites); end
- def after_suites(suites); end
+ def before_suites(suites, type); end
+ def after_suites(suites, type); end
def before_suite(suite); end
def after_suite(suite); end
def before_test(suite, test); end
- def pass(suite, test, runner); end
- def skip(suite, test, runner); end
- def failure(suite, test, runner); end
- def error(suite, test, runner); end
+ def pass(suite, test, test_runner); end
+ def skip(suite, test, test_runner); end
+ def failure(suite, test, test_runner); end
+ def error(suite, test, test_runner); end
end
end
@@ -0,0 +1,103 @@
+require 'ansi'
+
+module MiniTest
+ module Reporters
+ # A reporter identical to the standard MiniTest reporter.
+ #
+ # Based upon Ryan Davis of Seattle.rb's MiniTest (MIT License).
+ #
+ # @see https://github.com/seattlerb/minitest MiniTest
+ class DefaultReporter < MiniTest::Reporter
+ def before_suites(suites, type)
+ puts
+ puts "# Running #{type}s:"
+ puts
+ end
+
+ def before_test(suite, test)
+ print "#{suite}##{method} = " if verbose?
+ end
+
+ def pass(suite, test, test_runner)
+ after_test('.')
+ end
+
+ def skip(suite, test, test_runner)
+ after_test('S')
+ end
+
+ def failure(suite, test, test_runner)
+ after_test('F')
+ end
+
+ def error(suite, test, test_runner)
+ after_test('E')
+ end
+
+ def after_suites(suites, type)
+ time = Time.now - runner.start_time
+
+ puts
+ puts
+ puts "Finished #{type}s in %.6fs, %.4f tests/s, %.4f assertions/s." %
+ [time, runner.test_count / time, runner.assertion_count / time]
+
+ i = 0
+ runner.report.each do |suite, tests|
+ tests.each do |test, test_runner|
+ message = message_for(test_runner)
+ if message
+ i += 1
+ puts "\n%3d) %s" % [i, message]
+ end
+ end
+ end
+
+ puts
+
+ puts status
+ end
+
+ private
+
+ def after_test(result)
+ time = Time.now - runner.test_start_time
+
+ print '%.2f s = ' % time if verbose?
+ print result
+ puts if verbose?
+ end
+
+ def location(exception)
+ last_before_assertion = ''
+
+ exception.backtrace.reverse_each do |s|
+ break if s =~ /in .(assert|refute|flunk|pass|fail|raise|must|wont)/
+ last_before_assertion = s
+ end
+
+ last_before_assertion.sub(/:in .*$/, '')
+ end
+
+ def message_for(test_runner)
+ suite = test_runner.suite
+ test = test_runner.test
+ e = test_runner.exception
+
+ case test_runner.result
+ when :pass then nil
+ when :skip then "Skipped:\n#{test}(#{suite}) [#{location(e)}]:\n#{e.message}\n"
+ when :failure then "Failure:\n#{test}(#{suite}) [#{location(e)}]:\n#{e.message}\n"
+ when :error
+ bt = MiniTest::filter_backtrace(test_runner.exception.backtrace).join "\n "
+ "Error:\n#{test}(#{suite}):\n#{e.class}: #{e.message}\n #{bt}\n"
+ end
+ end
+
+ def status
+ '%d tests, %d assertions, %d failures, %d errors, %d skips' %
+ [runner.test_count, runner.assertion_count, runner.failures, runner.errors, runner.skips]
+ end
+ end
+ end
+end
@@ -0,0 +1,107 @@
+require 'ansi'
+require 'progressbar'
+
+module MiniTest
+ module Reporters
+ # Fuubar-like reporter with a progress bar.
+ #
+ # Based upon Jeff Kreefmeijer's Fuubar (MIT License) and paydro's
+ # monkey-patch.
+ #
+ # @see https://github.com/jeffkreeftmeijer/fuubar Fuubar
+ # @see https://gist.github.com/356945 paydro's monkey-patch
+ class ProgressReporter < MiniTest::Reporter
+ include ANSI::Code
+
+ INFO_PADDING = 2
+
+ def before_suites(suites, type)
+ puts 'Started'
+ puts
+
+ @color = GREEN
+ @finished_count = 0
+ @progress = ProgressBar.new("0/#{runner.test_count}", runner.test_count, runner.output)
+ @progress.bar_mark = '='
+ end
+
+ def increment
+ with_color do
+ @finished_count += 1
+ @progress.instance_variable_set('@title', "#{@finished_count}/#{runner.test_count}")
+ @progress.inc
+ end
+ end
+
+ def pass(suite, test, test_runner)
+ increment
+ end
+
+ def skip(suite, test, test_runner)
+ @color = YELLOW unless @color == RED
+ print(yellow { 'SKIP' })
+ print_test_with_time(suite, test)
+ puts
+ puts
+ increment
+ end
+
+ def failure(suite, test, test_runner)
+ @color = RED
+ print(red { 'FAIL' })
+ print_test_with_time(suite, test)
+ puts
+ print_info(test_runner.exception)
+ puts
+ increment
+ end
+
+ def error(suite, test, test_runner)
+ @color = RED
+ print(red { 'ERROR' })
+ print_test_with_time(suite, test)
+ puts
+ print_info(test_runner.exception)
+ puts
+ increment
+ end
+
+ def after_suites(suites, type)
+ with_color { @progress.finish }
+
+ 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(red { '%d failures, %d errors, ' } % [runner.failures, runner.errors])
+ print(yellow { '%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)#{clr}" % 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
+
+ def with_color
+ print @color
+ yield
+ print CLEAR
+ end
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit 0f70765

Please sign in to comment.