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

Inherits:
ProgressBarFormatter show all
Defined in:
lib/gems/rspec-1.1.12/lib/spec/runner/formatter/profile_formatter.rb

Instance Attribute Summary

Attributes inherited from BaseTextFormatter

#output, #pending_examples

Attributes inherited from BaseFormatter

#example_group, #options, #where

Instance Method Summary collapse

Methods inherited from ProgressBarFormatter

#example_failed, #example_pending

Methods inherited from BaseTextFormatter

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

Methods inherited from BaseFormatter

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

Constructor Details

#initialize(options, where) ⇒ ProfileFormatter

Returns a new instance of ProfileFormatter.



8
9
10
11
# File 'lib/gems/rspec-1.1.12/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

#method_missing(sym, *args) ⇒ Object



45
46
47
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/formatter/profile_formatter.rb', line 45

def method_missing(sym, *args)
  # ignore
end

Instance Method Details

#example_passed(example) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/gems/rspec-1.1.12/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/gems/rspec-1.1.12/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/gems/rspec-1.1.12/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/gems/rspec-1.1.12/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