Skip to content

Instantly share code, notes, and snippets.

@developer88
Forked from andrzejsliwa/gist:778535
Last active January 17, 2017 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save developer88/440df356c09a6e3eeca3c2404ae1c77d to your computer and use it in GitHub Desktop.
Save developer88/440df356c09a6e3eeca3c2404ae1c77d to your computer and use it in GitHub Desktop.
list all available cucumber steps - (rake cucumber:steps)
# based on http://www.natontesting.com/2010/01/11/updated-script-to-list-all-cucumber-step-definitions/
#
desc 'List all defined steps'
task :steps do
require 'hirb'
extend Hirb::Console
puts "CUCUMBER steps:"
puts ""
step_definition_dir = "features/step_definitions"
results = {}
Dir.glob(File.join(step_definition_dir,'**/*.rb')).each do |step_file|
File.new(step_file).read.each_line.each_with_index do |line, number|
next unless line =~ /^\s*(?:Given|When|Then)\s+|\//
res = /(Given|When|Then)[\s\(]*\/(.*)\/([imxo]*)[\s\)]*do\s*(?:$|\|(.*)\|)/.match(line)
next unless res
matches = res.captures
results[matches[0]] ||= []
results[matches[0]] << {
step: matches[1],
file: step_file,
modifier: matches[2],
args: matches[3]
}
end
end
results.keys.each do |key|
puts "#{key}:"
puts ""
table results[key], :resize => false, :fields=>[:step, :modifier, :args, :file]
puts ""
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment