Included Modules

Class Index [+]

Quicksearch

Spec::Runner::Formatter::HtmlFormatter

Public Class Methods

new(options, output) click to toggle source
    # File lib/spec/runner/formatter/html_formatter.rb, line 12
12:         def initialize(options, output)
13:           super
14:           @example_group_number = 0
15:           @example_number = 0
16:           @header_red = nil
17:         end

Public Instance Methods

dump_failure(counter, failure) click to toggle source
     # File lib/spec/runner/formatter/html_formatter.rb, line 116
116:         def dump_failure(counter, failure)
117:         end
dump_summary(duration, example_count, failure_count, pending_count) click to toggle source
     # File lib/spec/runner/formatter/html_formatter.rb, line 119
119:         def dump_summary(duration, example_count, failure_count, pending_count)
120:           if dry_run?
121:             totals = "This was a dry-run"
122:           else
123:             totals = "#{example_count} example#{'s' unless example_count == 1}, #{failure_count} failure#{'s' unless failure_count == 1}"
124:             totals << ", #{pending_count} pending" if pending_count > 0  
125:           end
126:           @output.puts "<script type=\"text/javascript\">document.getElementById('duration').innerHTML = \"Finished in <strong>#{duration} seconds</strong>\";</script>"
127:           @output.puts "<script type=\"text/javascript\">document.getElementById('totals').innerHTML = \"#{totals}\";</script>"
128:           @output.puts "</div>"
129:           @output.puts "</div>"
130:           @output.puts "</body>"
131:           @output.puts "</html>"
132:           @output.flush
133:         end
example_failed(example, counter, failure) click to toggle source
    # File lib/spec/runner/formatter/html_formatter.rb, line 67
67:         def example_failed(example, counter, failure)
68:           extra = extra_failure_content(failure)
69:           failure_style = failure.pending_fixed? ? 'pending_fixed' : 'failed'
70:           @output.puts "    <script type=\"text/javascript\">makeRed('rspec-header');</script>" unless @header_red
71:           @header_red = true
72:           @output.puts "    <script type=\"text/javascript\">makeRed('example_group_#{example_group_number}');</script>" unless @example_group_red
73:           @example_group_red = true
74:           move_progress
75:           @output.puts "    <dd class=\"spec #{failure_style}\">"
76:           @output.puts "      <span class=\"failed_spec_name\">#{h(example.description)}</span>"
77:           @output.puts "      <div class=\"failure\" id=\"failure_#{counter}\">"
78:           @output.puts "        <div class=\"message\"><pre>#{h(failure.exception.message)}</pre></div>" unless failure.exception.nil?
79:           @output.puts "        <div class=\"backtrace\"><pre>#{format_backtrace(failure.exception.backtrace)}</pre></div>" unless failure.exception.nil?
80:           @output.puts extra unless extra == ""
81:           @output.puts "      </div>"
82:           @output.puts "    </dd>"
83:           @output.flush
84:         end
example_group_number() click to toggle source

The number of the currently running example_group

    # File lib/spec/runner/formatter/html_formatter.rb, line 20
20:         def example_group_number
21:           @example_group_number
22:         end
example_group_started(example_group) click to toggle source
    # File lib/spec/runner/formatter/html_formatter.rb, line 37
37:         def example_group_started(example_group)
38:           super
39:           @example_group_red = false
40:           @example_group_number += 1
41:           unless example_group_number == 1
42:             @output.puts "  </dl>"
43:             @output.puts "</div>"
44:           end
45:           @output.puts "<div class=\"example_group\">"
46:           @output.puts "  <dl>"
47:           @output.puts "  <dt id=\"example_group_#{example_group_number}\">#{h(example_group.description)}</dt>"
48:           @output.flush
49:         end
example_number() click to toggle source

The number of the currently running example (a global counter)

    # File lib/spec/runner/formatter/html_formatter.rb, line 25
25:         def example_number
26:           @example_number
27:         end
example_passed(example) click to toggle source
    # File lib/spec/runner/formatter/html_formatter.rb, line 61
61:         def example_passed(example)
62:           move_progress
63:           @output.puts "    <dd class=\"spec passed\"><span class=\"passed_spec_name\">#{h(example.description)}</span></dd>"
64:           @output.flush
65:         end
example_pending(example, message, deprecated_pending_location=nil) click to toggle source
    # File lib/spec/runner/formatter/html_formatter.rb, line 86
86:         def example_pending(example, message, deprecated_pending_location=nil)
87:           @output.puts "    <script type=\"text/javascript\">makeYellow('rspec-header');</script>" unless @header_red
88:           @output.puts "    <script type=\"text/javascript\">makeYellow('example_group_#{example_group_number}');</script>" unless @example_group_red
89:           move_progress
90:           @output.puts "    <dd class=\"spec not_implemented\"><span class=\"not_implemented_spec_name\">#{h(example.description)} (PENDING: #{h(message)})</span></dd>"
91:           @output.flush
92:         end
example_started(example) click to toggle source
    # File lib/spec/runner/formatter/html_formatter.rb, line 57
57:         def example_started(example)
58:           @example_number += 1
59:         end
extra_failure_content(failure) click to toggle source

Override this method if you wish to output extra HTML for a failed spec. For example, you could output links to images or other files produced during the specs.

     # File lib/spec/runner/formatter/html_formatter.rb, line 97
 97:         def extra_failure_content(failure)
 98:           require 'spec/runner/formatter/snippet_extractor'
 99:           @snippet_extractor ||= SnippetExtractor.new
100:           "    <pre class=\"ruby\"><code>#{@snippet_extractor.snippet(failure.exception)}</code></pre>"
101:         end
global_scripts() click to toggle source
     # File lib/spec/runner/formatter/html_formatter.rb, line 187
187:         def global_scripts
188:           function moveProgressBar(percentDone) {  document.getElementById("rspec-header").style.width = percentDone +"%";}function makeRed(element_id) {  document.getElementById(element_id).style.background = '#C40D0D';  document.getElementById(element_id).style.color = '#FFFFFF';}function makeYellow(element_id) {  if (element_id == "rspec-header" && document.getElementById(element_id).style.background != '#C40D0D')  {    document.getElementById(element_id).style.background = '#FAF834';    document.getElementById(element_id).style.color = '#000000';  }  else  {    document.getElementById(element_id).style.background = '#FAF834';    document.getElementById(element_id).style.color = '#000000';  }}
189:         end
global_styles() click to toggle source
     # File lib/spec/runner/formatter/html_formatter.rb, line 212
212:         def global_styles
213:           #rspec-header {  background: #65C400; color: #fff; height: 4em;}.rspec-report h1 {  margin: 0px 10px 0px 10px;  padding: 10px;  font-family: "Lucida Grande", Helvetica, sans-serif;  font-size: 1.8em;  position: absolute;}#summary {  margin: 0; padding: 5px 10px;  font-family: "Lucida Grande", Helvetica, sans-serif;  text-align: right;  top: 0px;  right: 0px;  float:right;}#summary p {  margin: 0 0 0 2px;}#summary #totals {  font-size: 1.2em;}.example_group {  margin: 0 10px 5px;  background: #fff;}dl {  margin: 0; padding: 0 0 5px;  font: normal 11px "Lucida Grande", Helvetica, sans-serif;}dt {  padding: 3px;  background: #65C400;  color: #fff;  font-weight: bold;}dd {  margin: 5px 0 5px 5px;  padding: 3px 3px 3px 18px;}dd.spec.passed {  border-left: 5px solid #65C400;  border-bottom: 1px solid #65C400;  background: #DBFFB4; color: #3D7700;}dd.spec.failed {  border-left: 5px solid #C20000;  border-bottom: 1px solid #C20000;  color: #C20000; background: #FFFBD3;}dd.spec.not_implemented {  border-left: 5px solid #FAF834;  border-bottom: 1px solid #FAF834;  background: #FCFB98; color: #131313;}dd.spec.pending_fixed {  border-left: 5px solid #0000C2;  border-bottom: 1px solid #0000C2;  color: #0000C2; background: #D3FBFF;}.backtrace {  color: #000;  font-size: 12px;}a {  color: #BE5C00;}/* Ruby code, style similar to vibrant ink */.ruby {  font-size: 12px;  font-family: monospace;  color: white;  background-color: black;  padding: 0.1em 0 0.2em 0;}.ruby .keyword { color: #FF6600; }.ruby .constant { color: #339999; }.ruby .attribute { color: white; }.ruby .global { color: white; }.ruby .module { color: white; }.ruby .class { color: white; }.ruby .string { color: #66FF00; }.ruby .ident { color: white; }.ruby .method { color: #FFCC00; }.ruby .number { color: white; }.ruby .char { color: white; }.ruby .comment { color: #9933CC; }.ruby .symbol { color: white; }.ruby .regex { color: #44B4CC; }.ruby .punct { color: white; }.ruby .escape { color: white; }.ruby .interp { color: white; }.ruby .expr { color: white; }.ruby .offending { background-color: gray; }.ruby .linenum {  width: 75px;  padding: 0.1em 1em 0.2em 0;  color: #000000;  background-color: #FFFBD3;}
214:         end
html_header() click to toggle source
     # File lib/spec/runner/formatter/html_formatter.rb, line 135
135:         def html_header 
136:           <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html   PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head>  <title>RSpec results</title>  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  <meta http-equiv="Expires" content="-1" />  <meta http-equiv="Pragma" content="no-cache" />  <style type="text/css">  body {    margin: 0;    padding: 0;    background: #fff;    font-size: 80%;  }  </style>  <script type="text/javascript">    // <![CDATA[#{global_scripts}    // ]]>  </script>  <style type="text/css">#{global_styles}  </style></head><body>
137:         end
move_progress() click to toggle source
     # File lib/spec/runner/formatter/html_formatter.rb, line 103
103:         def move_progress
104:           @output.puts "    <script type=\"text/javascript\">moveProgressBar('#{percent_done}');</script>"
105:           @output.flush
106:         end
percent_done() click to toggle source
     # File lib/spec/runner/formatter/html_formatter.rb, line 108
108:         def percent_done
109:           result = 100.0
110:           if @example_count != 0
111:             result = ((example_number).to_f / @example_count.to_f * 1000).to_i / 10.0
112:           end
113:           result
114:         end
report_header() click to toggle source
     # File lib/spec/runner/formatter/html_formatter.rb, line 168
168:         def report_header
169:           <div class="rspec-report"><div id="rspec-header">  <div id="label">    <h1>RSpec Code Examples</h1>  </div>  <div id="summary">    <p id="totals">&nbsp;</p>    <p id="duration">&nbsp;</p>  </div></div><div class="results">
170:         end
start(example_count) click to toggle source
    # File lib/spec/runner/formatter/html_formatter.rb, line 29
29:         def start(example_count)
30:           @example_count = example_count
31: 
32:           @output.puts html_header
33:           @output.puts report_header
34:           @output.flush
35:         end
start_dump() click to toggle source
    # File lib/spec/runner/formatter/html_formatter.rb, line 51
51:         def start_dump
52:           @output.puts "  </dl>"
53:           @output.puts "</div>"
54:           @output.flush
55:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.