Class: Spec::Runner::Formatter::HtmlFormatter
- Inherits:
-
BaseTextFormatter
- Object
- BaseTextFormatter
- Spec::Runner::Formatter::HtmlFormatter
- Defined in:
- lib/spec/runner/formatter/html_formatter.rb
Constant Summary collapse
- HEADER =
<<-HEADER <?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.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=iso-8859-1" /> <meta http-equiv="Content-Script-Type" content="text/javascript" /> <style type="text/css"> body { font-size: 10pt; font: "lucida grande"; width: 85%; } ul { padding-left: 8px; } li.passed { background-color: #DDFFDD; } li { list-style-type: none; margin: 0; } li.failed { background-color: #FFBBBB; font-weight: bold; } li.failed:hover { color: #FFFFFF; background-color: #FF0000; } li.failed .failure { font-weight: normal; font-size: 9pt; } div.context { padding:4px; border:1px solid #000000; margin-top:4px; } </style> <script type="text/javascript"> // <![CDATA[ function toggle( id ) { if ( document.getElementById ) elem = document.getElementById( id ); else if ( document.all ) elem = eval( "document.all." + id ); else return false; elemStyle = elem.style; if ( elemStyle.display != "block" ) { elemStyle.display = "block" } else { elemStyle.display = "none" } return true; } // ]]> </script> </head> <body> HEADER
Instance Method Summary collapse
- #add_context(name, first) ⇒ Object
- #dump_failure(counter, failure) ⇒ Object
- #dump_summary(duration, spec_count, failure_count) ⇒ Object
- #escape(string) ⇒ Object
-
#initialize(output, dry_run = false) ⇒ HtmlFormatter
constructor
A new instance of HtmlFormatter.
- #spec_failed(name, counter, failure) ⇒ Object
- #spec_passed(name) ⇒ Object
- #spec_started(name) ⇒ Object
- #start(spec_count) ⇒ Object
- #start_dump ⇒ Object
Constructor Details
#initialize(output, dry_run = false) ⇒ HtmlFormatter
Returns a new instance of HtmlFormatter.
5 6 7 8 |
# File 'lib/spec/runner/formatter/html_formatter.rb', line 5 def initialize(output, dry_run=false) super @current_count = 0 end |
Instance Method Details
#add_context(name, first) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/spec/runner/formatter/html_formatter.rb', line 17 def add_context(name, first) unless first @output.puts " </ul>" @output.puts "</div>" end @output.puts "<div class=\"context\">" @output.puts " <div>#{name}</div>" @output.puts " <ul>" end |
#dump_failure(counter, failure) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/spec/runner/formatter/html_formatter.rb', line 58 def dump_failure(counter, failure) # @output << "\n" # @output << counter.to_s << ")\n" # @output << "#{failure.header}\n" # @output << "#{failure.message}\n" # @output << "#{failure.backtrace}\n" # @output.flush end |
#dump_summary(duration, spec_count, failure_count) ⇒ Object
67 68 69 70 71 |
# File 'lib/spec/runner/formatter/html_formatter.rb', line 67 def dump_summary(duration, spec_count, failure_count) @output << "</body>" @output << "</html>" @output.flush end |
#escape(string) ⇒ Object
54 55 56 |
# File 'lib/spec/runner/formatter/html_formatter.rb', line 54 def escape(string) string.gsub(/&/n, '&').gsub(/\"/n, '"').gsub(/>/n, '>').gsub(/</n, '<') end |
#spec_failed(name, counter, failure) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/spec/runner/formatter/html_formatter.rb', line 42 def spec_failed(name, counter, failure) @output.puts "<li class=\"spec failed\" onclick=\"toggle('failure_#{counter}');return false;\">" @output.puts " <div>#{escape(@current_spec)}</div>" @output.puts " <div class=\"failure\" id=\"failure_#{counter}\" style=\"display:none\">" @output.puts " <div><pre>#{escape(failure.header)}</pre></div>" unless failure.header == "" @output.puts " <div><pre>#{escape(failure.)}</pre></div>" unless failure. == "" @output.puts " <div><pre>#{escape(failure.backtrace)}</pre></div>" unless failure.backtrace == "" @output.puts " </div>" @output.puts "</li>" @output.flush end |
#spec_passed(name) ⇒ Object
38 39 40 |
# File 'lib/spec/runner/formatter/html_formatter.rb', line 38 def spec_passed(name) @output.puts "<li class=\"spec passed\">#{escape(@current_spec)}</li>" end |
#spec_started(name) ⇒ Object
33 34 35 36 |
# File 'lib/spec/runner/formatter/html_formatter.rb', line 33 def spec_started(name) @current_spec = name @current_count += 1 end |
#start(spec_count) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/spec/runner/formatter/html_formatter.rb', line 10 def start(spec_count) @spec_count = spec_count @output.puts HEADER @output.flush end |
#start_dump ⇒ Object
27 28 29 30 31 |
# File 'lib/spec/runner/formatter/html_formatter.rb', line 27 def start_dump @output.puts " </ul>" @output.puts "</div>" @output.flush end |