Class: Cucumber::Formatter::Html

Inherits:
Ast::Visitor show all
Includes:
Duration, ERB::Util
Defined in:
lib/cucumber/formatter/html.rb

Instance Attribute Summary

Attributes inherited from Ast::Visitor

#options, #step_mother

Instance Method Summary collapse

Methods included from Duration

#format_duration

Methods inherited from Ast::Visitor

#matches_scenario_names?, #visit_examples_array, #visit_table_cell

Constructor Details

#initialize(step_mother, io, options) ⇒ Html

Returns a new instance of Html.



10
11
12
13
14
# File 'lib/cucumber/formatter/html.rb', line 10

def initialize(step_mother, io, options)
  super(step_mother)
  @options = options
  @builder = create_builder(io)
end

Instance Method Details

#announce(announcement) ⇒ Object



227
228
229
# File 'lib/cucumber/formatter/html.rb', line 227

def announce(announcement)
  @builder.pre(announcement, :class => 'announcement')
end

#create_builder(io) ⇒ Object



16
17
18
# File 'lib/cucumber/formatter/html.rb', line 16

def create_builder(io)
  OrderedXmlMarkup.new(:target => io, :indent => 0)
end

#visit_background(background) ⇒ Object



87
88
89
90
91
92
93
# File 'lib/cucumber/formatter/html.rb', line 87

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



95
96
97
98
99
100
101
102
# File 'lib/cucumber/formatter/html.rb', line 95

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



44
45
46
47
48
# File 'lib/cucumber/formatter/html.rb', line 44

def visit_comment(comment)
  @builder.pre(:class => 'comment') do
    super
  end
end

#visit_comment_line(comment_line) ⇒ Object



50
51
52
53
# File 'lib/cucumber/formatter/html.rb', line 50

def visit_comment_line(comment_line)
  @builder.text!(comment_line)
  @builder.br
end

#visit_examples(examples) ⇒ Object



132
133
134
135
136
# File 'lib/cucumber/formatter/html.rb', line 132

def visit_examples(examples)
  @builder.div(:class => 'examples') do
    super(examples)
  end
end

#visit_examples_name(keyword, name) ⇒ Object



138
139
140
141
142
143
144
# File 'lib/cucumber/formatter/html.rb', line 138

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



180
181
182
# File 'lib/cucumber/formatter/html.rb', line 180

def visit_exception(exception, status)
  @builder.pre(format_exception(exception), :class => status)
end

#visit_feature(feature) ⇒ Object



55
56
57
58
59
60
# File 'lib/cucumber/formatter/html.rb', line 55

def visit_feature(feature)
  @exceptions = []
  @builder.div(:class => 'feature') do
    super
  end
end

#visit_feature_element(feature_element) ⇒ Object



104
105
106
107
108
109
110
111
112
113
# File 'lib/cucumber/formatter/html.rb', line 104

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



73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/cucumber/formatter/html.rb', line 73

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



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/cucumber/formatter/html.rb', line 20

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.meta(: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



184
185
186
187
188
189
190
191
192
193
# File 'lib/cucumber/formatter/html.rb', line 184

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



124
125
126
127
128
129
130
# File 'lib/cucumber/formatter/html.rb', line 124

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



195
196
197
198
199
# File 'lib/cucumber/formatter/html.rb', line 195

def visit_py_string(string)
  @builder.pre(:class => 'val') do |pre|
    @builder << string.gsub("\n", '&#x000A;')
  end
end

#visit_scenario_name(keyword, name, file_colon_line, source_indent) ⇒ Object



115
116
117
118
119
120
121
122
# File 'lib/cucumber/formatter/html.rb', line 115

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



152
153
154
155
# File 'lib/cucumber/formatter/html.rb', line 152

def visit_step(step)
  @step_id = step.dom_id
  super
end

#visit_step_name(keyword, step_match, status, source_indent, background) ⇒ Object



169
170
171
172
173
174
175
176
177
178
# File 'lib/cucumber/formatter/html.rb', line 169

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



157
158
159
160
161
162
163
164
165
166
167
# File 'lib/cucumber/formatter/html.rb', line 157

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



146
147
148
149
150
# File 'lib/cucumber/formatter/html.rb', line 146

def visit_steps(steps)
  @builder.ol do
    super
  end
end

#visit_table_cell_value(value, status) ⇒ Object



219
220
221
222
223
224
225
# File 'lib/cucumber/formatter/html.rb', line 219

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



201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/cucumber/formatter/html.rb', line 201

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



67
68
69
70
71
# File 'lib/cucumber/formatter/html.rb', line 67

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



62
63
64
65
# File 'lib/cucumber/formatter/html.rb', line 62

def visit_tags(tags)
  super
  @tag_spacer = nil
end