Skip to content

Instantly share code, notes, and snippets.

@fixlr
Created August 10, 2012 14:56
Show Gist options
  • Save fixlr/3314784 to your computer and use it in GitHub Desktop.
Save fixlr/3314784 to your computer and use it in GitHub Desktop.
Custom rspec formatter that prints the duration of each example
require 'rspec/core/formatters/progress_formatter'
class TimestampFormatter < RSpec::Core::Formatters::ProgressFormatter
def example_started(example)
@last_start = Time.new
super(example)
end
def example_passed(example)
time_diff = Time.now - @last_start
output.print green(". #{'%8.5f' % time_diff} #{example.full_description}\n")
end
def example_failed(example)
time_diff = Time.now - @last_start
output.print "F #{'%8.5f' % time_diff} #{example.full_description}\n"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment