Class: Cucumber::Formatter::Html

Inherits:
Ast::Visitor show all
Defined in:
lib/cucumber/formatter/html.rb

Instance Attribute Summary

Attributes inherited from Ast::Visitor

#options, #step_mother

Instance Method Summary collapse

Methods inherited from Ast::Visitor

#current_feature_lines=, #excluded_by_tags?, #included_by_tags?, #matches_lines?, #matches_scenario_names?, #visit_comment, #visit_comment_line, #visit_examples, #visit_table_cell, #visit_tag_name, #visit_tags

Constructor Details

#initialize(step_mother, io, options) ⇒ Html

Returns a new instance of Html.



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

def initialize(step_mother, io, options)
  super(step_mother)
  @builder = Builder::XmlMarkup.new(:target => io, :indent => 2)
end

Instance Method Details

#announce(announcement) ⇒ Object



159
160
161
# File 'lib/cucumber/formatter/html.rb', line 159

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

#visit_background(background) ⇒ Object



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

def visit_background(background)
  @builder.div(:class => 'background') do
    super
  end
end

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



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

def visit_background_name(keyword, name, file_colon_line, source_indent)
  @builder.h3("#{keyword} #{name}")
end

#visit_examples_name(keyword, name) ⇒ Object



84
85
86
# File 'lib/cucumber/formatter/html.rb', line 84

def visit_examples_name(keyword, name)
  @builder.h4("#{keyword} #{name}")
end

#visit_exception(exception, status) ⇒ Object



114
115
116
# File 'lib/cucumber/formatter/html.rb', line 114

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

#visit_feature(feature) ⇒ Object



38
39
40
41
42
# File 'lib/cucumber/formatter/html.rb', line 38

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

#visit_feature_element(feature_element) ⇒ Object



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

def visit_feature_element(feature_element)
  @builder.div(:class => 'scenario') do
    super
  end
  @open_step_list = true
end

#visit_feature_name(name) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/cucumber/formatter/html.rb', line 44

def visit_feature_name(name)
  lines = name.split(/\r?\n/)
  @builder.h2(lines[0])
  @builder.p do
    lines[1..-1].each do |line|
      @builder.text!(line.strip)
      @builder.br
    end
  end
end

#visit_features(features) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/cucumber/formatter/html.rb', line 16

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.title 'Cucumber'
      inline_css
    end
    @builder.body do
      @builder.div(:class => 'cucumber') do
        super
      end
    end
  end
end

#visit_multiline_arg(multiline_arg) ⇒ Object



118
119
120
121
122
123
124
125
126
127
# File 'lib/cucumber/formatter/html.rb', line 118

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



76
77
78
79
80
81
82
# File 'lib/cucumber/formatter/html.rb', line 76

def visit_outline_table(outline_table)
  @outline_row = 0
  @builder.table do
    super(outline_table)
  end
  @outline_row = nil
end

#visit_py_string(string, status) ⇒ Object



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

def visit_py_string(string, status)
  @builder.pre(:class => status) do |pre|
    pre << string
  end
end

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



72
73
74
# File 'lib/cucumber/formatter/html.rb', line 72

def visit_scenario_name(keyword, name, file_colon_line, source_indent)
  @builder.h3("#{keyword} #{name}")
end

#visit_step(step) ⇒ Object



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

def visit_step(step)
  @step_id = step.dom_id
  @builder.li(:id => @step_id) do
    super
  end
end

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



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

def visit_step_name(keyword, step_match, status, source_indent, background)
  @step_matches ||= []
  @skip_step = @step_matches.index(step_match)
  @step_matches << step_match

  unless @skip_step
    step_name = step_match.format_args(lambda{|param| "<span>#{param}</span>"})
    @builder.div(:class => status) do |div|
      div << "#{keyword} #{step_name}"
    end
  end
end

#visit_steps(steps) ⇒ Object



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

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

#visit_table_cell_value(value, width, status) ⇒ Object



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

def visit_table_cell_value(value, width, status)
  cell_type = @outline_row == 0 ? :th : :td
  @builder.__send__(cell_type, value, :class => status, :id => "#{@row_id}_#{@col_index}")
  @col_index += 1
end

#visit_table_row(table_row) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/cucumber/formatter/html.rb', line 135

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