Class: Spec::Runner::Formatter::ProfileFormatter

Inherits:
ProgressBarFormatter show all
Defined in:
lib/vendor/plugins/rspec/lib/spec/runner/formatter/profile_formatter.rb

Instance Attribute Summary

Attributes inherited from BaseTextFormatter

#example_group, #output

Instance Method Summary collapse

Methods inherited from ProgressBarFormatter

#example_failed, #example_pending

Methods included from NOOPMethodMissing

#respond_to?

Methods inherited from BaseTextFormatter

#close, #colorize_failure, #colourise, #dump_failure, #dump_pending, #dump_summary, #example_group_started, #example_pending, #format_backtrace

Methods inherited from BaseFormatter

#add_example_group, #close, #dump_failure, #dump_pending, #dump_summary, #example_failed, #example_group_started, #example_pending

Constructor Details

#initialize(options, where) ⇒ ProfileFormatter

Returns a new instance of ProfileFormatter.



8
9
10
11
# File 'lib/vendor/plugins/rspec/lib/spec/runner/formatter/profile_formatter.rb', line 8

def initialize(options, where)
  super
  @example_times = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Spec::Runner::Formatter::NOOPMethodMissing

Instance Method Details

#example_passed(example) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/vendor/plugins/rspec/lib/spec/runner/formatter/profile_formatter.rb', line 21

def example_passed(example)
  super
  @example_times << [
    example_group.description,
    example.description,
    Time.now - @time
  ]
end

#example_started(example) ⇒ Object



17
18
19
# File 'lib/vendor/plugins/rspec/lib/spec/runner/formatter/profile_formatter.rb', line 17

def example_started(example)
  @time = Time.now
end

#start(count) ⇒ Object



13
14
15
# File 'lib/vendor/plugins/rspec/lib/spec/runner/formatter/profile_formatter.rb', line 13

def start(count)
  @output.puts "Profiling enabled."
end

#start_dumpObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/vendor/plugins/rspec/lib/spec/runner/formatter/profile_formatter.rb', line 30

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