If you’re using cucumber you probably have step definitions split across several files, and you’re probably using a tool that doesn’t do a good job of listing the available step definitions (one of the biggest downsides of using cucumber).
What follows is a script that will list them all. It’s fairly rudimentary in that for each step definition it just lists the regex, any regex modifiers and the step definition arguments. It does everything I need at the moment so I haven’t developed it any further. Do with it what you will.
root_test_folder = "../my_project/features/support"
Dir.glob(File.join(root_test_folder,'**/*.rb')).each do |support_file|
File.new(support_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
matches[0] = Regexp.new(matches[0])
puts matches.inspect
end
end
Set the root_test_folder variable to the relevant location, run the file, and your console will be filled with what amounts to a step definition dictionary!
Better:
cucumber –dry-run –format usage features
Hi Aslak, there’s an even better version here:
http://www.natontesting.com/2010/01/11/updated-script-to-list-all-cucumber-step-definitions/
…which mentions using the -f stepdefs formatter. What I wanted was to create a ‘dictionary’ of step definitions to give to people who write tests. The usage formatter does that but since it also lists where the steps are used in feature files it adds noise to the output I wanted.
What I ended up using is:
cucumber -d -f stepdefs
…because it lists only available step definitions, not where they are used.
I’m using pickle and I have been unable to use –dry-run with it
What… with “-f stepdefs”? With my script? (Yeah, that won’t work) With cucumber?