class Tapout::Reporters::Html

HTML Test Reporter

This reporter is rather simplistic and rough at this point –in needs of some TLC.

Public Instance Methods

error(entry) click to toggle source
# File lib/tapout/reporters/html_reporter.rb, line 85
def error(entry)
  e = entry['exception']

  puts %[<li class="error">]
  puts "ERROR "
  puts e['message'].to_s
  puts "<pre>"
  puts clean_backtrace(e['backtrace']).join("\n")
  puts "</pre>"
  puts %[</li>]
  # TODO: Add captured_stdout and _stderr
end
fail(entry) click to toggle source
# File lib/tapout/reporters/html_reporter.rb, line 72
def fail(entry)
  e = entry['exception']

  puts %[<li class="fail">]
  puts "FAIL #{e['message']}"
  puts "<pre>"
  puts clean_backtrace(e['backtrace']).join("\n")
  puts "</pre>"
  puts %[</li>]
  # TODO: Add captured_stdout and _stderr
end
finish_suite(entry) click to toggle source
# File lib/tapout/reporters/html_reporter.rb, line 119
def finish_suite(entry)
  puts ""
  puts %[<div class="tally">]
  puts tally_message(entry)
  puts %[</div>]
  puts ""
  puts ""
  puts %[<div class="footer">]
  puts %[Generated by <a href="http://rubyworks.github.com/tapout">TAPOUT</a>]
  puts %[on #{Time.now}.]
  puts %[</div>]
  puts ""
  puts %[</div>]
  puts %[</div>]
  puts ""
  puts %[</body>]
  puts %[</html>]
end
omit(entry) click to toggle source
# File lib/tapout/reporters/html_reporter.rb, line 109
def omit(entry)
  e = entry['exception']

  puts %[<li class="omit">]
  puts "OMIT "
  puts e['message'].to_s
  puts %[</li>]
end
pass(entry) click to toggle source
# File lib/tapout/reporters/html_reporter.rb, line 65
def pass(entry)
  puts %[<li class="pass">]
  puts "%s %s" % [ "PASS", entry['label'] ]
  puts %[</li>]
end
start_case(entry) click to toggle source
# File lib/tapout/reporters/html_reporter.rb, line 44
def start_case(entry)
  body = []

  puts "<h2>"
  puts entry['label']
  puts "</h2>"

  puts body.join("\n")
end
start_suite(entry) click to toggle source
# File lib/tapout/reporters/html_reporter.rb, line 15
def start_suite(entry)
  timer_reset

  puts %[<html>]
  puts %[<head>]
  puts %[<title>Test Report</title>]
  puts %[  <style>]
  puts %[    html{ background: #fff; margin: 0; padding: 0; font-family: helvetica; }]
  puts %[    body{ margin: 0; padding: 0;}]
  puts %[    h3{color:#555;}]
  puts %[    #main{ margin: 0 auto; color: #110; width: 600px; ]
  puts %[           border-right: 1px solid #ddd; border-left: 1px solid #ddd; ]
  puts %[           padding: 10px 30px; width: 500px; } ]
  puts %[    .title{ color: gold; font-size: 22px; font-weight: bold; ]
  puts %[            font-family: courier; margin-bottom: -15px;}]
  puts %[    .tally{ font-weight: bold; margin-bottom: 10px; }]
  puts %[    .omit{ color: cyan; }]
  puts %[    .pass{ color: green; }]
  puts %[    .fail{ color: red; }]
  puts %[    .footer{ font-size: 0.7em; color: #666; margin: 20px 0; }]
  puts %[  </style>]
  puts %[</head>]
  puts %[<body>]
  puts %[<div id="main">]
  puts %[<div class="title">R U B Y - T E S T</div>]
  puts %[<h1>Test Report</h1>]
end
start_test(entry) click to toggle source
# File lib/tapout/reporters/html_reporter.rb, line 55
def start_test(entry)
  if subtext = entry['subtext']
    if @subtext != subtext
      @subtext = subtext
      puts "<h3>#{subtext}</h3>"
    end
  end
end
todo(entry) click to toggle source
# File lib/tapout/reporters/html_reporter.rb, line 99
def todo(entry)
  e = entry['exception']

  puts %[<li class="pending">]
  puts "TODO "
  puts e['message'].to_s
  puts %[</li>]
end

Private Instance Methods

timer() click to toggle source
# File lib/tapout/reporters/html_reporter.rb, line 141
def timer
  secs  = Time.now - @time
  @time = Time.now
  return "%0.5fs" % [secs.to_s]
end
timer_reset() click to toggle source
# File lib/tapout/reporters/html_reporter.rb, line 148
def timer_reset
  @time = Time.now
end