Class Spec::Runner::Formatter::HtmlFormatter
In: lib/spec/runner/formatter/html_formatter.rb
Parent: BaseTextFormatter

Methods

Included Modules

ERB::Util

Public Class methods

[Source]

    # File lib/spec/runner/formatter/html_formatter.rb, line 9
 9:         def initialize(output)
10:           super
11:           @current_behaviour_number = 0
12:           @current_example_number = 0
13:         end

Public Instance methods

[Source]

    # File lib/spec/runner/formatter/html_formatter.rb, line 33
33:         def add_behaviour(name)
34:           @behaviour_red = false
35:           @behaviour_red = false
36:           @current_behaviour_number += 1
37:           unless current_behaviour_number == 1
38:             @output.puts "  </dl>"
39:             @output.puts "</div>"
40:           end
41:           @output.puts "<div class=\"behaviour\">"
42:           @output.puts "  <dl>"
43:           @output.puts "  <dt id=\"behaviour_#{current_behaviour_number}\">#{h(name)}</dt>"
44:           @output.flush
45:         end

The number of the currently running behaviour

[Source]

    # File lib/spec/runner/formatter/html_formatter.rb, line 16
16:         def current_behaviour_number
17:           @current_behaviour_number
18:         end

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

[Source]

    # File lib/spec/runner/formatter/html_formatter.rb, line 21
21:         def current_example_number
22:           @current_example_number
23:         end

[Source]

     # File lib/spec/runner/formatter/html_formatter.rb, line 103
103:         def dump_failure(counter, failure)
104:         end

[Source]

     # File lib/spec/runner/formatter/html_formatter.rb, line 106
106:         def dump_summary(duration, example_count, failure_count, pending_count)
107:           if @dry_run
108:             totals = "This was a dry-run"
109:           else
110:             totals = "#{example_count} example#{'s' unless example_count == 1}, #{failure_count} failure#{'s' unless failure_count == 1}"
111:             totals << ", #{pending_count} pending" if pending_count > 0  
112:           end
113:           @output.puts "<script type=\"text/javascript\">document.getElementById('duration').innerHTML = \"Finished in <strong>#{duration} seconds</strong>\";</script>"
114:           @output.puts "<script type=\"text/javascript\">document.getElementById('totals').innerHTML = \"#{totals}\";</script>"
115:           @output.puts "</div>"
116:           @output.puts "</div>"
117:           @output.puts "</body>"
118:           @output.puts "</html>"
119:           @output.flush
120:         end

[Source]

    # File lib/spec/runner/formatter/html_formatter.rb, line 63
63:         def example_failed(example, counter, failure)
64:           extra = extra_failure_content(failure)
65:           failure_style = failure.pending_fixed? ? 'pending_fixed' : 'failed'
66:           @output.puts "    <script type=\"text/javascript\">makeRed('rspec-header');</script>" unless @header_red
67:           @header_red = true
68:           @output.puts "    <script type=\"text/javascript\">makeRed('behaviour_#{current_behaviour_number}');</script>" unless @behaviour_red
69:           @behaviour_red = true
70:           move_progress
71:           @output.puts "    <dd class=\"spec #{failure_style}\">"
72:           @output.puts "      <span class=\"failed_spec_name\">#{h(example.description)}</span>"
73:           @output.puts "      <div class=\"failure\" id=\"failure_#{counter}\">"
74:           @output.puts "        <div class=\"message\"><pre>#{h(failure.exception.message)}</pre></div>" unless failure.exception.nil?
75:           @output.puts "        <div class=\"backtrace\"><pre>#{format_backtrace(failure.exception.backtrace)}</pre></div>" unless failure.exception.nil?
76:           @output.puts extra unless extra == ""
77:           @output.puts "      </div>"
78:           @output.puts "    </dd>"
79:           @output.flush
80:         end

[Source]

    # File lib/spec/runner/formatter/html_formatter.rb, line 57
57:         def example_passed(example)
58:           move_progress
59:           @output.puts "    <dd class=\"spec passed\"><span class=\"passed_spec_name\">#{h(example.description)}</span></dd>"
60:           @output.flush
61:         end

[Source]

    # File lib/spec/runner/formatter/html_formatter.rb, line 82
82:         def example_pending(behaviour_name, example_name, message)
83:           @output.puts "    <script type=\"text/javascript\">makeYellow('rspec-header');</script>" unless @header_red
84:           @output.puts "    <script type=\"text/javascript\">makeYellow('behaviour_#{current_behaviour_number}');</script>" unless @behaviour_red
85:           move_progress
86:           @output.puts "    <dd class=\"spec not_implemented\"><span class=\"not_implemented_spec_name\">#{h(example_name)}</span></dd>"
87:           @output.flush
88:         end

[Source]

    # File lib/spec/runner/formatter/html_formatter.rb, line 53
53:         def example_started(example)
54:           @current_example_number = example.number
55:         end

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.

[Source]

    # File lib/spec/runner/formatter/html_formatter.rb, line 93
93:         def extra_failure_content(failure)
94:           "    <pre class=\"ruby\"><code>#{@snippet_extractor.snippet(failure.exception)}</code></pre>"
95:         end

[Source]

     # File lib/spec/runner/formatter/html_formatter.rb, line 175
175:         def global_scripts
176:           "function moveProgressBar(percentDone) {\ndocument.getElementById(\"rspec-header\").style.width = percentDone +\"%\";\n}\nfunction makeRed(element_id) {\ndocument.getElementById(element_id).style.background = '#C40D0D';\ndocument.getElementById(element_id).style.color = '#FFFFFF';\n}\n\nfunction makeYellow(element_id) {\nif (element_id == \"rspec-header\" && document.getElementById(element_id).style.background != '#C40D0D')\n{\ndocument.getElementById(element_id).style.background = '#FAF834';\ndocument.getElementById(element_id).style.color = '#000000';\n}\nelse\n{\ndocument.getElementById(element_id).style.background = '#FAF834';\ndocument.getElementById(element_id).style.color = '#000000';\n}\n}\n"
177:         end

[Source]

     # File lib/spec/runner/formatter/html_formatter.rb, line 201
201:         def global_styles
202:           "#rspec-header {\nbackground: #65C400; color: #fff;\n}\n\n.rspec-report h1 {\nmargin: 0px 10px 0px 10px;\npadding: 10px;\nfont-family: \"Lucida Grande\", Helvetica, sans-serif;\nfont-size: 1.8em;\n}\n\n#summary {\nmargin: 0; padding: 5px 10px;\nfont-family: \"Lucida Grande\", Helvetica, sans-serif;\ntext-align: right;\nposition: absolute;\ntop: 0px;\nright: 0px;\n}\n\n#summary p {\nmargin: 0 0 0 2px;\n}\n\n#summary #totals {\nfont-size: 1.2em;\n}\n\n.behaviour {\nmargin: 0 10px 5px;\nbackground: #fff;\n}\n\ndl {\nmargin: 0; padding: 0 0 5px;\nfont: normal 11px \"Lucida Grande\", Helvetica, sans-serif;\n}\n\ndt {\npadding: 3px;\nbackground: #65C400;\ncolor: #fff;\nfont-weight: bold;\n}\n\ndd {\nmargin: 5px 0 5px 5px;\npadding: 3px 3px 3px 18px;\n}\n\ndd.spec.passed {\nborder-left: 5px solid #65C400;\nborder-bottom: 1px solid #65C400;\nbackground: #DBFFB4; color: #3D7700;\n}\n\ndd.spec.failed {\nborder-left: 5px solid #C20000;\nborder-bottom: 1px solid #C20000;\ncolor: #C20000; background: #FFFBD3;\n}\n\ndd.spec.not_implemented {\nborder-left: 5px solid #FAF834;\nborder-bottom: 1px solid #FAF834;\nbackground: #FCFB98; color: #131313;\n}\n\ndd.spec.pending_fixed {\nborder-left: 5px solid #0000C2;\nborder-bottom: 1px solid #0000C2;\ncolor: #0000C2; background: #D3FBFF;\n}\n\n.backtrace {\ncolor: #000;\nfont-size: 12px;\n}\n\na {\ncolor: #BE5C00;\n}\n\n/* Ruby code, style similar to vibrant ink */\n.ruby {\nfont-size: 12px;\nfont-family: monospace;\ncolor: white;\nbackground-color: black;\npadding: 0.1em 0 0.2em 0;\n}\n\n.ruby .keyword { color: #FF6600; }\n.ruby .constant { color: #339999; }\n.ruby .attribute { color: white; }\n.ruby .global { color: white; }\n.ruby .module { color: white; }\n.ruby .class { color: white; }\n.ruby .string { color: #66FF00; }\n.ruby .ident { color: white; }\n.ruby .method { color: #FFCC00; }\n.ruby .number { color: white; }\n.ruby .char { color: white; }\n.ruby .comment { color: #9933CC; }\n.ruby .symbol { color: white; }\n.ruby .regex { color: #44B4CC; }\n.ruby .punct { color: white; }\n.ruby .escape { color: white; }\n.ruby .interp { color: white; }\n.ruby .expr { color: white; }\n\n.ruby .offending { background-color: gray; }\n.ruby .linenum {\nwidth: 75px;\npadding: 0.1em 1em 0.2em 0;\ncolor: #000000;\nbackground-color: #FFFBD3;\n}\n"
203:         end

[Source]

     # File lib/spec/runner/formatter/html_formatter.rb, line 122
122:         def html_header 
123:           "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n<!DOCTYPE html\nPUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n<head>\n<title>RSpec results</title>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />\n<meta http-equiv=\"Expires\" content=\"-1\" />\n<meta http-equiv=\"Pragma\" content=\"no-cache\" />\n<style type=\"text/css\">\nbody {\nmargin: 0;\npadding: 0;\nbackground: #fff;\nfont-size: 80%;\n}\n</style>\n</head>\n<body>\n"
124:         end

[Source]

     # File lib/spec/runner/formatter/html_formatter.rb, line 97
 97:         def move_progress
 98:           percent_done = @example_count == 0 ? 100.0 : ((current_example_number + 1).to_f / @example_count.to_f * 1000).to_i / 10.0
 99:           @output.puts "    <script type=\"text/javascript\">moveProgressBar('#{percent_done}');</script>"
100:           @output.flush
101:         end

[Source]

     # File lib/spec/runner/formatter/html_formatter.rb, line 149
149:         def report_header
150:           "<div class=\"rspec-report\">\n<script type=\"text/javascript\">\n// <![CDATA[\n\#{global_scripts}\n// ]]>\n</script>\n<style type=\"text/css\">\n\#{global_styles}\n</style>\n\n<div id=\"rspec-header\">\n<h1>RSpec Results</h1>\n\n<div id=\"summary\">\n<p id=\"totals\">&nbsp;</p>\n<p id=\"duration\">&nbsp;</p>\n</div>\n</div>\n\n<div class=\"results\">\n"
151:         end

[Source]

    # File lib/spec/runner/formatter/html_formatter.rb, line 25
25:         def start(example_count)
26:           @example_count = example_count
27: 
28:           @output.puts html_header
29:           @output.puts report_header
30:           @output.flush
31:         end

[Source]

    # File lib/spec/runner/formatter/html_formatter.rb, line 47
47:         def start_dump
48:           @output.puts "  </dl>"
49:           @output.puts "</div>"
50:           @output.flush
51:         end

[Validate]