Skip to content

Instantly share code, notes, and snippets.

@tychobrailleur
Created March 5, 2012 13:18
Show Gist options
  • Save tychobrailleur/1978277 to your computer and use it in GitHub Desktop.
Save tychobrailleur/1978277 to your computer and use it in GitHub Desktop.
Extract cucumber-jvm mappings from stepdefs ("already implemented stepdefs") and prints them in alphabetical order
require 'erb'
mappings = []
features = File.join("**", "*.java")
current_dir = ARGV[0]
Dir.chdir(current_dir)
Dir.glob(features).each do |file_name|
puts "Processing #{file_name}" if $DEBUG
File.open(file_name).each do |line|
mapping = line.scan(/@(When|Then|And|Given)\("\^?(.+?)\$?"\)/)
mappings << mapping[0][1] if not mapping.empty?
end
end
@mappings = mappings.map{ |m| m.capitalize }.sort
simple_template =<<TEMPLATE
<html>
<body>
<% for @mapping in @mappings %>
<p><%= @mapping %></p>
<% end %>
</body>
</html>
TEMPLATE
output_file = File.join(File.dirname(__FILE__), "mappings.html")
renderer = ERB.new(simple_template)
File.open(output_file, "w") { |f| f.write(renderer.result()) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment