Skip to content

Instantly share code, notes, and snippets.

@masami256
Created February 8, 2013 05:10
Show Gist options
  • Save masami256/4736760 to your computer and use it in GitHub Desktop.
Save masami256/4736760 to your computer and use it in GitHub Desktop.
cucumberのhtml形式のログを読んでシナリオ数、pass数、fail数をcsv形式で出力
#!/usr/bin/env ruby
# vim:ts=4
require "find"
require "optparse"
def read_file(name, offset)
f = open(name)
str = f.read
f.close
tmp = name[offset + 12..name.size]
y = tmp[0..3]
m = tmp[4..5]
d = tmp[6..7]
# "224 scenarios (35 failed, 189 passed)<br />935 steps (35 failed, 15 skipped, 885 passed)
scenarios = str.scan(/(\d+) scenarios/)
failed = str.scan(/(\d+) failed,/)
passed = str.scan(/(\d+) passed\)/)
return sprintf "%s/%s/%s,%s,%s,%s\n", y, m, d, scenarios[0][0], failed[0][0], passed[0][0]
end
def print_header()
printf "date, scenarios, failed, passed\n";
end
def print_line(line)
printf "%s", line
end
def create_all_report(dir_name)
print_header()
Find.find(dir_name) { |name|
idx = name.index("test_result_")
if idx != nil then
line = read_file(name, idx)
print_line(line)
end
}
end
def create_single_report(name)
if File.exist?(name) == false then
printf "File [%s] is not found\n", name
return
end
print_header()
idx = name.index("test_result_")
if idx != nil then
line = read_file(name, idx)
print_line(line)
end
end
if __FILE__ == $0
ProgramConfig = Hash.new
opts = OptionParser.new
opts.on("-d dir") { |v| create_all_report(v) }
opts.on("-f file") { |v| create_single_report(v) }
opts.on("-h") { |v| printf "usage report.rb [df] [name]\n-d: directory name\n-f file name\n" }
opts.parse!(ARGV)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment