Class: Nukumber::Reporter::Html
- Defined in:
- lib/nukumber/reporter/html.rb,
lib/nukumber/reporter/html_css.rb
Instance Method Summary collapse
- #begin_element(element) ⇒ Object
- #begin_feature(feature) ⇒ Object
- #error(exception, element) ⇒ Object
- #final_report(passed, failed, pending, undefined) ⇒ Object
-
#initialize(out) ⇒ Html
constructor
A new instance of Html.
- #print_example(table, row, status) ⇒ Object
- #print_skeleton_code ⇒ Object
- #print_step(step, status) ⇒ Object
- #terminate ⇒ Object
- #undefined_element(element) ⇒ Object
Constructor Details
#initialize(out) ⇒ Html
Returns a new instance of Html.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/nukumber/reporter/html.rb', line 31 def initialize(out) @outstream = out @doc = Nokogiri::HTML::Document.new @html = node("html", @doc) node_head = node("head", @html) node_style = node("style", node_head, {:type => 'text/css'}) node_style.inner_html = css node_body = node("body", @html) node("h1", node_body, {}, 'Nukumber test report') end |
Instance Method Details
#begin_element(element) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/nukumber/reporter/html.rb', line 54 def begin_element(element) @node_element = node("div", @node_feature, {:class => 'element'}) node_header = node('div', @node_element, {:class => 'header'}) node("h3", node_header, {}, "#{element.keyword}: #{element.name}") node("div", node_header, {:class => 'address'}, "#{element.feature.file_path.split('/').last}:#{element.line}") unless element.is_a? Nukumber::Model::Background or element..empty? node("div", node_header, {:class => 'tags'}, element..join(' ')) end unless element.description.empty? node("p", node_header, {}, element.description.gsub(/\n/,' ')) end if element.is_a? Nukumber::Model::ScenarioOutline element.steps.each { |step| print_step(step, :outline) } @node_ex_table = node("table", @node_element) add_row(element.examples.table, nil, @node_ex_table) end end |
#begin_feature(feature) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/nukumber/reporter/html.rb', line 42 def begin_feature(feature) @node_feature = node('div', @html.at_css('body'), {:class => 'feature'}) node_header = node('div', @node_feature, {:class => 'header'}) node("h2", node_header, {}, "#{feature.keyword}: #{feature.name}") unless feature..empty? node("div", node_header, {:class => 'tags'}, feature..join(' ')) end unless feature.description.empty? node("p", node_header, {}, feature.description.gsub(/\n/,' ')) end end |
#error(exception, element) ⇒ Object
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/nukumber/reporter/html.rb', line 112 def error(exception, element) node_error = node("div", @node_element, {:class => "error"}) node("p", node_error, {}, exception.) node_backtrace = node("div", node_error) filtered_backtrace(exception.backtrace).each do |l| node("p", node_backtrace, {}, l) end node("p", node_backtrace, {}, "#{element.feature.file_path}:#{element.line}") @node_element['class'] = 'element failed' end |
#final_report(passed, failed, pending, undefined) ⇒ Object
123 124 125 126 127 128 129 130 |
# File 'lib/nukumber/reporter/html.rb', line 123 def final_report(passed, failed, pending, undefined) rpt = {:passed => passed, :failed => failed, :pending => pending, :undefined => undefined} node_final_report = node("div", @html.at_css('body'), {:id => 'final_report'}) %w( passed failed pending undefined ).each do |str| node("div", node_final_report, {:class => str}, "#{rpt[str.to_sym].size} test#{rpt[str.to_sym].size == 1 ? '' : 's'} #{str}") end node("div", node_final_report, {:class => "datetime"}, "#{Time.now}") end |
#print_example(table, row, status) ⇒ Object
105 106 107 108 109 110 |
# File 'lib/nukumber/reporter/html.rb', line 105 def print_example(table, row, status) add_row(table, row, @node_ex_table, status.to_s) unless @node_element['class'] == "element failed" @node_element['class'] = "element #{status.to_s}" end end |
#print_skeleton_code ⇒ Object
132 133 |
# File 'lib/nukumber/reporter/html.rb', line 132 def print_skeleton_code(*) end |
#print_step(step, status) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/nukumber/reporter/html.rb', line 92 def print_step(step, status) node_step = node("div", @node_element, {:class => "step #{status.to_s}"}) node("p", node_step, {}, "#{step.keyword}#{step.name}") unless step.args.empty? node_table = Nokogiri::XML::Node.new "table", @doc (0..step.args.row_count).each do |i| add_row(step.args, i - 1, node_table) end node_step.add_child node_table end @node_element['class'] = "element #{status.to_s}" end |
#terminate ⇒ Object
135 136 137 |
# File 'lib/nukumber/reporter/html.rb', line 135 def terminate() @outstream.puts @doc.to_html end |
#undefined_element(element) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/nukumber/reporter/html.rb', line 72 def undefined_element(element) @node_element = node("div", @node_feature, {:class => 'element undefined'}) node_header = node('div', @node_element, {:class => 'header'}) node("h3", node_header, {}, "#{element.keyword}: #{element.name}") node("div", node_header, {:class => 'address'}, "#{element.feature.file_path.split('/').last}:#{element.line}") unless element.is_a? Nukumber::Model::Background or element..empty? node("div", node_header, {:class => 'tags'}, element..join(' ')) end unless element.description.empty? node("p", node_header, {}, element.description.gsub(/\n/,' ')) end element.steps.each { |step| print_step(step, :undefined) } if element.is_a? Nukumber::Model::ScenarioOutline @node_ex_table = node("table", @node_element) (0..element.examples.table.row_count).each do |i| add_row(element.examples.table, i - 1, @node_ex_table, 'undefined') end end end |