Skip to content

Instantly share code, notes, and snippets.

@mediocretes
Created May 2, 2011 22:25
Show Gist options
  • Save mediocretes/952496 to your computer and use it in GitHub Desktop.
Save mediocretes/952496 to your computer and use it in GitHub Desktop.
class MiniTest::Unit
alias :run_test_suites_old :run_test_suites
def run_test_suites(filter = /./)
@test_count, @assertion_count = 0, 0
old_sync, @@out.sync = @@out.sync, true if @@out.respond_to? :sync=
TestCase.test_suites.each do |suite|
test_cases = suite.test_methods.grep(filter)
if test_cases.size > 0
@@out.print "\n#{suite}:\n"
end
test_cases.each do |test|
inst = suite.new test
inst._assertions = 0
@broken = nil
@@out.print(case run_one inst
when :pass
@broken = false
green { "P" }
when :error
@broken = true
@@out.puts
yellow { pad_with_size "ERROR" }
when :fail
@broken = true
@@out.puts
red { pad_with_size "FAIL" }
when :skip
@broken = false
cyan { "S" }
end)
if @broken
@@out.print MiniTest::Unit.use_natural_language_case_names? ?
" #{test.gsub("test_", "").gsub(/_/, " ")}" : " #{test}"
@@out.print " (%.2fs) " % @elapsed
@@out.puts
report = @report.last
@@out.puts pad(report[:message], 10)
trace = MiniTest::filter_backtrace(report[:exception].backtrace).first
@@out.print pad(trace, 10)
@@out.puts
end
# @@out.puts
@test_count += 1
@assertion_count += inst._assertions
end
end
@@out.sync = old_sync if @@out.respond_to? :sync=
[@test_count, @assertion_count]
end
def run_one(inst)
t = Time.now
result = inst.run self
@elapsed = Time.now - t
if result == :pass && @elapsed > 1.0
result = :error
@report << { :message => "Test took a long time (%.2fs)" % @elapsed,
:exception => Exception.new("Long test")}
end
result
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment