-
-
Save developer88/440df356c09a6e3eeca3c2404ae1c77d to your computer and use it in GitHub Desktop.
list all available cucumber steps - (rake cucumber:steps)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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