Sha256: d42946fdce8c3e6d46180c67079b9367e89c492722b6e46328453ffa42f1a59f

Contents?: true

Size: 1.2 KB

Versions: 60

Compression:

Stored size: 1.2 KB

Contents

require 'spec/runner/formatter/progress_bar_formatter'

module Spec
  module Runner
    module Formatter
      class ProfileFormatter < ProgressBarFormatter
        
        def initialize(options, where)
          super
          @example_times = []
        end
        
        def start(count)
          @output.puts "Profiling enabled."
        end
        
        def example_started(example)
          @time = Time.now
        end
        
        def example_passed(example)
          super
          @example_times << [
            example_group.description,
            example.description,
            Time.now - @time
          ]
        end
        
        def start_dump
          super
          @output.puts "\n\nTop 10 slowest examples:\n"
          
          @example_times = @example_times.sort_by do |description, example, time|
            time
          end.reverse
          
          @example_times[0..9].each do |description, example, time|
            @output.print red(sprintf("%.7f", time))
            @output.puts " #{description} #{example}"
          end
          @output.flush
        end
        
        def method_missing(sym, *args)
          # ignore
        end
      end
    end
  end
end

Version data entries

60 entries across 60 versions & 10 rubygems

Version Path
dchelimsky-rspec-1.1.10 lib/spec/runner/formatter/profile_formatter.rb
dchelimsky-rspec-1.1.11.1 lib/spec/runner/formatter/profile_formatter.rb
dchelimsky-rspec-1.1.11.2 lib/spec/runner/formatter/profile_formatter.rb
dchelimsky-rspec-1.1.11.3 lib/spec/runner/formatter/profile_formatter.rb
dchelimsky-rspec-1.1.11.4 lib/spec/runner/formatter/profile_formatter.rb
dchelimsky-rspec-1.1.11.5 lib/spec/runner/formatter/profile_formatter.rb
dchelimsky-rspec-1.1.11.6 lib/spec/runner/formatter/profile_formatter.rb
dchelimsky-rspec-1.1.11.7 lib/spec/runner/formatter/profile_formatter.rb
dchelimsky-rspec-1.1.11 lib/spec/runner/formatter/profile_formatter.rb
dchelimsky-rspec-1.1.12 lib/spec/runner/formatter/profile_formatter.rb
dchelimsky-rspec-1.1.99.1 lib/spec/runner/formatter/profile_formatter.rb
dchelimsky-rspec-1.1.99.13 lib/spec/runner/formatter/profile_formatter.rb
dchelimsky-rspec-1.1.99.2 lib/spec/runner/formatter/profile_formatter.rb
dchelimsky-rspec-1.1.99.3 lib/spec/runner/formatter/profile_formatter.rb
dchelimsky-rspec-1.1.99.4 lib/spec/runner/formatter/profile_formatter.rb
dchelimsky-rspec-1.1.99.5 lib/spec/runner/formatter/profile_formatter.rb
dchelimsky-rspec-1.1.99.6 lib/spec/runner/formatter/profile_formatter.rb
dchelimsky-rspec-1.1.99.7 lib/spec/runner/formatter/profile_formatter.rb
dchelimsky-rspec-1.1.99.8 lib/spec/runner/formatter/profile_formatter.rb
dchelimsky-rspec-1.1.99.9 lib/spec/runner/formatter/profile_formatter.rb