Skip to content

Instantly share code, notes, and snippets.

@enriquez
Created July 4, 2010 16:44
Show Gist options
  • Save enriquez/463570 to your computer and use it in GitHub Desktop.
Save enriquez/463570 to your computer and use it in GitHub Desktop.
require 'cucumber/step_definition_light'
class StepUsage
class StepDefKey < Cucumber::StepDefinitionLight
end
def initialize(step_mother, io, options)
@step_mother = step_mother
@io = io
@stepdef_to_match = Hash.new{|h,stepdef_key| h[stepdef_key] = []}
end
def before_step(step)
@step = step
end
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
}
@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
@keys = @stepdef_to_match.keys.sort { |a,b| a.file_colon_line <=> b.file_colon_line }
end
end
def after_features(features)
print_summary
end
private
def print_summary
last_step_file = @keys.first.file_colon_line.gsub(/:\d+$/, "")
@io.puts last_step_file
@keys.each do |stepdef_key|
this_step_file = stepdef_key.file_colon_line.gsub(/:\d+$/, "")
if last_step_file != this_step_file
@io.puts
@io.puts this_step_file
end
last_step_file = this_step_file
@io.puts " #{stepdef_key.regexp_source} # #{stepdef_key.file_colon_line}"
@stepdef_to_match[stepdef_key].collect { |step| step[:file_colon_line] }.uniq.each { |file_colon_line| @io.puts " #{file_colon_line}" }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment