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, #visit_tags

Constructor Details

#initialize(step_mother, io, options) ⇒ Html

Returns a new instance of Html.



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

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

Instance Method Details

#announce(announcement) ⇒ Object



225
226
227
# File 'lib/cucumber/formatter/html.rb', line 225

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

#create_builder(io) ⇒ Object



22
23
24
# File 'lib/cucumber/formatter/html.rb', line 22

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

#visit_background(background) ⇒ Object



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

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



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

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



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

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

#visit_comment_line(comment_line) ⇒ Object



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

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

#visit_examples(examples) ⇒ Object



130
131
132
133
134
# File 'lib/cucumber/formatter/html.rb', line 130

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

#visit_examples_name(keyword, name) ⇒ Object



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

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



178
179
180
# File 'lib/cucumber/formatter/html.rb', line 178

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

#visit_feature(feature) ⇒ Object



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

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

#visit_feature_element(feature_element) ⇒ Object



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

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



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

def visit_feature_name(name)
  lines = name.split(/\r?\n/)
  @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



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cucumber/formatter/html.rb', line 26

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



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

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



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

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



193
194
195
196
197
# File 'lib/cucumber/formatter/html.rb', line 193

def visit_py_string(string)
  @builder.pre(:class => 'val') do |pre|
    @builder.text!('  ' + string)
  end
end

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



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

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



150
151
152
153
# File 'lib/cucumber/formatter/html.rb', line 150

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

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



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

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



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

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



144
145
146
147
148
# File 'lib/cucumber/formatter/html.rb', line 144

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

#visit_table_cell_value(value, width, status) ⇒ Object



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

def visit_table_cell_value(value, width, 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



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

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
# File 'lib/cucumber/formatter/html.rb', line 68

def visit_tag_name(tag_name)
  @builder.span("@#{tag_name}", :class => 'tag')
end