Class: Cucumber::Formatter::Html
- Inherits:
-
Ast::Visitor
- Object
- Ast::Visitor
- Cucumber::Formatter::Html
- Includes:
- Duration, ERB::Util
- Defined in:
- lib/cucumber/formatter/html.rb
Overview
The formatter used for --format html
Instance Attribute Summary
Attributes inherited from Ast::Visitor
Instance Method Summary collapse
- #announce(announcement) ⇒ Object
- #create_builder(io) ⇒ Object
-
#initialize(step_mother, io, options) ⇒ Html
constructor
A new instance of Html.
- #visit_background(background) ⇒ Object
- #visit_background_name(keyword, name, file_colon_line, source_indent) ⇒ Object
- #visit_comment(comment) ⇒ Object
- #visit_comment_line(comment_line) ⇒ Object
- #visit_examples(examples) ⇒ Object
- #visit_examples_name(keyword, name) ⇒ Object
- #visit_exception(exception, status) ⇒ Object
- #visit_feature(feature) ⇒ Object
- #visit_feature_element(feature_element) ⇒ Object
- #visit_feature_name(name) ⇒ Object
- #visit_features(features) ⇒ Object
- #visit_multiline_arg(multiline_arg) ⇒ Object
- #visit_outline_table(outline_table) ⇒ Object
- #visit_py_string(string) ⇒ Object
- #visit_scenario_name(keyword, name, file_colon_line, source_indent) ⇒ Object
- #visit_step(step) ⇒ Object
- #visit_step_name(keyword, step_match, status, source_indent, background) ⇒ Object
- #visit_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background) ⇒ Object
- #visit_steps(steps) ⇒ Object
- #visit_table_cell_value(value, status) ⇒ Object
- #visit_table_row(table_row) ⇒ Object
- #visit_tag_name(tag_name) ⇒ Object
- #visit_tags(tags) ⇒ Object
Methods included from Duration
Methods inherited from Ast::Visitor
#visit_examples_array, #visit_table_cell
Constructor Details
#initialize(step_mother, io, options) ⇒ Html
Returns a new instance of Html.
11 12 13 14 15 |
# File 'lib/cucumber/formatter/html.rb', line 11 def initialize(step_mother, io, ) super(step_mother) @options = @builder = create_builder(io) end |
Instance Method Details
#announce(announcement) ⇒ Object
228 229 230 |
# File 'lib/cucumber/formatter/html.rb', line 228 def announce(announcement) @builder.pre(announcement, :class => 'announcement') end |
#create_builder(io) ⇒ Object
17 18 19 |
# File 'lib/cucumber/formatter/html.rb', line 17 def create_builder(io) OrderedXmlMarkup.new(:target => io, :indent => 0) end |
#visit_background(background) ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/cucumber/formatter/html.rb', line 88 def visit_background(background) @builder.div(:class => 'background') do @in_background = true super @in_background = nil end end |
#visit_background_name(keyword, name, file_colon_line, source_indent) ⇒ Object
96 97 98 99 100 101 102 103 |
# File 'lib/cucumber/formatter/html.rb', line 96 def visit_background_name(keyword, name, file_colon_line, source_indent) @listing_background = true @builder.h3 do |h3| @builder.span(keyword, :class => 'keyword') @builder.text!(' ') @builder.span(name, :class => 'val') end end |
#visit_comment(comment) ⇒ Object
45 46 47 48 49 |
# File 'lib/cucumber/formatter/html.rb', line 45 def visit_comment(comment) @builder.pre(:class => 'comment') do super end end |
#visit_comment_line(comment_line) ⇒ Object
51 52 53 54 |
# File 'lib/cucumber/formatter/html.rb', line 51 def visit_comment_line(comment_line) @builder.text!(comment_line) @builder.br end |
#visit_examples(examples) ⇒ Object
133 134 135 136 137 |
# File 'lib/cucumber/formatter/html.rb', line 133 def visit_examples(examples) @builder.div(:class => 'examples') do super(examples) end end |
#visit_examples_name(keyword, name) ⇒ Object
139 140 141 142 143 144 145 |
# File 'lib/cucumber/formatter/html.rb', line 139 def visit_examples_name(keyword, name) @builder.h4 do @builder.span(keyword, :class => 'keyword') @builder.text!(' ') @builder.span(name, :class => 'val') end end |
#visit_exception(exception, status) ⇒ Object
181 182 183 |
# File 'lib/cucumber/formatter/html.rb', line 181 def visit_exception(exception, status) @builder.pre(format_exception(exception), :class => status) end |
#visit_feature(feature) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/cucumber/formatter/html.rb', line 56 def visit_feature(feature) @exceptions = [] @builder.div(:class => 'feature') do super end end |
#visit_feature_element(feature_element) ⇒ Object
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/cucumber/formatter/html.rb', line 105 def visit_feature_element(feature_element) css_class = { Ast::Scenario => 'scenario', Ast::ScenarioOutline => 'scenario outline' }[feature_element.class] @builder.div(:class => css_class) do super end @open_step_list = true end |
#visit_feature_name(name) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/cucumber/formatter/html.rb', line 74 def visit_feature_name(name) lines = name.split(/\r?\n/) return if lines.empty? @builder.h2 do |h2| @builder.span(lines[0], :class => 'val') end @builder.p(:class => 'narrative') do lines[1..-1].each do |line| @builder.text!(line.strip) @builder.br end end end |
#visit_features(features) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/cucumber/formatter/html.rb', line 21 def visit_features(features) # <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> @builder.declare!( :DOCTYPE, :html, :PUBLIC, '-//W3C//DTD XHTML 1.0 Strict//EN', 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd' ) @builder.html(:xmlns => 'http://www.w3.org/1999/xhtml') do @builder.head do @builder.(:content => 'text/html;charset=utf-8') @builder.title 'Cucumber' inline_css end @builder.body do @builder.div(:class => 'cucumber') do super @builder.div(format_duration(features.duration), :class => 'duration') end end end end |
#visit_multiline_arg(multiline_arg) ⇒ Object
185 186 187 188 189 190 191 192 193 194 |
# File 'lib/cucumber/formatter/html.rb', line 185 def visit_multiline_arg(multiline_arg) return if @skip_step if Ast::Table === multiline_arg @builder.table do super end else super end end |
#visit_outline_table(outline_table) ⇒ Object
125 126 127 128 129 130 131 |
# File 'lib/cucumber/formatter/html.rb', line 125 def visit_outline_table(outline_table) @outline_row = 0 @builder.table do super(outline_table) end @outline_row = nil end |
#visit_py_string(string) ⇒ Object
196 197 198 199 200 |
# File 'lib/cucumber/formatter/html.rb', line 196 def visit_py_string(string) @builder.pre(:class => 'val') do |pre| @builder << string.gsub("\n", '
') end end |
#visit_scenario_name(keyword, name, file_colon_line, source_indent) ⇒ Object
116 117 118 119 120 121 122 123 |
# File 'lib/cucumber/formatter/html.rb', line 116 def visit_scenario_name(keyword, name, file_colon_line, source_indent) @listing_background = false @builder.h3 do @builder.span(keyword, :class => 'keyword') @builder.text!(' ') @builder.span(name, :class => 'val') end end |
#visit_step(step) ⇒ Object
153 154 155 156 |
# File 'lib/cucumber/formatter/html.rb', line 153 def visit_step(step) @step_id = step.dom_id super end |
#visit_step_name(keyword, step_match, status, source_indent, background) ⇒ Object
170 171 172 173 174 175 176 177 178 179 |
# File 'lib/cucumber/formatter/html.rb', line 170 def visit_step_name(keyword, step_match, status, source_indent, background) @step_matches ||= [] background_in_scenario = background && !@listing_background @skip_step = @step_matches.index(step_match) || background_in_scenario @step_matches << step_match unless @skip_step build_step(keyword, step_match, status) end end |
#visit_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background) ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/cucumber/formatter/html.rb', line 158 def visit_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background) if exception return if @exceptions.index(exception) @exceptions << exception end return if status != :failed && @in_background ^ background @status = status @builder.li(:id => @step_id, :class => "step #{status}") do super(keyword, step_match, multiline_arg, status, exception, source_indent, background) end end |
#visit_steps(steps) ⇒ Object
147 148 149 150 151 |
# File 'lib/cucumber/formatter/html.rb', line 147 def visit_steps(steps) @builder.ol do super end end |
#visit_table_cell_value(value, status) ⇒ Object
220 221 222 223 224 225 226 |
# File 'lib/cucumber/formatter/html.rb', line 220 def visit_table_cell_value(value, status) cell_type = @outline_row == 0 ? :th : :td attributes = {:id => "#{@row_id}_#{@col_index}", :class => 'val'} attributes[:class] += " #{status}" if status build_cell(cell_type, value, attributes) @col_index += 1 end |
#visit_table_row(table_row) ⇒ Object
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/cucumber/formatter/html.rb', line 202 def visit_table_row(table_row) @row_id = table_row.dom_id @col_index = 0 @builder.tr(:id => @row_id) do super end if table_row.exception @builder.tr do @builder.td(:colspan => @col_index.to_s, :class => 'failed') do @builder.pre do |pre| pre << format_exception(table_row.exception) end end end end @outline_row += 1 if @outline_row end |
#visit_tag_name(tag_name) ⇒ Object
68 69 70 71 72 |
# File 'lib/cucumber/formatter/html.rb', line 68 def visit_tag_name(tag_name) @builder.text!(@tag_spacer) if @tag_spacer @tag_spacer = ' ' @builder.span("@#{tag_name}", :class => 'tag') end |
#visit_tags(tags) ⇒ Object
63 64 65 66 |
# File 'lib/cucumber/formatter/html.rb', line 63 def () super @tag_spacer = nil end |