class Cucumber::Formatter::Usage

Public Class Methods

new(runtime, path_or_io, options) click to toggle source
# File lib/cucumber/formatter/usage.rb, line 13
def initialize(runtime, path_or_io, options)
  @runtime = runtime
  @io = ensure_io(path_or_io)
  @options = options
  @stepdef_to_match = Hash.new { |h, stepdef_key| h[stepdef_key] = [] }
  @total_duration = 0
  @matches = {}
  runtime.configuration.on_event :step_match do |event|
    @matches[event.test_step.source] = event.step_match
  end
end

Public Instance Methods

after_test_step(test_step, result) click to toggle source
# File lib/cucumber/formatter/usage.rb, line 25
def after_test_step(test_step, result)
  return if HookQueryVisitor.new(test_step).hook?

  step_match = @matches[test_step.source]
  step_definition = step_match.step_definition
  stepdef_key = StepDefKey.new(step_definition.regexp_source, step_definition.location)
  unless @stepdef_to_match[stepdef_key].map { |key| key[:location] }.include? test_step.location
    duration = DurationExtractor.new(result).result_duration

    @stepdef_to_match[stepdef_key] << {
      keyword: test_step.source.last.keyword,
      step_match: step_match,
      status: result.to_sym,
      location: test_step.location,
      duration: duration
    }
  end
  super
end

Private Instance Methods

add_unused_stepdefs() click to toggle source
# File lib/cucumber/formatter/usage.rb, line 128
def add_unused_stepdefs
  @runtime.unmatched_step_definitions.each do |step_definition|
    stepdef_key = StepDefKey.new(step_definition.regexp_source, step_definition.location)
    @stepdef_to_match[stepdef_key] = []
  end
end
aggregate_info() click to toggle source
# File lib/cucumber/formatter/usage.rb, line 109
def aggregate_info
  @stepdef_to_match.each do |key, steps|
    if steps.empty?
      key.status = :skipped
      key.mean_duration = 0
    else
      key.status = 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
max_length() click to toggle source
# File lib/cucumber/formatter/usage.rb, line 95
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 103
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 99
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() click to toggle source
worst_status(statuses) click to toggle source
# File lib/cucumber/formatter/usage.rb, line 122
def worst_status(statuses)
  [:passed, :undefined, :pending, :skipped, :failed].find do |status|
    statuses.include?(status)
  end
end