Files

Class/Module Index [+]

Quicksearch

ProfileFormatter

Public Class Methods

new(out=nil) click to toggle source
# File lib/mspec/runner/formatters/profile.rb, line 5
def initialize(out=nil)
  super

  @describe_name = nil
  @describe_time = nil
  @describes = []
  @its = []
end

Public Instance Methods

after(state) click to toggle source

Callback for the MSpec :after event. Prints a newline to finish the description string output.

# File lib/mspec/runner/formatters/profile.rb, line 41
def after(state)
  @its << [@describe_name, @it_name, Time.now.to_f - @it_time]
  super
end
before(state) click to toggle source

Callback for the MSpec :before event. Prints the it block string.

# File lib/mspec/runner/formatters/profile.rb, line 32
def before(state)
  super

  @it_name = state.it
  @it_time = Time.now.to_f
end
enter(describe) click to toggle source

Callback for the MSpec :enter event. Prints the describe block string.

# File lib/mspec/runner/formatters/profile.rb, line 21
def enter(describe)
  if @describe_time
    @describes << [@describe_name, Time.now.to_f - @describe_time]
  end

  @describe_name = describe
  @describe_time = Time.now.to_f
end
finish() click to toggle source
# File lib/mspec/runner/formatters/profile.rb, line 46
def finish
  puts "\nProfiling info:"

  desc = @describes.sort { |a,b| b.last <=> a.last }
  desc.delete_if { |a| a.last <= 0.001 }
  show = desc[0, 100]

  puts "Top #{show.size} describes:"

  show.each do |des, time|
    printf "%3.3f - %s\n", time, des
  end

  its = @its.sort { |a,b| b.last <=> a.last }
  its.delete_if { |a| a.last <= 0.001 }
  show = its[0, 100]

  puts "\nTop #{show.size} its:"
  show.each do |des, it, time|
    printf "%3.3f - %s %s\n", time, des, it
  end

  super
end
register() click to toggle source
# File lib/mspec/runner/formatters/profile.rb, line 14
def register
  super
  MSpec.register :enter, self
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.