# File lib/cucumber/formatter/usage.rb, line 13 13: def initialize(step_mother, path_or_io, options) 14: @step_mother = step_mother 15: @io = ensure_io(path_or_io, "usage") 16: @options = options 17: @stepdef_to_match = Hash.new{|h,stepdef_key| h[stepdef_key] = []} 18: end
# File lib/cucumber/formatter/usage.rb, line 119 119: def add_unused_stepdefs 120: @step_mother.unmatched_step_definitions.each do |step_definition| 121: stepdef_key = StepDefKey.new(step_definition.regexp_source, step_definition.file_colon_line) 122: @stepdef_to_match[stepdef_key] = [] 123: end 124: end
# File lib/cucumber/formatter/usage.rb, line 29 29: def after_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background) 30: if step_match.name.nil? # nil if it's from a scenario outline 31: stepdef_key = StepDefKey.new(step_match.step_definition.regexp_source, step_match.step_definition.file_colon_line) 32: 33: @stepdef_to_match[stepdef_key] << { 34: :keyword => keyword, 35: :step_match => step_match, 36: :status => status, 37: :file_colon_line => @step.file_colon_line, 38: :duration => @duration 39: } 40: end 41: super 42: end
# File lib/cucumber/formatter/usage.rb, line 106 106: def aggregate_info 107: @stepdef_to_match.each do |key, steps| 108: if steps.empty? 109: key.status = :skipped 110: key.mean_duration = 0 111: else 112: key.status = Ast::StepInvocation.worst_status(steps.map{|step| step[:status]}) 113: total_duration = steps.inject(0) {|sum, step| step[:duration] + sum} 114: key.mean_duration = total_duration / steps.length 115: end 116: end 117: end
# File lib/cucumber/formatter/usage.rb, line 20 20: def before_step(step) 21: @step = step 22: @start_time = Time.now 23: end
# File lib/cucumber/formatter/usage.rb, line 25 25: def before_step_result(*args) 26: @duration = Time.now - @start_time 27: end
# File lib/cucumber/formatter/usage.rb, line 92 92: def max_length 93: [max_stepdef_length, max_step_length].compact.max 94: end
# File lib/cucumber/formatter/usage.rb, line 100 100: def max_step_length 101: @stepdef_to_match.values.to_a.flatten.map do |step| 102: step[:keyword].unpack('U*').length + step[:step_match].format_args.unpack('U*').length 103: end.max 104: end
# File lib/cucumber/formatter/usage.rb, line 96 96: def max_stepdef_length 97: @stepdef_to_match.keys.flatten.map{|key| key.regexp_source.unpack('U*').length}.max 98: end
# File lib/cucumber/formatter/usage.rb, line 67 67: def print_step_definition(stepdef_key) 68: @io.print format_string(sprintf("%.7f", stepdef_key.mean_duration), :skipped) + " " unless @options[:dry_run] 69: @io.print format_string(stepdef_key.regexp_source, stepdef_key.status) 70: if @options[:source] 71: indent = max_length - stepdef_key.regexp_source.unpack('U*').length 72: line_comment = " # #{stepdef_key.file_colon_line}".indent(indent) 73: @io.print(format_string(line_comment, :comment)) 74: end 75: @io.puts 76: end
# File lib/cucumber/formatter/usage.rb, line 78 78: def print_steps(stepdef_key) 79: @stepdef_to_match[stepdef_key].each do |step| 80: @io.print " " 81: @io.print format_string(sprintf("%.7f", step[:duration]), :skipped) + " " unless @options[:dry_run] 82: @io.print format_step(step[:keyword], step[:step_match], step[:status], nil) 83: if @options[:source] 84: indent = max_length - (step[:keyword].unpack('U*').length + step[:step_match].format_args.unpack('U*').length) 85: line_comment = " # #{step[:file_colon_line]}".indent(indent) 86: @io.print(format_string(line_comment, :comment)) 87: end 88: @io.puts 89: end 90: end
# File lib/cucumber/formatter/usage.rb, line 44 44: def print_summary(features) 45: add_unused_stepdefs 46: aggregate_info 47: 48: if @options[:dry_run] 49: keys = @stepdef_to_match.keys.sort {|a,b| a.regexp_source <=> b.regexp_source} 50: else 51: keys = @stepdef_to_match.keys.sort {|a,b| a.mean_duration <=> b.mean_duration}.reverse 52: end 53: 54: keys.each do |stepdef_key| 55: print_step_definition(stepdef_key) 56: 57: if @stepdef_to_match[stepdef_key].any? 58: print_steps(stepdef_key) 59: else 60: @io.puts(" " + format_string("NOT MATCHED BY ANY STEPS", :failed)) 61: end 62: end 63: @io.puts 64: super 65: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.