Sha256: ada317d310af419ee405eb44722d03fd382b98968692fecc63a15e7341deee53

Contents?: true

Size: 1.07 KB

Versions: 3

Compression:

Stored size: 1.07 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

3 entries across 3 versions & 1 rubygems

Version Path
picolena-0.1.6 rails_plugins/rspec/lib/spec/runner/formatter/profile_formatter.rb
picolena-0.1.7 rails_plugins/rspec/lib/spec/runner/formatter/profile_formatter.rb
picolena-0.1.8 rails_plugins/rspec/lib/spec/runner/formatter/profile_formatter.rb