Created
January 16, 2013 11:12
-
-
Save oskarizu/4546410 to your computer and use it in GitHub Desktop.
Formatter for RSpec 2 based on RspecEnhancedFormatter from https://github.com/grosser/rspec_enhanced_profile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# RSpec 2 | |
require 'rspec/core/formatters/progress_formatter' | |
class NewProfile < RSpec::Core::Formatters::ProgressFormatter | |
SHOW_TOP = (ENV['PROFILE_SHOW_TOP'] || 20).to_i | |
def initialize(*args) | |
super | |
@example_times = [] | |
end | |
def example_started(*args) | |
@time = Time.now | |
end | |
def example_passed(example) | |
super | |
@example_times << [ | |
example_group.description, | |
example.description, | |
Time.now - @time | |
] | |
end | |
def start_dump | |
dump_example_times | |
@output.flush | |
end | |
private | |
def dump_example_times | |
#@output.puts "\n\nSingle examples:\n" | |
@output.puts "\n\nTop #{SHOW_TOP} slowest examples:\n\n" | |
sorted_by_time(@example_times)[0..SHOW_TOP].each do |group, example, time| | |
@output.puts "#{red(sprintf("%.7f", time))} #{group} #{example}" | |
end | |
end | |
#sorted by last ascending | |
def sorted_by_time(times) | |
times.to_a.sort_by{|x| x.last}.reverse | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment