Skip to content

Instantly share code, notes, and snippets.

@rocknrollMarc
Created August 15, 2014 09:37
Show Gist options
  • Save rocknrollMarc/6dc6de955276c2c13a64 to your computer and use it in GitHub Desktop.
Save rocknrollMarc/6dc6de955276c2c13a64 to your computer and use it in GitHub Desktop.
ruby Step definition parser cucumber, gherkin
step_definition_dir = "../features/step_definitions"
steps = []
Dir.glob(File.join(step_definition_dir,'**/*.rb')).each do |step_file|
File.new(step_file).read.each_line do |line|
next unless line =~ /^\s*(?:Given|When|Then)\s+\//
matches = /(Given|When|Then)\s*\/(.*)\/([imxo]*)\s*do\s*(?:$|\|(.*)\|)/.match(line).captures
type = matches[0]
matches[1] = Regexp.new(matches[1])
step = matches[1].inspect
step = step[2..step.length-3]
steps << type + " " + step
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment