]> git.openstreetmap.org Git - rails.git/blob - vendor/gems/rspec-1.1.2/lib/spec/runner/formatter/profile_formatter.rb
3784f3ac77d308359bf341ab8299d79ea2ad366e
[rails.git] / vendor / gems / rspec-1.1.2 / lib / spec / runner / formatter / profile_formatter.rb
1 require 'spec/runner/formatter/progress_bar_formatter'
2
3 module Spec
4   module Runner
5     module Formatter
6       class ProfileFormatter < ProgressBarFormatter
7         
8         def initialize(options, where)
9           super
10           @example_times = []
11         end
12         
13         def start(count)
14           @output.puts "Profiling enabled."
15         end
16         
17         def example_started(example)
18           @time = Time.now
19         end
20         
21         def example_passed(example)
22           super
23           @example_times << [
24             example_group.description,
25             example.description,
26             Time.now - @time
27           ]
28         end
29         
30         def start_dump
31           super
32           @output.puts "\n\nTop 10 slowest examples:\n"
33           
34           @example_times = @example_times.sort_by do |description, example, time|
35             time
36           end.reverse
37           
38           @example_times[0..9].each do |description, example, time|
39             @output.print red(sprintf("%.7f", time))
40             @output.puts " #{description} #{example}"
41           end
42           @output.flush
43         end
44       end
45     end
46   end
47 end