class SplitHtmlPrinter
Constants
- GLOBAL_SCRIPTS
- GLOBAL_STYLES
- HTML_HEADER
- REPORT_HEADER
Public Class Methods
new(output)
click to toggle source
# File lib/splithtml_printer.rb, line 16 def initialize(output) @output = output end
Public Instance Methods
flush()
click to toggle source
# File lib/splithtml_printer.rb, line 149 def flush @output.flush end
make_example_group_header_red(group_id)
click to toggle source
# File lib/splithtml_printer.rb, line 166 def make_example_group_header_red(group_id) @output.puts " <script type=\"text/javascript\">makeRed('div_group_#{group_id}');</script>" @output.puts " <script type=\"text/javascript\">makeRed('example_group_#{group_id}');</script>" end
make_example_group_header_yellow(group_id)
click to toggle source
# File lib/splithtml_printer.rb, line 171 def make_example_group_header_yellow(group_id) @output.puts " <script type=\"text/javascript\">makeYellow('div_group_#{group_id}');</script>" @output.puts " <script type=\"text/javascript\">makeYellow('example_group_#{group_id}');</script>" end
make_header_red()
click to toggle source
# File lib/splithtml_printer.rb, line 158 def make_header_red @output.puts " <script type=\"text/javascript\">makeRed('rspec-header');</script>" end
make_header_yellow()
click to toggle source
# File lib/splithtml_printer.rb, line 162 def make_header_yellow @output.puts " <script type=\"text/javascript\">makeYellow('rspec-header');</script>" end
move_progress( percent_done )
click to toggle source
# File lib/splithtml_printer.rb, line 153 def move_progress( percent_done ) @output.puts " <script type=\"text/javascript\">moveProgressBar('#{percent_done}');</script>" @output.flush end
print_end_time(time)
click to toggle source
# File lib/splithtml_printer.rb, line 145 def print_end_time(time) @output.puts "<p time=\"end_time\"><span style=\"visibility:hidden\">#{time}</span></p>" end
print_example_end()
click to toggle source
# File lib/splithtml_printer.rb, line 61 def print_example_end() @captured_io.flush() @captured_io.string = @captured_io.string.gsub(/</, '<') @captured_io.string = @captured_io.string.gsub(/>/, '>') logs = @captured_io.string.dup @captured_io.truncate(0) @captured_io.seek(0) return logs end
print_example_failed( pending_fixed, description, run_time, failure_id, exception, extra_content, escape_backtrace = false )
click to toggle source
# File lib/splithtml_printer.rb, line 82 def print_example_failed( pending_fixed, description, run_time, failure_id, exception, extra_content, escape_backtrace = false ) formatted_run_time = 0 formatted_run_time = sprintf("%.5f", run_time) if run_time @output.puts " <dd class=\"example #{pending_fixed ? 'pending_fixed' : 'failed'}\">" @output.puts " <span class=\"failed_spec_name\">#{h(description)}</span>" @output.puts " <span class=\"duration\">#{formatted_run_time}s</span>" @output.puts " <div class=\"console_log\">" @output.puts " <pre>#{print_example_end()}</pre>" @output.puts " </div>" @output.puts " <div class=\"failure\" id=\"failure_#{failure_id}\">" if exception @output.puts " <div class=\"message\"><pre>#{h(exception[:message])}</pre></div>" if escape_backtrace @output.puts " <div class=\"backtrace\"><pre>#{h exception[:backtrace]}</pre></div>" else @output.puts " <div class=\"backtrace\"><pre>#{exception[:backtrace]}</pre></div>" end end @output.puts extra_content if extra_content @output.puts " </div>" @output.puts " </dd>" end
print_example_group_end()
click to toggle source
# File lib/splithtml_printer.rb, line 42 def print_example_group_end() logs = @captured_io.string unless logs.empty? @output.puts " <dd class=\"example passed\">" @output.puts " <span class=\"\">after(:all)</span>" @output.puts " <div class=\"console_log\">" @output.puts " <pre>#{logs}</pre>" @output.puts " </div>" @output.puts " </dd>" end @output.puts " </dl>" @output.puts "</div>" end
print_example_group_start(description)
click to toggle source
# File lib/splithtml_printer.rb, line 32 def print_example_group_start(description) @output.puts "<div id=\"div_group_0\" class=\"example_group passed\">" @output.puts " <dl #{indentation_style(1)}>" @output.puts " <dt id=\"example_group_0\" class=\"passed\">#{h(description)}</dt>" @captured_io = StringIO.new() $stdout = @captured_io $stderr = @captured_io end
print_example_passed( description, run_time )
click to toggle source
# File lib/splithtml_printer.rb, line 71 def print_example_passed( description, run_time ) formatted_run_time = sprintf("%.5f", run_time) if run_time @output.puts " <dd class=\"example passed\">" @output.puts " <span class=\"passed_spec_name\">#{h(description)}</span>" @output.puts " <span class=\"duration\">#{formatted_run_time}s</span>" @output.puts " <div class=\"console_log\">" @output.puts " <pre>#{print_example_end()}</pre>" @output.puts " </div>" @output.puts " </dd>" end
print_example_pending( description, pending_message )
click to toggle source
# File lib/splithtml_printer.rb, line 108 def print_example_pending( description, pending_message ) @output.puts " <dd class=\"example not_implemented\">" @output.puts " <span class=\"not_implemented_spec_name\">#{h(description)} (PENDING: #{h(pending_message)})</span>" @output.puts " <div class=\"console_log\">" @output.puts " <pre>#{print_example_end()}</pre>" @output.puts " </div>" @output.puts " </dd>" end
print_example_start()
click to toggle source
# File lib/splithtml_printer.rb, line 57 def print_example_start() end
print_html_start(test_file_name)
click to toggle source
# File lib/splithtml_printer.rb, line 22 def print_html_start(test_file_name) @output.puts HTML_HEADER @output.puts "<div class=\"rspec-report\">" @output.puts "<div id=\"rspec-header\">" @output.puts " <div id=\"label\">" @output.puts " <h1>#{test_file_name}</h1>" @output.puts " </div>" @output.puts REPORT_HEADER end
print_start_time(time)
click to toggle source
# File lib/splithtml_printer.rb, line 141 def print_start_time(time) @output.puts "<p time=\"start_time\"><span style=\"visibility:hidden\">#{time}</span></p>" end
print_summary( was_dry_run, duration, example_count, failure_count, pending_count, test_path, start_time, end_time)
click to toggle source
# File lib/splithtml_printer.rb, line 117 def print_summary( was_dry_run, duration, example_count, failure_count, pending_count, test_path, start_time, end_time) totals = "#{example_count} example#{'s' unless example_count == 1}, " totals << "#{failure_count} failure#{'s' unless failure_count == 1}" totals << ", #{pending_count} pending" if pending_count > 0 formatted_duration = sprintf("%.5f", duration) @output.puts "<script type=\"text/javascript\">document.getElementById('duration').innerHTML = \"Finished in <strong>#{formatted_duration} seconds</strong>\";</script>" @output.puts "<script type=\"text/javascript\">document.getElementById('totals').innerHTML = \"#{totals}\";</script>" if failure_count != 0 @output.puts "<p status=\"failed\"><span style=\"visibility:hidden\">#{failure_count}</span></p>" elsif pending_count != 0 @output.puts "<p status=\"pending\"><span style=\"visibility:hidden\">#{pending_count}</span></p>" else @output.puts "<p status=\"passed\"><span style=\"visibility:hidden\">#{example_count}</span></p>" end @output.puts "<p test_file_path=#{test_path}><span style=\"visibility:hidden\"></span></p>" print_start_time(start_time) print_end_time(end_time) @output.puts "</div>" @output.puts "</div>" @output.puts "</body>" @output.puts "</html>" end
Private Instance Methods
indentation_style( number_of_parents )
click to toggle source
# File lib/splithtml_printer.rb, line 178 def indentation_style( number_of_parents ) "style=\"margin-left: #{(number_of_parents - 1) * 15}px;\"" end