Class: Test::Reporters::Html
- Inherits:
-
Abstract
- Object
- Abstract
- Test::Reporters::Html
- Defined in:
- lib/rubytest/format/html.rb
Overview
HTML Test Reporter
This reporter is rather simplistic and rough at this point –in need of some TLC. Also, it may move to the TAPOUT project rather than be a built-in Ruby-Test reporter. – TODO: Make this more like a microformat and add timer info. ++
Instance Method Summary collapse
- #begin_case(tc) ⇒ Object
- #begin_suite(suite) ⇒ Object
- #begin_test(test) ⇒ Object
- #end_suite(suite) ⇒ Object
- #error(test, exception) ⇒ Object
- #fail(test, exception) ⇒ Object
- #omit(test, exception) ⇒ Object
- #pass(test) ⇒ Object
- #todo(test, exception) ⇒ Object
Instance Method Details
#begin_case(tc) ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rubytest/format/html.rb', line 47 def begin_case(tc) lines = tc.to_s.split("\n") title = lines.shift @body << "<h2>" @body << title @body << "</h2>" @body << "<div>" @body << lines.join("<br/>") @body << "</div>" end |
#begin_suite(suite) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rubytest/format/html.rb', line 16 def begin_suite(suite) timer_reset @html = [] @html << %[<html>] @html << %[<head>] @html << %[<title>Test Report</title>] @html << %[ <style>] @html << %[ html{ background: #fff; margin: 0; padding: 0; font-family: helvetica; }] @html << %[ body{ margin: 0; padding: 0;}] @html << %[ h3{color:#555;}] @html << %[ #main{ margin: 0 auto; color: #110; width: 600px; ] @html << %[ border-right: 1px solid #ddd; border-left: 1px solid #ddd; ] @html << %[ padding: 10px 30px; width: 500px; } ] @html << %[ .lemon{ color: gold; font-size: 22px; font-weight: bold; ] @html << %[ font-family: courier; margin-bottom: -15px;}] @html << %[ .tally{ font-weight: bold; margin-bottom: 10px; }] @html << %[ .omit{ color: cyan; }] @html << %[ .pass{ color: green; }] @html << %[ .fail{ color: red; }] @html << %[ .footer{ font-size: 0.7em; color: #666; margin: 20px 0; }] @html << %[ </style>] @html << %[</head>] @html << %[<body>] @html << %[<div id="main">] @html << %[<div class="lemon">R U B Y - T E S T</div>] @html << %[<h1>Test Report</h1>] @body = [] end |
#begin_test(test) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/rubytest/format/html.rb', line 59 def begin_test(test) if test.respond_to?(:topic) topic = test.topic if @topic != topic @topic = topic @body << "<h3>" @body << "#{topic}" @body << "</h3>" end end end |
#end_suite(suite) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/rubytest/format/html.rb', line 116 def end_suite(suite) @html << "" @html << %[<div class="tally">] @html << tally @html << %[</div>] @html << "" @body << "" @body << %[<div class="footer">] @body << %[Generated by <a href="http://rubyworks.github.com/test">Lemon</a>] @body << %[on #{Time.now}.] @body << %[</div>] @body << "" @body << %[</div>] @body << %[</div>] @body << "" @body << %[</body>] @body << %[</html>] puts @html.join("\n") puts @body.join("\n") end |
#error(test, exception) ⇒ Object
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/rubytest/format/html.rb', line 90 def error(test, exception) @body << %[<li class="error">] @body << "%s %s" % ["ERROR", test.to_s] @body << "<pre>" @body << " ERROR #{exception.class}" @body << " #{exception}" @body << " " + clean_backtrace(exception).join("\n ") @body << "</pre>" @body << %[</li>] end |
#fail(test, exception) ⇒ Object
79 80 81 82 83 84 85 86 87 |
# File 'lib/rubytest/format/html.rb', line 79 def fail(test, exception) @body << %[<li class="fail">] @body << "%s %s" % ["FAIL", test.to_s] @body << "<pre>" @body << " FAIL #{clean_backtrace(exception)[0]}" @body << " #{exception}" @body << "</pre>" @body << %[</li>] end |
#omit(test, exception) ⇒ Object
109 110 111 112 113 |
# File 'lib/rubytest/format/html.rb', line 109 def omit(test, exception) @body << %[<li class="omit">] @body << "%s %s" % ["OMIT", test.to_s] @body << %[</li>] end |
#pass(test) ⇒ Object
72 73 74 75 76 |
# File 'lib/rubytest/format/html.rb', line 72 def pass(test) @body << %[<li class="pass">] @body << "%s %s" % ["PASS", test.to_s] @body << %[</li>] end |
#todo(test, exception) ⇒ Object
102 103 104 105 106 |
# File 'lib/rubytest/format/html.rb', line 102 def todo(test, exception) @body << %[<li class="pending">] @body << "%s %s" % ["PENDING", test.to_s] @body << %[</li>] end |