~ubuntu-branches/ubuntu/oneiric/puppet/oneiric-security

« back to all changes in this revision

Viewing changes to vendor/gems/rspec/lib/spec/runner/formatter/profile_formatter.rb

  • Committer: Bazaar Package Importer
  • Author(s): Micah Anderson
  • Date: 2008-07-26 15:43:45 UTC
  • mto: (3.1.1 lenny) (1.3.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: james.westby@ubuntu.com-20080726154345-1fmgo76b4l72ulvc
ImportĀ upstreamĀ versionĀ 0.24.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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