Methods
public class
public instance
Included modules
- ERB::Util
Public class methods
new
(options, output)
[show source]
# File lib/spec/runner/formatter/html_formatter.rb, line 10 def initialize(options, output) super @example_group_number = 0 @example_number = 0 end
Public instance methods
add_example_group
(example_group)
[show source]
# File lib/spec/runner/formatter/html_formatter.rb, line 38 def add_example_group(example_group) super @example_group_red = false @example_group_number += 1 unless example_group_number == 1 @output.puts " </dl>" @output.puts "</div>" end @output.puts "<div class=\"example_group\">" @output.puts " <dl>" @output.puts " <dt id=\"example_group_#{example_group_number}\">#{h(example_group.description)}</dt>" @output.flush end
dump_failure
(counter, failure)
[show source]
# File lib/spec/runner/formatter/html_formatter.rb, line 117 def dump_failure(counter, failure) end
dump_summary
(duration, example_count, failure_count, pending_count)
[show source]
# File lib/spec/runner/formatter/html_formatter.rb, line 120 def dump_summary(duration, example_count, failure_count, pending_count) if dry_run? totals = "This was a dry-run" else totals = "#{example_count} example#{'s' unless example_count == 1}, #{failure_count} failure#{'s' unless failure_count == 1}" totals << ", #{pending_count} pending" if pending_count > 0 end @output.puts "<script type=\"text/javascript\">document.getElementById('duration').innerHTML = \"Finished in <strong>#{duration} seconds</strong>\";</script>" @output.puts "<script type=\"text/javascript\">document.getElementById('totals').innerHTML = \"#{totals}\";</script>" @output.puts "</div>" @output.puts "</div>" @output.puts "</body>" @output.puts "</html>" @output.flush end
example_failed
(example, counter, failure)
[show source]
# File lib/spec/runner/formatter/html_formatter.rb, line 68 def example_failed(example, counter, failure) extra = extra_failure_content(failure) failure_style = failure.pending_fixed? ? 'pending_fixed' : 'failed' @output.puts " <script type=\"text/javascript\">makeRed('rspec-header');</script>" unless @header_red @header_red = true @output.puts " <script type=\"text/javascript\">makeRed('example_group_#{example_group_number}');</script>" unless @example_group_red @example_group_red = true move_progress @output.puts " <dd class=\"spec #{failure_style}\">" @output.puts " <span class=\"failed_spec_name\">#{h(example.description)}</span>" @output.puts " <div class=\"failure\" id=\"failure_#{counter}\">" @output.puts " <div class=\"message\"><pre>#{h(failure.exception.message)}</pre></div>" unless failure.exception.nil? @output.puts " <div class=\"backtrace\"><pre>#{format_backtrace(failure.exception.backtrace)}</pre></div>" unless failure.exception.nil? @output.puts extra unless extra == "" @output.puts " </div>" @output.puts " </dd>" @output.flush end
example_group_number
()
The number of the currently running example_group
[show source]
# File lib/spec/runner/formatter/html_formatter.rb, line 21 def example_group_number @example_group_number end
example_number
()
The number of the currently running example (a global counter)
[show source]
# File lib/spec/runner/formatter/html_formatter.rb, line 26 def example_number @example_number end
example_passed
(example)
[show source]
# File lib/spec/runner/formatter/html_formatter.rb, line 62 def example_passed(example) move_progress @output.puts " <dd class=\"spec passed\"><span class=\"passed_spec_name\">#{h(example.description)}</span></dd>" @output.flush end
example_pending
(example, message, pending_caller)
[show source]
# File lib/spec/runner/formatter/html_formatter.rb, line 87 def example_pending(example, message, pending_caller) @output.puts " <script type=\"text/javascript\">makeYellow('rspec-header');</script>" unless @header_red @output.puts " <script type=\"text/javascript\">makeYellow('example_group_#{example_group_number}');</script>" unless @example_group_red move_progress @output.puts " <dd class=\"spec not_implemented\"><span class=\"not_implemented_spec_name\">#{h(example.description)} (PENDING: #{h(message)})</span></dd>" @output.flush end
example_started
(example)
[show source]
# File lib/spec/runner/formatter/html_formatter.rb, line 58 def example_started(example) @example_number += 1 end
extra_failure_content
(failure)
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.
[show source]
# File lib/spec/runner/formatter/html_formatter.rb, line 98 def extra_failure_content(failure) require 'spec/runner/formatter/snippet_extractor' @snippet_extractor ||= SnippetExtractor.new " <pre class=\"ruby\"><code>#{@snippet_extractor.snippet(failure.exception)}</code></pre>" end
global_scripts
()
[show source]
# File lib/spec/runner/formatter/html_formatter.rb, line 190 def global_scripts "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" end
global_styles
()
[show source]
# File lib/spec/runner/formatter/html_formatter.rb, line 216 def global_styles "#rspec-header {\nbackground: #65C400; color: #fff; height: 4em;\n}\n\n.rspec-report h1 {\nmargin: 0px 10px 0px 10px;\npadding: 10px;\nfont-family: \"Lucida Grande\", Helvetica, sans-serif;\nfont-size: 1.8em;\nposition: absolute;\n}\n\n#summary {\nmargin: 0; padding: 5px 10px;\nfont-family: \"Lucida Grande\", Helvetica, sans-serif;\ntext-align: right;\ntop: 0px;\nright: 0px;\nfloat:right;\n}\n\n#summary p {\nmargin: 0 0 0 2px;\n}\n\n#summary #totals {\nfont-size: 1.2em;\n}\n\n.example_group {\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" end
html_header
()
[show source]
# File lib/spec/runner/formatter/html_formatter.rb, line 136 def html_header "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE html\nPUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\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=utf-8\" />\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<script type=\"text/javascript\">\n// <![CDATA[\n\#{global_scripts}\n// ]]>\n</script>\n<style type=\"text/css\">\n\#{global_styles}\n</style>\n</head>\n<body>\n" end
method_missing
(sym, *args)
[show source]
# File lib/spec/runner/formatter/html_formatter.rb, line 16 def method_missing(sym, *args) # no-op end
move_progress
()
[show source]
# File lib/spec/runner/formatter/html_formatter.rb, line 104 def move_progress @output.puts " <script type=\"text/javascript\">moveProgressBar('#{percent_done}');</script>" @output.flush end
percent_done
()
[show source]
# File lib/spec/runner/formatter/html_formatter.rb, line 109 def percent_done result = 100.0 if @example_count != 0 result = ((example_number).to_f / @example_count.to_f * 1000).to_i / 10.0 end result end
report_header
()
[show source]
# File lib/spec/runner/formatter/html_formatter.rb, line 170 def report_header "<div class=\"rspec-report\">\n\n<div id=\"rspec-header\">\n<div id=\"label\">\n<h1>RSpec Results</h1>\n</div>\n\n<div id=\"summary\">\n<p id=\"totals\"> </p>\n<p id=\"duration\"> </p>\n</div>\n</div>\n\n<div class=\"results\">\n" end
start
(example_count)
[show source]
# File lib/spec/runner/formatter/html_formatter.rb, line 30 def start(example_count) @example_count = example_count @output.puts html_header @output.puts report_header @output.flush end
start_dump
()
[show source]
# File lib/spec/runner/formatter/html_formatter.rb, line 52 def start_dump @output.puts " </dl>" @output.puts "</div>" @output.flush end