Included Modules

Class Index [+]

Quicksearch

RSpec::Core::Formatters::HtmlFormatter

Public Class Methods

new(output) click to toggle source
    # File lib/rspec/core/formatters/html_formatter.rb, line 10
10:         def initialize(output)
11:           super(output)
12:           @example_group_number = 0
13:           @example_number = 0
14:           @header_red = nil
15:         end

Public Instance Methods

current_indentation() click to toggle source
     # File lib/rspec/core/formatters/html_formatter.rb, line 154
154:         def current_indentation
155:           "style=\"margin-left: #{(example_group.ancestors.size - 1) * 15}px;\""
156:         end
dump_failures() click to toggle source
     # File lib/rspec/core/formatters/html_formatter.rb, line 130
130:         def dump_failures
131:         end
dump_pending() click to toggle source
     # File lib/rspec/core/formatters/html_formatter.rb, line 133
133:         def dump_pending
134:         end
dump_summary(duration, example_count, failure_count, pending_count) click to toggle source
     # File lib/rspec/core/formatters/html_formatter.rb, line 136
136:         def dump_summary(duration, example_count, failure_count, pending_count)
137:           # TODO - kill dry_run?
138:           if dry_run?
139:             totals = "This was a dry-run"
140:           else
141:             totals =  "#{example_count} example#{'s' unless example_count == 1}, "
142:             totals << "#{failure_count} failure#{'s' unless failure_count == 1}"
143:             totals << ", #{pending_count} pending" if pending_count > 0
144:           end
145:           @output.puts "<script type=\"text/javascript\">document.getElementById('duration').innerHTML = \"Finished in <strong>#{sprintf("%.5f", duration)} seconds</strong>\";</script>"
146:           @output.puts "<script type=\"text/javascript\">document.getElementById('totals').innerHTML = \"#{totals}\";</script>"
147:           @output.puts "</div>"
148:           @output.puts "</div>"
149:           @output.puts "</body>"
150:           @output.puts "</html>"
151:           @output.flush
152:         end
example_failed(example) click to toggle source
    # File lib/rspec/core/formatters/html_formatter.rb, line 74
74:         def example_failed(example)
75:           super(example)
76:           exception = example.metadata[:execution_result][:exception]
77:           extra = extra_failure_content(exception)
78:           @output.puts "    <script type=\"text/javascript\">makeRed('rspec-header');</script>" unless @header_red
79:           @header_red = true
80:           @output.puts "    <script type=\"text/javascript\">makeRed('div_group_#{example_group_number}');</script>" unless @example_group_red
81:           @output.puts "    <script type=\"text/javascript\">makeRed('example_group_#{example_group_number}');</script>" unless @example_group_red
82:           @example_group_red = true
83:           move_progress
84:           @output.puts "    <dd class=\"example #{exception.pending_fixed? ? 'pending_fixed' : 'failed'}\">"
85:           @output.puts "      <span class=\"failed_spec_name\">#{h(example.description)}</span>"
86:           @output.puts "      <span class=\"duration\">#{sprintf('%.5f', example.execution_result[:run_time])}s</span>"
87:           @output.puts "      <div class=\"failure\" id=\"failure_#{@failed_examples.size}\">"
88:           @output.puts "        <div class=\"message\"><pre>#{h(exception.message)}</pre></div>" unless exception.nil?
89:           @output.puts "        <div class=\"backtrace\"><pre>#{format_backtrace(exception.backtrace, example).join("\n")}</pre></div>" if exception
90:           @output.puts extra unless extra == ""
91:           @output.puts "      </div>"
92:           @output.puts "    </dd>"
93:           @output.flush
94:         end
example_group_number() click to toggle source

The number of the currently running example_group

    # File lib/rspec/core/formatters/html_formatter.rb, line 27
27:         def example_group_number
28:           @example_group_number
29:         end
example_group_started(example_group) click to toggle source
    # File lib/rspec/core/formatters/html_formatter.rb, line 43
43:         def example_group_started(example_group)
44:           super(example_group)
45:           @example_group_red = false
46:           @example_group_number += 1
47:           unless example_group_number == 1
48:             @output.puts "  </dl>"
49:             @output.puts "</div>"
50:           end
51:           @output.puts "<div id=\"div_group_#{example_group_number}\" class=\"example_group passed\">"
52:           @output.puts "  <dl #{current_indentation}>"
53:           @output.puts "  <dt id=\"example_group_#{example_group_number}\" class=\"passed\">#{h(example_group.description)}</dt>"
54:           @output.flush
55:         end
example_number() click to toggle source

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

    # File lib/rspec/core/formatters/html_formatter.rb, line 32
32:         def example_number
33:           @example_number
34:         end
example_passed(example) click to toggle source
    # File lib/rspec/core/formatters/html_formatter.rb, line 68
68:         def example_passed(example)
69:           move_progress
70:           @output.puts "    <dd class=\"example passed\"><span class=\"passed_spec_name\">#{h(example.description)}</span><span class='duration'>#{sprintf("%.5f", example.execution_result[:run_time])}s</span></dd>"
71:           @output.flush
72:         end
example_pending(example) click to toggle source
     # File lib/rspec/core/formatters/html_formatter.rb, line 96
 96:         def example_pending(example)
 97:           message = example.metadata[:execution_result][:pending_message]
 98:           @output.puts "    <script type=\"text/javascript\">makeYellow('rspec-header');</script>" unless @header_red
 99:           @output.puts "    <script type=\"text/javascript\">makeYellow('div_group_#{example_group_number}');</script>" unless @example_group_red
100:           @output.puts "    <script type=\"text/javascript\">makeYellow('example_group_#{example_group_number}');</script>" unless @example_group_red
101:           move_progress
102:           @output.puts "    <dd class=\"example not_implemented\"><span class=\"not_implemented_spec_name\">#{h(example.description)} (PENDING: #{h(message)})</span></dd>"
103:           @output.flush
104:         end
example_started(example) click to toggle source
    # File lib/rspec/core/formatters/html_formatter.rb, line 63
63:         def example_started(example)
64:           super(example)
65:           @example_number += 1
66:         end
extra_failure_content(exception) 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/rspec/core/formatters/html_formatter.rb, line 109
109:         def extra_failure_content(exception)
110:           require 'rspec/core/formatters/snippet_extractor'
111:           backtrace = exception.backtrace.map {|line| backtrace_line(line)}
112:           backtrace.compact!
113:           @snippet_extractor ||= SnippetExtractor.new
114:           "    <pre class=\"ruby\"><code>#{@snippet_extractor.snippet(backtrace)}</code></pre>"
115:         end
global_scripts() click to toggle source
     # File lib/rspec/core/formatters/html_formatter.rb, line 217
217:         def global_scripts
218:           function addClass(element_id, classname) {  document.getElementById(element_id).className += (" " + classname);}function removeClass(element_id, classname) {  var elem = document.getElementById(element_id);  var classlist = elem.className.replace(classname,'');  elem.className = classlist;}function moveProgressBar(percentDone) {  document.getElementById("rspec-header").style.width = percentDone +"%";}function makeRed(element_id) {  removeClass(element_id, 'passed');  removeClass(element_id, 'not_implemented');  addClass(element_id,'failed');}function makeYellow(element_id) {  var elem = document.getElementById(element_id);  if (elem.className.indexOf("failed") == -1) {  // class doesn't includes failed    if (elem.className.indexOf("not_implemented") == -1) { // class doesn't include not_implemented      removeClass(element_id, 'passed');      addClass(element_id,'not_implemented');    }  }}function apply_filters() {  var passed_filter = document.getElementById('passed_checkbox').checked;  var failed_filter = document.getElementById('failed_checkbox').checked;  var pending_filter = document.getElementById('pending_checkbox').checked;  assign_display_style("example passed", passed_filter);  assign_display_style("example failed", failed_filter);  assign_display_style("example not_implemented", pending_filter);  assign_display_style_for_group("example_group passed", passed_filter);  assign_display_style_for_group("example_group not_implemented", pending_filter, pending_filter || passed_filter);  assign_display_style_for_group("example_group failed", failed_filter, failed_filter || pending_filter || passed_filter);}function get_display_style(display_flag) {  var style_mode = 'none';  if (display_flag == true) {    style_mode = 'block';  }  return style_mode;}function assign_display_style(classname, display_flag) {  var style_mode = get_display_style(display_flag);  var elems = document.getElementsByClassName(classname)  for (var i=0; i<elems.length;i++) {    elems[i].style.display = style_mode;  }}function assign_display_style_for_group(classname, display_flag, subgroup_flag) {  var display_style_mode = get_display_style(display_flag);  var subgroup_style_mode = get_display_style(subgroup_flag);  var elems = document.getElementsByClassName(classname)  for (var i=0; i<elems.length;i++) {    var style_mode = display_style_mode;    if ((display_flag != subgroup_flag) && (elems[i].getElementsByTagName('dt')[0].innerHTML.indexOf(", ") != -1)) {      elems[i].style.display = subgroup_style_mode;    } else {      elems[i].style.display = display_style_mode;    }  }}
219:         end
global_styles() click to toggle source
     # File lib/rspec/core/formatters/html_formatter.rb, line 296
296:         def global_styles
297:           #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;}#label {  float:left;}#display-filters {  float:left;  padding: 28px 0 0 40%;  font-family: "Lucida Grande", Helvetica, sans-serif;}#summary {  float:right;  padding: 5px 10px;  font-family: "Lucida Grande", Helvetica, sans-serif;  text-align: 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 .duration {  padding-left: 5px;  text-align: right;  right: 0px;  float:right;}dd.example.passed {  border-left: 5px solid #65C400;  border-bottom: 1px solid #65C400;  background: #DBFFB4; color: #3D7700;}dd.example.not_implemented {  border-left: 5px solid #FAF834;  border-bottom: 1px solid #FAF834;  background: #FCFB98; color: #131313;}dd.example.pending_fixed {  border-left: 5px solid #0000C2;  border-bottom: 1px solid #0000C2;  color: #0000C2; background: #D3FBFF;}dd.example.failed {  border-left: 5px solid #C20000;  border-bottom: 1px solid #C20000;  color: #C20000; background: #FFFBD3;}dt.not_implemented {  color: #000000; background: #FAF834;}dt.pending_fixed {  color: #FFFFFF; background: #C40D0D;}dt.failed {  color: #FFFFFF; background: #C40D0D;}#rspec-header.not_implemented {  color: #000000; background: #FAF834;}#rspec-header.pending_fixed {  color: #FFFFFF; background: #C40D0D;}#rspec-header.failed {  color: #FFFFFF; background: #C40D0D;}.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;}
298:         end
html_header() click to toggle source
     # File lib/rspec/core/formatters/html_formatter.rb, line 158
158:         def html_header
159:           <?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>
160:         end
message(message) click to toggle source
    # File lib/rspec/core/formatters/html_formatter.rb, line 23
23:         def message(message)
24:         end
move_progress() click to toggle source
     # File lib/rspec/core/formatters/html_formatter.rb, line 117
117:         def move_progress
118:           @output.puts "    <script type=\"text/javascript\">moveProgressBar('#{percent_done}');</script>"
119:           @output.flush
120:         end
percent_done() click to toggle source
     # File lib/rspec/core/formatters/html_formatter.rb, line 122
122:         def percent_done
123:           result = 100.0
124:           if @example_count > 0
125:             result = ((example_number).to_f / @example_count.to_f * 1000).to_i / 10.0
126:           end
127:           result
128:         end
report_header() click to toggle source
     # File lib/rspec/core/formatters/html_formatter.rb, line 191
191:         def report_header
192:           <div class="rspec-report"><div id="rspec-header">  <div id="label">    <h1>RSpec Code Examples</h1>  </div>  <div id="display-filters">    <input id="passed_checkbox" name="passed_checkbox" type="checkbox" checked onchange="apply_filters()" value="1"> <label for="passed_checkbox">Passed</label>    <input id="failed_checkbox" name="failed_checkbox" type="checkbox" checked onchange="apply_filters()" value="2"> <label for="failed_checkbox">Failed</label>    <input id="pending_checkbox" name="pending_checkbox" type="checkbox" checked onchange="apply_filters()" value="3"> <label for="pending_checkbox">Pending</label>  </div>  <div id="summary">    <p id="totals">&nbsp;</p>    <p id="duration">&nbsp;</p>  </div></div><div class="results">
193:         end
start(example_count) click to toggle source
    # File lib/rspec/core/formatters/html_formatter.rb, line 36
36:         def start(example_count)
37:           super(example_count)
38:           @output.puts html_header
39:           @output.puts report_header
40:           @output.flush
41:         end
start_dump() click to toggle source
    # File lib/rspec/core/formatters/html_formatter.rb, line 57
57:         def start_dump
58:           @output.puts "  </dl>"
59:           @output.puts "</div>"
60:           @output.flush
61:         end

Private Instance Methods

method_missing(m, *a, &b) click to toggle source
    # File lib/rspec/core/formatters/html_formatter.rb, line 18
18:         def method_missing(m, *a, &b)
19:           # no-op
20:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.