Created
April 5, 2011 17:45
-
-
Save harvgill/904091 to your computer and use it in GitHub Desktop.
Parses all your cucumber feature files and outputs a sexy html file. Just drop this file in the same folder as your features folder, and run it. Gives you an overall view of everything you have automated.
This file contains 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
def print_header | |
@out.puts '<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |
<title>Automation Documentation</title> | |
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script> | |
<script type="text/javascript"> | |
$(document).ready(function(){ | |
$(".feature_body").hide(); | |
$(".feature_head").click(function(){ | |
$(this).next(".feature_body").slideToggle(300); | |
}); | |
$(".feature_head").hover( | |
function () { | |
$(this).append($("<span>Toggle Scenarios on/off</span>")); | |
}, | |
function () { | |
$(this).find("span:last").remove(); | |
} | |
); | |
$(".scenario_body").hide(); | |
$(".scenario_head").click(function(){ | |
$(this).next(".scenario_body").slideToggle(300); | |
}); | |
$(".scenario_head").hover( | |
function () { | |
$(this).append($("<span>Toggle Steps on/off</span>")); | |
}, | |
function () { | |
$(this).find("span:last").remove(); | |
} | |
); | |
}); | |
</script> | |
<style type="text/css"> | |
body { | |
margin: 10px auto; | |
width: 570px; | |
font: 75%/120% Verdana,Arial, Helvetica, sans-serif; | |
} | |
p { | |
padding: 0 0 1em; | |
} | |
.feature_list { | |
margin: 0px; | |
padding: 0px; | |
width: 800px; | |
} | |
.feature_head { | |
padding: 5px 10px; | |
cursor: pointer; | |
position: relative; | |
background-color:#cccccc; | |
margin:1px; | |
} | |
.feature_body { | |
padding: 5px 10px 15px; | |
background-color:#F4F4F8; | |
} | |
.scenario_head { | |
padding: 5px 10px; | |
cursor: pointer; | |
position: relative; | |
background-color:#99cc66; | |
margin:1px; | |
} | |
.scenario_body { | |
padding: 5px 10px 15px; | |
background-color:#F4F4F8; | |
} | |
</style> | |
</head>' | |
@out.puts '<html><body>' | |
@out.puts '<BR>' | |
@out.puts '<div class="feature_list">' | |
end | |
def begin_feature(line) | |
@out.puts '<p class="feature_head">' + line + '</p>' | |
@out.puts "<div class='feature_body'>" | |
end | |
def end_feature() | |
@out.puts "</div>" | |
@out.puts '<BR><BR>' | |
end | |
def begin_scenario(line) | |
@out.puts '<p class="scenario_head">' + line + '</p>' | |
@out.puts "<div class='scenario_body'>" | |
end | |
def end_scenario() | |
@out.puts "</div><BR>" | |
end | |
def print_step(line) | |
@out.puts line | |
@out.puts '<BR>' | |
end | |
def print_footer | |
@out.puts '</body></html>' | |
end | |
@out = File.open('automation_documentation.html', 'w') | |
@out.sync = true | |
state = 'LFF' | |
print_header | |
root_dir = File.expand_path(File.dirname(__FILE__)) | |
feature_dir = root_dir + '/features' | |
feature_file_glob = File.join("**", "*.feature") | |
feature_files = Dir.glob(feature_file_glob) | |
feature_files.each do |entry| | |
full_path = root_dir + '/' + entry | |
@file_name = entry.split('/').last | |
infile = File.open(full_path) | |
infile.each do |line| | |
if(line.match(/[f|F]eature:/) && state == 'LFF') | |
begin_feature(line) | |
state = 'LFS' | |
elsif(line.match(/[s|S]cenario:/) && state == 'LFS') | |
begin_scenario(line) | |
state = 'S' | |
elsif(line.match(/[s|S]cenario:/) && state == 'S') | |
end_scenario | |
begin_scenario(line) | |
state = 'S' | |
elsif(line.match(/[Given|When|Then]/) && state == 'S') | |
print_step(line) | |
else | |
print_step(line) | |
end | |
end | |
end_scenario | |
end_feature | |
state = 'LFF' | |
infile.close | |
end | |
print_footer | |
@out.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment