Sha256: 05455164c209c67e21a4911626062d72be61b3f3afa7d4ba5e18e98bdd5c2ff0

Contents?: true

Size: 1.13 KB

Versions: 65

Compression:

Stored size: 1.13 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
      end
    end
  end
end

Version data entries

65 entries across 65 versions & 14 rubygems

Version Path
rspec-instructure-1.3.3 lib/spec/runner/formatter/profile_formatter.rb
radiant-1.0.0 ruby-debug/ruby/1.8/gems/rspec-1.3.2/lib/spec/runner/formatter/profile_formatter.rb
rspec-1.3.2 lib/spec/runner/formatter/profile_formatter.rb
rspec-1.3.1 lib/spec/runner/formatter/profile_formatter.rb
rspec-1.3.1.rc lib/spec/runner/formatter/profile_formatter.rb
rspec-1.3.0 lib/spec/runner/formatter/profile_formatter.rb
hubbub-0.0.11 lib/vendor/plugins/rspec/lib/spec/runner/formatter/profile_formatter.rb
hubbub-0.0.10 lib/vendor/plugins/rspec/lib/spec/runner/formatter/profile_formatter.rb
hubbub-0.0.9 lib/vendor/plugins/rspec/lib/spec/runner/formatter/profile_formatter.rb
hubbub-0.0.8 lib/vendor/plugins/rspec/lib/spec/runner/formatter/profile_formatter.rb
hubbub-0.0.6 lib/vendor/plugins/rspec/lib/spec/runner/formatter/profile_formatter.rb
simple-templater-0.0.1.4 gems/gems/rspec-1.2.9/lib/spec/runner/formatter/profile_formatter.rb
media-path-0.1.2 vendor/rspec/lib/spec/runner/formatter/profile_formatter.rb
simple-templater-0.0.1.3 vendor/rspec/lib/spec/runner/formatter/profile_formatter.rb
pupu-0.0.2.pre vendor/rspec/lib/spec/runner/formatter/profile_formatter.rb
media-path-0.1.1.pre vendor/rspec/lib/spec/runner/formatter/profile_formatter.rb
simple-templater-0.0.1.2 vendor/rspec/lib/spec/runner/formatter/profile_formatter.rb
media-path-0.1.1 vendor/rspec/lib/spec/runner/formatter/profile_formatter.rb
simple-templater-0.0.1.1 vendor/rspec/lib/spec/runner/formatter/profile_formatter.rb
pupu-0.0.2 vendor/rspec/lib/spec/runner/formatter/profile_formatter.rb