Created
March 22, 2010 17:59
-
-
Save diasjorge/340325 to your computer and use it in GitHub Desktop.
List all cucumber step definitions
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
# Original Source: http://www.natontesting.com/2010/01/11/updated-script-to-list-all-cucumber-step-definitions/ | |
namespace :cucumber do | |
desc "Generate all step definitions report, opens file in a new browser if you have launchy gem" | |
task :step_definitions do | |
step_definition_dir = "./features/step_definitions" | |
output_file = "step_definitions.html" | |
f = File.new(output_file, "w") | |
f << "<table><th>Regex</th><th>Modifiers</th><th>Step Definition Args</th><th>Source file</th>" | |
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 | |
matches << step_file | |
f << "<tr>" | |
f << "<td>#{matches[0]}</td>" | |
f << "<td>#{matches[1]}</td>" | |
f << "<td>#{matches[2]}</td>" | |
f << "<td><a href=\"#{matches[3]}\">#{matches[3]}</a></td>" | |
f << "</tr>" | |
end | |
end | |
f << "</table>" | |
f.close | |
begin | |
require 'launchy' | |
Launchy::Browser.run(output_file) | |
rescue LoadError | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment