Skip to content

Instantly share code, notes, and snippets.

@inkel
Created May 21, 2012 21:14
Show Gist options
  • Save inkel/2764770 to your computer and use it in GitHub Desktop.
Save inkel/2764770 to your computer and use it in GitHub Desktop.
Protest Timed reporter
module Protest
class Reports::TimedTest < Report
include Utils::Summaries
include Utils::ColorfulOutput
attr_reader :stream
attr_reader :slowest
attr_reader :max_time
def initialize(stream=STDOUT)
@stream = stream
end
on :test do |report, test|
time = Time.now - @start
if @slowest.nil? || @max_time < time
@slowest = test
@max_time = time
end
report.print "- %-67s %3.4fs " % [test.test_name, time]
end
on :pass do |report, test|
report.puts "PASS", :passed
end
on :failure do |report, test|
report.puts "FAIL", :failed
end
on :error do |report, test|
report.puts "ERROR", :errored
end
on :pending do |report, test|
report.puts "PENDING", :pending
end
on :enter do |report, context|
report.puts context.description unless context.tests.empty?
@start = Time.now
end
on :exit do |report, context|
report.puts unless context.tests.empty?
end
on :end do |report|
report.puts "Slowest test took %3.4fs: %-67s\n %s\n" %
[ @max_time, @slowest.test_name, @slowest.test.instance_eval { @location } ]
report.summarize_pending_tests
report.summarize_errors
report.summarize_test_totals
end
end
add_report :timed, Reports::TimedTest
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment