Class: Closer::Formatter::Html
- Inherits:
-
Object
- Object
- Closer::Formatter::Html
show all
- Includes:
- CloserHtml, Cucumber::Formatter::Duration, Cucumber::Formatter::Io, ERB::Util
- Defined in:
- lib/closer/formatter/html.rb
Defined Under Namespace
Classes: SnippetExtractor
Constant Summary
collapse
- AST_CLASSES =
TODO: remove coupling to types
{
Cucumber::Core::Ast::Scenario => 'scenario',
Cucumber::Core::Ast::ScenarioOutline => 'scenario outline'
}
- AST_DATA_TABLE =
::Cucumber::Formatter::LegacyApi::Ast::MultilineArg::DataTable
Instance Method Summary
collapse
-
#after_background(_background) ⇒ Object
-
#after_comment(_comment) ⇒ Object
-
#after_examples(_examples) ⇒ Object
-
#after_feature(_feature) ⇒ Object
-
#after_feature_element(_feature_element) ⇒ Object
-
#after_features(features) ⇒ Object
-
#after_multiline_arg(multiline_arg) ⇒ Object
-
#after_outline_table(_outline_table) ⇒ Object
-
#after_step(_step) ⇒ Object
-
#after_step_result(keyword, step_match, _multiline_arg, status, _exception, _source_indent, _background, _file_colon_line) ⇒ Object
-
#after_steps(_steps) ⇒ Object
-
#after_table_row(table_row) ⇒ Object
-
#after_tags(_tags) ⇒ Object
-
#after_test_case(_test_case, result) ⇒ Object
-
#background_name(keyword, name, _file_colon_line, _source_indent) ⇒ Object
-
#before_background(_background) ⇒ Object
-
#before_comment(_comment) ⇒ Object
-
#before_examples(_examples) ⇒ Object
-
#before_feature(_feature) ⇒ Object
-
#before_feature_element(feature_element) ⇒ Object
-
#before_features(features) ⇒ Object
-
#before_multiline_arg(multiline_arg) ⇒ Object
-
#before_outline_table(_outline_table) ⇒ Object
-
#before_step(step) ⇒ Object
-
#before_step_result(_keyword, step_match, _multiline_arg, status, exception, _source_indent, background, _file_colon_line) ⇒ Object
-
#before_steps(_steps) ⇒ Object
-
#before_table_row(table_row) ⇒ Object
-
#before_test_case(_test_case) ⇒ Object
-
#comment_line(comment_line) ⇒ Object
-
#doc_string(string) ⇒ Object
-
#empty_messages ⇒ Object
-
#examples_name(keyword, name) ⇒ Object
-
#exception(exception, _status) ⇒ Object
-
#extra_failure_content(file_colon_line) ⇒ Object
-
#feature_name(keyword, name) ⇒ Object
-
#initialize(runtime, path_or_io, options) ⇒ Html
constructor
-
#print_messages ⇒ Object
-
#print_table_row_messages ⇒ Object
-
#puts(message) ⇒ Object
-
#scenario_name(keyword, name, file_colon_line, _source_indent) ⇒ Object
-
#step_name(keyword, step_match, status, _source_indent, background, _file_colon_line) ⇒ Object
-
#table_cell_value(value, status) ⇒ Object
-
#tag_name(tag_name) ⇒ Object
Methods included from CloserHtml
#current_time_string, #display_keyword, #feature_dir, #feature_id, #gem_dir, #indent_size, #magic_comment?, #ruby_version_dir
Constructor Details
#initialize(runtime, path_or_io, options) ⇒ Html
Returns a new instance of Html.
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/closer/formatter/html.rb', line 30
def initialize(runtime, path_or_io, options)
@io = ensure_io(path_or_io)
@runtime = runtime
@options = options
@buffer = {}
@builder = HtmlBuilder.new(target: @io, indent: 0)
@feature_number = 0
@scenario_number = 0
@step_number = 0
@header_red = nil
@delayed_messages = []
@inside_outline = false
@previous_step_keyword = nil
@summary = ::Cucumber::Core::Report::Summary.new(runtime.configuration.event_bus)
end
|
Instance Method Details
#after_background(_background) ⇒ Object
136
137
138
139
|
# File 'lib/closer/formatter/html.rb', line 136
def after_background(_background)
@in_background = nil
builder << '</div>'
end
|
87
88
89
90
91
|
# File 'lib/closer/formatter/html.rb', line 87
def ()
return if ()
builder << '</pre>'
end
|
#after_examples(_examples) ⇒ Object
209
210
211
|
# File 'lib/closer/formatter/html.rb', line 209
def after_examples(_examples)
builder << '</div>'
end
|
#after_feature(_feature) ⇒ Object
77
78
79
|
# File 'lib/closer/formatter/html.rb', line 77
def after_feature(_feature)
builder << '</div>'
end
|
#after_feature_element(_feature_element) ⇒ Object
158
159
160
161
162
163
164
165
|
# File 'lib/closer/formatter/html.rb', line 158
def after_feature_element(_feature_element)
unless @in_scenario_outline
print_messages
builder << '</ol>'
end
builder << '</div>'
@in_scenario_outline = nil
end
|
#after_features(features) ⇒ Object
53
54
55
56
57
58
|
# File 'lib/closer/formatter/html.rb', line 53
def after_features(features)
print_stats(features)
builder << '</div>'
builder << '</body>'
builder << '</html>'
end
|
#after_multiline_arg(multiline_arg) ⇒ Object
328
329
330
331
332
333
|
# File 'lib/closer/formatter/html.rb', line 328
def after_multiline_arg(multiline_arg)
return if @hide_this_step || @skip_step
if AST_DATA_TABLE === multiline_arg
builder << '</table>'
end
end
|
#after_outline_table(_outline_table) ⇒ Object
199
200
201
202
203
|
# File 'lib/closer/formatter/html.rb', line 199
def after_outline_table(_outline_table)
builder << '</table>'
@outline_row = nil
@inside_outline = false
end
|
#after_step(_step) ⇒ Object
237
238
|
# File 'lib/closer/formatter/html.rb', line 237
def after_step(_step)
end
|
#after_step_result(keyword, step_match, _multiline_arg, status, _exception, _source_indent, _background, _file_colon_line) ⇒ Object
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
|
# File 'lib/closer/formatter/html.rb', line 265
def after_step_result(keyword, step_match, _multiline_arg, status, _exception, _source_indent, _background, _file_colon_line)
return if @hide_this_step
unless outline_step?(@step)
keyword = @step.actual_keyword(@previous_step_keyword)
@previous_step_keyword = keyword
end
if status == :undefined
builder.pre do |pre|
pre << @runtime.snippet_text(keyword,step_match.instance_variable_get('@name') || '', @step.multiline_arg)
end
end
builder << '</li>'
unless status == :undefined
step_file = step_match.file_colon_line
step_contents = "<div class=\"step_contents hidden\"><pre>"
step_file.gsub(/^([^:]*\.rb):(\d*)/) do
line_index = $2.to_i - 1
file = $1.force_encoding('UTF-8')
file = File.join(gem_dir, file) unless File.exist?(file)
File.readlines(file)[line_index..-1].each do |line|
step_contents << line
break if line.chop == 'end' or line.chop.start_with?('end ')
end
end
step_contents << "</pre></div>"
builder << step_contents
end
print_messages
end
|
#after_steps(_steps) ⇒ Object
225
226
227
228
|
# File 'lib/closer/formatter/html.rb', line 225
def after_steps(_steps)
print_messages
builder << '</ol>' if @in_background || @in_scenario_outline
end
|
#after_table_row(table_row) ⇒ Object
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
|
# File 'lib/closer/formatter/html.rb', line 349
def after_table_row(table_row)
return if @hide_this_step
print_table_row_messages
builder << '</tr>'
if table_row.exception
builder.tr do
builder.td(:colspan => @col_index.to_s, :class => 'failed') do
builder.pre do |pre|
pre << h(format_exception(table_row.exception))
end
end
end
if table_row.exception.is_a? ::Cucumber::Pending
set_scenario_color_pending
else
set_scenario_color_failed
end
end
if @outline_row
@outline_row += 1
end
@step_number += 1
end
|
100
101
102
|
# File 'lib/closer/formatter/html.rb', line 100
def after_tags(_tags)
@tag_spacer = nil
end
|
#after_test_case(_test_case, result) ⇒ Object
415
416
417
418
419
|
# File 'lib/closer/formatter/html.rb', line 415
def after_test_case(_test_case, result)
if result.failed? && !@scenario_red
set_scenario_color_failed
end
end
|
#background_name(keyword, name, _file_colon_line, _source_indent) ⇒ Object
141
142
143
144
145
146
147
148
|
# File 'lib/closer/formatter/html.rb', line 141
def background_name(keyword, name, _file_colon_line, _source_indent)
@listing_background = true
builder.h3(:id => "background_#{@scenario_number}") do |h3|
builder.span(keyword, :class => 'keyword')
builder.text!(' ')
builder.span(name, :class => 'val')
end
end
|
#before_background(_background) ⇒ Object
131
132
133
134
|
# File 'lib/closer/formatter/html.rb', line 131
def before_background(_background)
@in_background = true
builder << '<div class="background">'
end
|
81
82
83
84
85
|
# File 'lib/closer/formatter/html.rb', line 81
def ()
return if ()
builder << '<pre class="comment">'
end
|
#before_examples(_examples) ⇒ Object
205
206
207
|
# File 'lib/closer/formatter/html.rb', line 205
def before_examples(_examples)
builder << '<div class="examples">'
end
|
#before_feature(_feature) ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/closer/formatter/html.rb', line 60
def before_feature(_feature)
dir = feature_dir(_feature)
unless dir.empty?
if @feature_dir != dir
builder << '<div class="feature_dir"><span class="val" onclick="toggle_feature_dir(this);">'
builder << dir
builder << '</span></div>'
end
@feature_dir = dir
end
@feature = _feature
@exceptions = []
builder << "<div id=\"#{feature_id}\" class=\"feature\">"
end
|
#before_feature_element(feature_element) ⇒ Object
150
151
152
153
154
155
156
|
# File 'lib/closer/formatter/html.rb', line 150
def before_feature_element(feature_element)
@scenario_number+=1
@scenario_red = false
css_class = AST_CLASSES[feature_element.class]
builder << "<div class='#{css_class}'>"
@in_scenario_outline = feature_element.class == Cucumber::Core::Ast::ScenarioOutline
end
|
#before_features(features) ⇒ Object
46
47
48
49
50
51
|
# File 'lib/closer/formatter/html.rb', line 46
def before_features(features)
@step_count = features && features.step_count || 0
builder.build_document!
builder.format_features! features
end
|
#before_multiline_arg(multiline_arg) ⇒ Object
321
322
323
324
325
326
|
# File 'lib/closer/formatter/html.rb', line 321
def before_multiline_arg(multiline_arg)
return if @hide_this_step || @skip_step
if AST_DATA_TABLE === multiline_arg
builder << '<table>'
end
end
|
#before_outline_table(_outline_table) ⇒ Object
193
194
195
196
197
|
# File 'lib/closer/formatter/html.rb', line 193
def before_outline_table(_outline_table)
@inside_outline = true
@outline_row = 0
builder << '<table>'
end
|
#before_step(step) ⇒ Object
230
231
232
233
234
235
|
# File 'lib/closer/formatter/html.rb', line 230
def before_step(step)
print_messages
@step_id = step.dom_id
@step_number += 1
@step = step
end
|
#before_step_result(_keyword, step_match, _multiline_arg, status, exception, _source_indent, background, _file_colon_line) ⇒ Object
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
|
# File 'lib/closer/formatter/html.rb', line 240
def before_step_result(_keyword, step_match, _multiline_arg, status, exception, _source_indent, background, _file_colon_line)
@step_match = step_match
@hide_this_step = false
if exception
if @exceptions.include?(exception)
@hide_this_step = true
return
end
@exceptions << exception
end
if status != :failed && @in_background ^ background
@hide_this_step = true
return
end
@status = status
return if @hide_this_step
set_scenario_color(status)
if ! @delayed_messages.empty? and status == :passed
builder << "<li id='#{@step_id}' class='step #{status} expand'>"
else
builder << "<li id='#{@step_id}' class='step #{status}'>"
end
end
|
#before_steps(_steps) ⇒ Object
221
222
223
|
# File 'lib/closer/formatter/html.rb', line 221
def before_steps(_steps)
builder << '<ol class="hidden">'
end
|
#before_table_row(table_row) ⇒ Object
342
343
344
345
346
347
|
# File 'lib/closer/formatter/html.rb', line 342
def before_table_row(table_row)
@row_id = table_row.dom_id
@col_index = 0
return if @hide_this_step
builder << "<tr class='step' id='#{@row_id}'>"
end
|
#before_test_case(_test_case) ⇒ Object
127
128
129
|
# File 'lib/closer/formatter/html.rb', line 127
def before_test_case(_test_case)
@previous_step_keyword = nil
end
|
93
94
95
96
97
98
|
# File 'lib/closer/formatter/html.rb', line 93
def ()
return if ()
builder.text!()
builder.br
end
|
#doc_string(string) ⇒ Object
335
336
337
338
339
340
|
# File 'lib/closer/formatter/html.rb', line 335
def doc_string(string)
return if @hide_this_step
builder.pre(:class => 'val') do |pre|
builder << h(string).gsub("\n", '
')
end
end
|
#empty_messages ⇒ Object
411
412
413
|
# File 'lib/closer/formatter/html.rb', line 411
def empty_messages
@delayed_messages = []
end
|
#examples_name(keyword, name) ⇒ Object
213
214
215
216
217
218
219
|
# File 'lib/closer/formatter/html.rb', line 213
def examples_name(keyword, name)
builder.h4 do
builder.span(keyword, :class => 'keyword')
builder.text!(' ')
builder.span(name, :class => 'val')
end
end
|
#exception(exception, _status) ⇒ Object
310
311
312
313
314
|
# File 'lib/closer/formatter/html.rb', line 310
def exception(exception, _status)
return if @hide_this_step
print_messages
build_exception_detail(exception)
end
|
316
317
318
319
|
# File 'lib/closer/formatter/html.rb', line 316
def (file_colon_line)
@snippet_extractor ||= SnippetExtractor.new
"<pre class=\"ruby\"><code>#{@snippet_extractor.snippet(file_colon_line)}</code></pre>"
end
|
#feature_name(keyword, name) ⇒ Object
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
# File 'lib/closer/formatter/html.rb', line 110
def feature_name(keyword, name)
title = feature_dir(@feature, true) + @feature.file.split('/').last.gsub(/\.feature/, '')
lines = name.split(/\r?\n/)
return if lines.empty?
builder.h2 do |h2|
builder.span(:class => 'val') do
builder << title
end
end
if lines.size > 1
builder.div(:class => 'narrative') do
builder << lines[1..-1].join("\n")
end
end
end
|
#print_messages ⇒ Object
389
390
391
392
393
394
395
396
397
398
399
400
|
# File 'lib/closer/formatter/html.rb', line 389
def print_messages
return if @delayed_messages.empty?
@delayed_messages.each do |ann|
builder.li(:class => 'message hidden') do
builder << ann
end
end
empty_messages
end
|
#print_table_row_messages ⇒ Object
402
403
404
405
406
407
408
409
|
# File 'lib/closer/formatter/html.rb', line 402
def print_table_row_messages
return if @delayed_messages.empty?
builder.td(:class => 'message') do
builder << @delayed_messages.join(', ')
end
empty_messages
end
|
#puts(message) ⇒ Object
384
385
386
387
|
# File 'lib/closer/formatter/html.rb', line 384
def puts(message)
@delayed_messages << message
end
|
#scenario_name(keyword, name, file_colon_line, _source_indent) ⇒ Object
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
# File 'lib/closer/formatter/html.rb', line 167
def scenario_name(keyword, name, file_colon_line, _source_indent)
builder.span(:class => 'scenario_file hidden') do
builder << file_colon_line
end
@listing_background = false
scenario_id = "scenario_#{@scenario_number}"
if @inside_outline
@outline_row += 1
scenario_id += "_#{@outline_row}"
@scenario_red = false
end
lines = name.split("\n")
title = lines.shift
builder.h3(:id => scenario_id) do
builder.span(title, :class => 'val pointer')
end
if lines.size > 0
builder.pre(:class => 'narrative hidden') do
trim_size = indent_size(lines.first)
builder << lines.map{|line| line[trim_size..-1] }.join("\n")
end
end
end
|
#step_name(keyword, step_match, status, _source_indent, background, _file_colon_line) ⇒ Object
301
302
303
304
305
306
307
308
|
# File 'lib/closer/formatter/html.rb', line 301
def step_name(keyword, step_match, status, _source_indent, background, _file_colon_line)
background_in_scenario = background && !@listing_background
@skip_step = background_in_scenario
unless @skip_step
build_step(keyword, step_match, status)
end
end
|
#table_cell_value(value, status) ⇒ Object
373
374
375
376
377
378
379
380
381
382
|
# File 'lib/closer/formatter/html.rb', line 373
def table_cell_value(value, status)
return if @hide_this_step
@cell_type = @outline_row == 0 ? :th : :td
attributes = {:id => "#{@row_id}_#{@col_index}", :class => 'step'}
attributes[:class] += " #{status}" if status
build_cell(@cell_type, value, attributes)
set_scenario_color(status) if @inside_outline
@col_index += 1
end
|
#tag_name(tag_name) ⇒ Object
104
105
106
107
108
|
# File 'lib/closer/formatter/html.rb', line 104
def tag_name(tag_name)
builder.text!(@tag_spacer) if @tag_spacer
@tag_spacer = ' '
builder.span(tag_name, :class => 'tag')
end
|