class Cucumber::Formatter::Usage

Public Class Methods

new(step_mother, path_or_io, options) click to toggle source
# File lib/cucumber/formatter/usage.rb, line 13
def initialize(step_mother, path_or_io, options)
  @step_mother = step_mother
  @io = ensure_io(path_or_io, "usage")
  @options = options
  @stepdef_to_match = Hash.new{|h,stepdef_key| h[stepdef_key] = []}
end

Public Instance Methods

add_unused_stepdefs() click to toggle source
# File lib/cucumber/formatter/usage.rb, line 119
def add_unused_stepdefs
  @step_mother.unmatched_step_definitions.each do |step_definition|
    stepdef_key = StepDefKey.new(step_definition.regexp_source, step_definition.file_colon_line)
    @stepdef_to_match[stepdef_key] = []
  end
end
after_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background) click to toggle source
# File lib/cucumber/formatter/usage.rb, line 29
def after_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background)
  if step_match.name.nil? # nil if it's from a scenario outline
    stepdef_key = StepDefKey.new(step_match.step_definition.regexp_source, step_match.step_definition.file_colon_line)

    @stepdef_to_match[stepdef_key] << {
      :keyword => keyword, 
      :step_match => step_match, 
      :status => status, 
      :file_colon_line => @step.file_colon_line,
      :duration => @duration
    }
  end
  super
end
aggregate_info() click to toggle source
# File lib/cucumber/formatter/usage.rb, line 106
def aggregate_info
  @stepdef_to_match.each do |key, steps|
    if steps.empty?
      key.status = :skipped
      key.mean_duration = 0
    else
      key.status = Ast::StepInvocation.worst_status(steps.map{|step| step[:status]})
      total_duration = steps.inject(0) {|sum, step| step[:duration] + sum}
      key.mean_duration = total_duration / steps.length
    end
  end
end
before_step(step) click to toggle source
# File lib/cucumber/formatter/usage.rb, line 20
def before_step(step)
  @step = step
  @start_time = Time.now
end
before_step_result(*args) click to toggle source
# File lib/cucumber/formatter/usage.rb, line 25
def before_step_result(*args)
  @duration = Time.now - @start_time
end
max_length() click to toggle source
# File lib/cucumber/formatter/usage.rb, line 92
def max_length
  [max_stepdef_length, max_step_length].compact.max
end
max_step_length() click to toggle source
# File lib/cucumber/formatter/usage.rb, line 100
def max_step_length
  @stepdef_to_match.values.to_a.flatten.map do |step|
    step[:keyword].unpack('U*').length + step[:step_match].format_args.unpack('U*').length
  end.max
end
max_stepdef_length() click to toggle source
# File lib/cucumber/formatter/usage.rb, line 96
def max_stepdef_length
  @stepdef_to_match.keys.flatten.map{|key| key.regexp_source.unpack('U*').length}.max
end
print_step_definition(stepdef_key) click to toggle source
print_steps(stepdef_key) click to toggle source
print_summary(features) click to toggle source