require 'erb' module RSpec module Core module Formatters # @private class HtmlPrinter include ERB::Util # For the #h method. def initialize(output) @output = output end def print_html_start @output.puts HTML_HEADER @output.puts REPORT_HEADER end def print_example_group_end @output.puts " " @output.puts "" end def print_example_group_start(group_id, description, number_of_parents) @output.puts "
" @output.puts "
" @output.puts "
#{h(description)}
" end def print_example_passed(description, run_time) formatted_run_time = "%.5f" % run_time @output.puts "
" \ "#{h(description)}" \ "#{formatted_run_time}s
" end # rubocop:disable Style/ParameterLists def print_example_failed(pending_fixed, description, run_time, failure_id, exception, extra_content, escape_backtrace=false) # rubocop:enable Style/ParameterLists formatted_run_time = "%.5f" % run_time @output.puts "
" @output.puts " #{h(description)}" @output.puts " #{formatted_run_time}s" @output.puts "
" if exception @output.puts "
#{h(exception[:message])}
" if escape_backtrace @output.puts "
#{h exception[:backtrace]}
" else @output.puts "
#{exception[:backtrace]}
" end end @output.puts extra_content if extra_content @output.puts "
" @output.puts "
" end def print_example_pending(description, pending_message) @output.puts "
" \ "#{h(description)} " \ "(PENDING: #{h(pending_message)})
" end def print_summary(duration, example_count, failure_count, pending_count) 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 = "%.5f" % duration @output.puts "" @output.puts "" @output.puts "
" @output.puts "" @output.puts "" @output.puts "" end def flush @output.flush end def move_progress(percent_done) @output.puts " " @output.flush end def make_header_red @output.puts " " end def make_header_yellow @output.puts " " end def make_example_group_header_red(group_id) @output.puts " " @output.puts " " end def make_example_group_header_yellow(group_id) @output.puts " " @output.puts " " end private def indentation_style(number_of_parents) "style=\"margin-left: #{(number_of_parents - 1) * 15}px;\"" end # rubocop:disable LineLength REPORT_HEADER = <<-EOF

RSpec Code Examples

 

 

EOF # rubocop:enable LineLength # rubocop:disable LineLength GLOBAL_SCRIPTS = <<-EOF 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 RSpec results EOF end end end end