Class: Cucumber::Formatters::HtmlFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/gems/cucumber-0.1.15/lib/cucumber/formatters/html_formatter.rb

Instance Method Summary collapse

Constructor Details

#initialize(io, step_mother) ⇒ HtmlFormatter

Returns a new instance of HtmlFormatter.



6
7
8
9
10
11
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/formatters/html_formatter.rb', line 6

def initialize(io, step_mother)
  @io = io
  @step_mother = step_mother
  @errors = []
  @scenario_table_header = []
end

Instance Method Details

#dumpObject



128
129
130
131
132
133
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/formatters/html_formatter.rb', line 128

def dump
  @io.puts <<-HTML
  </body>
</html>
HTML
end


124
125
126
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/formatters/html_formatter.rb', line 124

def print_javascript_tag(js)
  @io.puts %{    <script type="text/javascript">#{js}</script>}
end

#step_failed(step, regexp, args) ⇒ Object



107
108
109
110
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/formatters/html_formatter.rb', line 107

def step_failed(step, regexp, args)
  @errors << step.error
  print_javascript_tag("stepFailed(#{step.id}, #{step.error.message.inspect}, #{step.error.backtrace.join("\n").inspect})")
end

#step_passed(step, regexp, args) ⇒ Object



103
104
105
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/formatters/html_formatter.rb', line 103

def step_passed(step, regexp, args)
  print_javascript_tag("stepPassed(#{step.id})")
end

#step_pending(step, regexp, args) ⇒ Object



112
113
114
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/formatters/html_formatter.rb', line 112

def step_pending(step, regexp, args)
  print_javascript_tag("stepPending(#{step.id})")
end

#step_skipped(step, regexp, args) ⇒ Object



116
117
118
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/formatters/html_formatter.rb', line 116

def step_skipped(step, regexp, args)
  # noop
end

#step_traced(step, regexp, args) ⇒ Object



120
121
122
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/formatters/html_formatter.rb', line 120

def step_traced(step, regexp, args)
  # noop
end

#visit_feature(feature) ⇒ Object



43
44
45
46
47
48
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/formatters/html_formatter.rb', line 43

def visit_feature(feature)
  @io.puts %{      <dl class="feature new">}
  feature.accept(self)
  @io.puts %{        </dd>}
  @io.puts %{      </dl>}
end

#visit_features(features) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/formatters/html_formatter.rb', line 13

def visit_features(features)
  # IMPORTANT NOTICE ABOUT JQUERY BELOW. THE ORIGINAL BACKSLASHES (\) HAVE
  # BEEN REPLACED BY DOUBLE BACKSLASHES (\\) IN THIS FILE TO MAKE SURE THEY
  # ARE PRINTED PROPERLY WITH ONLY ONE BACKSLASH (\).
  @io.puts(<<-HTML)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html 
  PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <title>#{Cucumber.language['feature']}</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="Expires" content="-1" />
    <meta http-equiv="Pragma" content="no-cache" />
    <script type="text/javascript">
#{IO.read(File.dirname(__FILE__) + '/jquery.js')}
#{IO.read(File.dirname(__FILE__) + '/cucumber.js')}
    </script>
    <style>
#{IO.read(File.dirname(__FILE__) + '/cucumber.css')}
    </style>
  </head>
  <body>
    <div id="container">
HTML
  features.accept(self)
  @io.puts %{    </div>}
end

#visit_header(header) ⇒ Object



50
51
52
53
54
55
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/formatters/html_formatter.rb', line 50

def visit_header(header)
  header = header.gsub(/\n/, "<br />\n")
  @io.puts %{        <dt>#{header}}
  @io.puts %{        </dt>}
  @io.puts %{        <dd>}
end

#visit_regular_scenario(scenario) ⇒ Object



57
58
59
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/formatters/html_formatter.rb', line 57

def visit_regular_scenario(scenario)
  visit_scenario(scenario, Cucumber.language['scenario'])
end

#visit_regular_step(step) ⇒ Object



93
94
95
96
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/formatters/html_formatter.rb', line 93

def visit_regular_step(step)
  regexp, _, _ = step.regexp_args_proc(@step_mother)
  @io.puts %{                <li class="new" id="#{step.id}">#{step.keyword} #{step.format(regexp, '<span>%s</span>')}</li>}
end

#visit_row_scenario(scenario) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/formatters/html_formatter.rb', line 65

def visit_row_scenario(scenario)
  @io.puts %{          <dl class="new">}
  @io.puts %{            <dt>#{Cucumber.language['scenario']}: #{scenario.name}</dt>}
  @io.puts %{            <dd>}
  @io.puts %{              <table cellpadding="3">}
  @io.puts %{                <thead>}
  @io.puts %{                  <tr>}
  @scenario_table_header.each do |column_header|
    @io.puts %{                    <th>#{column_header}</th>}
  end
  @io.puts %{                  </tr>}
  @io.puts %{                </thead>}
  @io.puts %{                <tbody>}
  scenario.accept(self)
  @io.puts %{                </tbody>}
  @io.puts %{              </table>}
  @io.puts %{            </dd>}
  @io.puts %{          </dl>}
end

#visit_row_step(step) ⇒ Object



85
86
87
88
89
90
91
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/formatters/html_formatter.rb', line 85

def visit_row_step(step)
  _, args, _ = step.regexp_args_proc(@step_mother)
  args = step.visible_args if step.outline?
  args.each do |arg|
    @io.puts %{                    <td id="#{step.id}"><span>#{arg}</span></td>}
  end
end

#visit_scenario_outline(scenario) ⇒ Object



61
62
63
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/formatters/html_formatter.rb', line 61

def visit_scenario_outline(scenario)
  visit_scenario(scenario, Cucumber.language['scenario_outline'])
end

#visit_step_outline(step) ⇒ Object



98
99
100
101
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/formatters/html_formatter.rb', line 98

def visit_step_outline(step)
  regexp, _, _ = step.regexp_args_proc(@step_mother)
  @io.puts %{                <li class="new" id="#{step.id}">#{step.keyword} #{CGI.escapeHTML(step.format(nil))}</li>}
end