Class: Opal::RSpec::HtmlPrinter
- Inherits:
-
RSpec::Core::Formatters::HtmlPrinter
- Object
- RSpec::Core::Formatters::HtmlPrinter
- Opal::RSpec::HtmlPrinter
- Defined in:
- opal/opal/rspec/formatter/html_printer.rb
Instance Method Summary collapse
- #current_node ⇒ Object
- #flush_output ⇒ Object
-
#initialize(output) ⇒ HtmlPrinter
constructor
A new instance of HtmlPrinter.
- #make_example_group_header_red(group_id) ⇒ Object
- #make_example_group_header_yellow(group_id) ⇒ Object
- #make_header_red ⇒ Object
- #make_header_yellow ⇒ Object
-
#move_progress(percent_done) ⇒ Object
Directly manipulate scripts here.
- #print_example_failed(pending_fixed, description, run_time, failure_id, exception, extra_content, escape_backtrace = false) ⇒ Object
- #print_example_group_end ⇒ Object
- #print_example_group_start(group_id, description, number_of_parents) ⇒ Object
- #print_example_passed(description, run_time) ⇒ Object
- #print_example_pending(description, pending_message) ⇒ Object
- #print_html_start ⇒ Object
- #print_summary(duration, example_count, failure_count, pending_count) ⇒ Object
- #reset_output ⇒ Object
Constructor Details
#initialize(output) ⇒ HtmlPrinter
Returns a new instance of HtmlPrinter.
7 8 9 10 11 |
# File 'opal/opal/rspec/formatter/html_printer.rb', line 7 def initialize(output) super @group_stack = [] @update_stack = [] end |
Instance Method Details
#current_node ⇒ Object
27 28 29 |
# File 'opal/opal/rspec/formatter/html_printer.rb', line 27 def current_node @group_stack.last ? @group_stack.last : @root_node end |
#flush_output ⇒ Object
31 32 33 34 35 36 |
# File 'opal/opal/rspec/formatter/html_printer.rb', line 31 def flush_output node = current_node new_node = Element.from_string(@output.string) node.append new_node reset_output end |
#make_example_group_header_red(group_id) ⇒ Object
106 107 108 109 110 111 |
# File 'opal/opal/rspec/formatter/html_printer.rb', line 106 def make_example_group_header_red(group_id) @update_stack.last << lambda do `makeRed(#{"div_group_#{group_id}"})` `makeRed(#{"example_group_#{group_id}"})` end end |
#make_example_group_header_yellow(group_id) ⇒ Object
113 114 115 116 117 118 |
# File 'opal/opal/rspec/formatter/html_printer.rb', line 113 def make_example_group_header_yellow(group_id) @update_stack.last << lambda do `makeYellow(#{"div_group_#{group_id}"})` `makeYellow(#{"example_group_#{group_id}"})` end end |
#make_header_red ⇒ Object
98 99 100 |
# File 'opal/opal/rspec/formatter/html_printer.rb', line 98 def make_header_red `makeRed('rspec-header')` end |
#make_header_yellow ⇒ Object
102 103 104 |
# File 'opal/opal/rspec/formatter/html_printer.rb', line 102 def make_header_yellow `makeYellow('rspec-header')` end |
#move_progress(percent_done) ⇒ Object
Directly manipulate scripts here
94 95 96 |
# File 'opal/opal/rspec/formatter/html_printer.rb', line 94 def move_progress(percent_done) `moveProgressBar(#{percent_done})` end |
#print_example_failed(pending_fixed, description, run_time, failure_id, exception, extra_content, escape_backtrace = false) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'opal/opal/rspec/formatter/html_printer.rb', line 64 def print_example_failed(pending_fixed, description, run_time, failure_id, exception, extra_content, escape_backtrace=false) super flush_output example_we_just_wrote = current_node.get_child_by_tag_name('dd', index=-1) = lambda do |*| puts "Exception for example '#{description}'\n#{exception[:backtrace]}" false end = Element.from_string('<form><button type="button">Console</button></form>') .on_click = example_we_just_wrote << end |
#print_example_group_end ⇒ Object
54 55 56 57 |
# File 'opal/opal/rspec/formatter/html_printer.rb', line 54 def print_example_group_end @group_stack.pop @update_stack.pop.each(&:call) end |
#print_example_group_start(group_id, description, number_of_parents) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'opal/opal/rspec/formatter/html_printer.rb', line 42 def print_example_group_start(group_id, description, number_of_parents) super @output.puts '</dl></div>' parent_node = current_node new_node = Element.from_string(@output.string) reset_output parent_node << new_node @group_stack << new_node.get_child_by_tag_name('dl') # We won't have this in the DOM until group ends, so need to queue up yellow/red updates @update_stack << [] end |
#print_example_passed(description, run_time) ⇒ Object
59 60 61 62 |
# File 'opal/opal/rspec/formatter/html_printer.rb', line 59 def print_example_passed(description, run_time) super flush_output end |
#print_example_pending(description, pending_message) ⇒ Object
77 78 79 80 |
# File 'opal/opal/rspec/formatter/html_printer.rb', line 77 def print_example_pending(description, ) super flush_output end |
#print_html_start ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'opal/opal/rspec/formatter/html_printer.rb', line 13 def print_html_start # Will output the header super # Now close out the doc so we can use DOM manipulation for the rest @output.puts "</div>" @output.puts "</div>" @output.puts "</body>" @output.puts "</html>" @output.close # From here, we'll do more direct DOM manipulation reset_output @root_node = Element.klass 'results' end |
#print_summary(duration, example_count, failure_count, pending_count) ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'opal/opal/rspec/formatter/html_printer.rb', line 82 def print_summary(duration, example_count, failure_count, pending_count) # string mutation 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 Element.id('duration').html = "Finished in <strong>#{formatted_duration} seconds</strong>" Element.id('totals').html = totals end |
#reset_output ⇒ Object
38 39 40 |
# File 'opal/opal/rspec/formatter/html_printer.rb', line 38 def reset_output @output = NoopFlushStringIO.new end |