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 = Regexp.new(matches) puts matches.inspect end end
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!