Class: Cucumber::Formatter::HtmlImage
- Inherits:
-
Object
- Object
- Cucumber::Formatter::HtmlImage
show all
- Includes:
- Duration, Io, ERB::Util
- Defined in:
- lib/cucumber/formatter/html_image.rb
Defined Under Namespace
Classes: SnippetExtractor
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) ⇒ Object
-
#after_steps(steps) ⇒ Object
-
#after_table_row(table_row) ⇒ Object
-
#after_tags(tags) ⇒ 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) ⇒ Object
-
#before_steps(steps) ⇒ Object
-
#before_table_row(table_row) ⇒ Object
-
#comment_line(comment_line) ⇒ Object
-
#doc_string(string) ⇒ Object
-
#embed(src, mime_type, label) ⇒ Object
-
#embed_image(src, label) ⇒ 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(step_mother, path_or_io, options) ⇒ HtmlImage
constructor
A new instance of HtmlImage.
-
#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) ⇒ Object
-
#table_cell_value(value, status) ⇒ Object
-
#tag_name(tag_name) ⇒ Object
Methods included from Io
#ensure_dir, #ensure_file, #ensure_io
Methods included from Duration
#format_duration
Constructor Details
#initialize(step_mother, path_or_io, options) ⇒ HtmlImage
Returns a new instance of HtmlImage.
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/cucumber/formatter/html_image.rb', line 15
def initialize(step_mother, path_or_io, options)
@options = options
@demo_site_path = File.expand_path(File.dirname(__FILE__) + '/../../../demo_test_site')
=begin
if options[:paths].length > 0
file_name = File.basename(options[:paths].first)
dir_name = File.expand_path("#{File.dirname(options[:paths].first)}/../results")
FileUtils.mkdir dir_name unless File.directory? dir_name
html = File.expand_path("#{dir_name}/#{file_name}_#{Time.now}.html")
else
=end
FileUtils.mkdir Dir.pwd + '/results' unless File.directory? Dir.pwd + '/results'
t = "#{Time.now}".gsub(':', '_')
html = Dir.pwd + "/results/test_run_#{t}.html"
@io = ensure_io(html, 'html')
@step_mother = step_mother
@buffer = {}
@builder = create_builder(@io)
@feature_number = 0
@scenario_number = 0
@step_number = 0
@header_red = nil
@delayed_messages = []
@img_id = 0
@feature_ct = 0
end
|
Instance Method Details
#after_background(background) ⇒ Object
180
181
182
183
|
# File 'lib/cucumber/formatter/html_image.rb', line 180
def after_background(background)
@in_background = nil
@builder << '</div>'
end
|
142
143
144
|
# File 'lib/cucumber/formatter/html_image.rb', line 142
def ()
@builder << '</pre>'
end
|
#after_examples(examples) ⇒ Object
235
236
237
|
# File 'lib/cucumber/formatter/html_image.rb', line 235
def after_examples(examples)
@builder << '</div>'
end
|
#after_feature(feature) ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
# File 'lib/cucumber/formatter/html_image.rb', line 109
def after_feature(feature)
if Cucumber::Constants::IMAGES.length > 0
if Cucumber::Constants::IMAGES.length > 1
images = Cucumber::Constants::IMAGES[1..Cucumber::Constants::IMAGES.length]
else
images = Cucumber::Constants::IMAGES
end
@builder << "<center>"
@builder << "<div id='result_images_#{@feature_ct}'>"
res = "result_images_#{@feature_ct}"
@builder << "<img id='prev_img' alt='#{res}' src='#{@demo_site_path}/public/images/arrow_left_48.png'>"
@builder << "<img id='next_img' alt='#{res}' src='#{@demo_site_path}/public/images/arrow_right_48.png'>"
Cucumber::Constants::IMAGES.each_with_index { |i, ct|
if ct == 0
@builder << "<div id='active_img'><h2>#{i[:label]}</h2><br><br><img id='result_image_#{ct}' alt='#{i[:label]}' src='#{i[:src]}'></div>"
end
@builder << "<img id='result_image_#{ct}' class='hidden' alt='#{i[:label]}' src='#{i[:src]}'>"
}
@builder << "<img id='prev_img' alt='#{res}' src='#{@demo_site_path}/public/images/arrow_left_48.png'>"
@builder << "<img id='next_img' alt='#{res}' src='#{@demo_site_path}/public/images/arrow_right_48.png'>"
@builder << "</div>"
@builder << "</center>"
end
@feature_ct += 1
Cucumber::Constants::IMAGES.delete_all
@builder << '</div>'
end
|
#after_feature_element(feature_element) ⇒ Object
204
205
206
207
|
# File 'lib/cucumber/formatter/html_image.rb', line 204
def after_feature_element(feature_element)
@builder << '</div>'
@open_step_list = true
end
|
#after_features(features) ⇒ Object
97
98
99
100
101
102
|
# File 'lib/cucumber/formatter/html_image.rb', line 97
def after_features(features)
print_stats(features)
@builder << '</div>'
@builder << '</body>'
@builder << '</html>'
end
|
#after_multiline_arg(multiline_arg) ⇒ Object
331
332
333
334
335
336
|
# File 'lib/cucumber/formatter/html_image.rb', line 331
def after_multiline_arg(multiline_arg)
return if @hide_this_step || @skip_step
if Ast::Table === multiline_arg
@builder << '</table>'
end
end
|
#after_outline_table(outline_table) ⇒ Object
226
227
228
229
|
# File 'lib/cucumber/formatter/html_image.rb', line 226
def after_outline_table(outline_table)
@builder << '</table>'
@outline_row = nil
end
|
#after_step(step) ⇒ Object
263
264
265
|
# File 'lib/cucumber/formatter/html_image.rb', line 263
def after_step(step)
move_progress
end
|
#after_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background) ⇒ Object
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
|
# File 'lib/cucumber/formatter/html_image.rb', line 287
def after_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background)
return if @hide_this_step
if status == :undefined
step_multiline_class = @step.multiline_arg ? @step.multiline_arg.class : nil
@builder.pre do |pre|
pre << @step_mother.snippet_text(@step.actual_keyword,step_match.instance_variable_get("@name") || '',step_multiline_class)
end
end
@builder << '</li>'
print_messages
end
|
#after_steps(steps) ⇒ Object
252
253
254
255
|
# File 'lib/cucumber/formatter/html_image.rb', line 252
def after_steps(steps)
@builder << '</ol>'
end
|
#after_table_row(table_row) ⇒ Object
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
|
# File 'lib/cucumber/formatter/html_image.rb', line 353
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 << format_exception(table_row.exception)
end
end
end
set_scenario_color_failed
end
if @outline_row
@outline_row += 1
end
@step_number += 1
move_progress
end
|
151
152
153
|
# File 'lib/cucumber/formatter/html_image.rb', line 151
def after_tags(tags)
@tag_spacer = nil
end
|
#background_name(keyword, name, file_colon_line, source_indent) ⇒ Object
185
186
187
188
189
190
191
192
|
# File 'lib/cucumber/formatter/html_image.rb', line 185
def 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
|
#before_background(background) ⇒ Object
175
176
177
178
|
# File 'lib/cucumber/formatter/html_image.rb', line 175
def before_background(background)
@in_background = true
@builder << '<div class="background">'
end
|
138
139
140
|
# File 'lib/cucumber/formatter/html_image.rb', line 138
def ()
@builder << '<pre class="comment">'
end
|
#before_examples(examples) ⇒ Object
231
232
233
|
# File 'lib/cucumber/formatter/html_image.rb', line 231
def before_examples(examples)
@builder << '<div class="examples">'
end
|
#before_feature(feature) ⇒ Object
104
105
106
107
|
# File 'lib/cucumber/formatter/html_image.rb', line 104
def before_feature(feature)
@exceptions = []
@builder << '<div class="feature">'
end
|
#before_feature_element(feature_element) ⇒ Object
194
195
196
197
198
199
200
201
202
|
# File 'lib/cucumber/formatter/html_image.rb', line 194
def before_feature_element(feature_element)
@scenario_number+=1
@scenario_red = false
css_class = {
Ast::Scenario => 'scenario',
Ast::ScenarioOutline => 'scenario outline'
}[feature_element.class]
@builder << "<div class='#{css_class}'>"
end
|
#before_features(features) ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/cucumber/formatter/html_image.rb', line 60
def before_features(features)
@step_count = get_step_count(features)
@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">'
@builder.head do
@builder.meta(:content => 'text/html;charset=utf-8')
@builder.title 'Cucumber'
inline_css
inline_js
end
@builder << '<body>'
@builder << "<!-- Step count #{@step_count}-->"
@builder << '<div class="cucumber">'
@builder.div(:id => 'cucumber-header') do
@builder.div(:id => 'label') do
@builder.h1('Cucumber Features')
end
@builder.div(:id => 'summary') do
@builder.p('',:id => 'totals')
@builder.p('',:id => 'duration')
@builder.div(:id => 'expand-collapse') do
@builder.p('Expand All', :id => 'expander')
@builder.p('Collapse All', :id => 'collapser')
end
end
end
end
|
#before_multiline_arg(multiline_arg) ⇒ Object
324
325
326
327
328
329
|
# File 'lib/cucumber/formatter/html_image.rb', line 324
def before_multiline_arg(multiline_arg)
return if @hide_this_step || @skip_step
if Ast::Table === multiline_arg
@builder << '<table>'
end
end
|
#before_outline_table(outline_table) ⇒ Object
221
222
223
224
|
# File 'lib/cucumber/formatter/html_image.rb', line 221
def before_outline_table(outline_table)
@outline_row = 0
@builder << '<table>'
end
|
#before_step(step) ⇒ Object
257
258
259
260
261
|
# File 'lib/cucumber/formatter/html_image.rb', line 257
def before_step(step)
@step_id = step.dom_id
@step_number += 1
@step = step
end
|
#before_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background) ⇒ Object
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
|
# File 'lib/cucumber/formatter/html_image.rb', line 267
def before_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background)
@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)
@builder << "<li id='#{@step_id}' class='step #{status}'>"
end
|
#before_steps(steps) ⇒ Object
247
248
249
250
|
# File 'lib/cucumber/formatter/html_image.rb', line 247
def before_steps(steps)
@builder << '<ol>'
end
|
#before_table_row(table_row) ⇒ Object
346
347
348
349
350
351
|
# File 'lib/cucumber/formatter/html_image.rb', line 346
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
|
146
147
148
149
|
# File 'lib/cucumber/formatter/html_image.rb', line 146
def ()
@builder.text!()
@builder.br
end
|
#doc_string(string) ⇒ Object
338
339
340
341
342
343
|
# File 'lib/cucumber/formatter/html_image.rb', line 338
def doc_string(string)
return if @hide_this_step
@builder.pre(:class => 'val') do |pre|
@builder << h(string).gsub("\n", '
')
end
end
|
#embed(src, mime_type, label) ⇒ Object
43
44
45
46
47
48
|
# File 'lib/cucumber/formatter/html_image.rb', line 43
def embed(src, mime_type, label)
case(mime_type)
when /^image\/(png|gif|jpg|jpeg)/
embed_image(src, label)
end
end
|
#embed_image(src, label) ⇒ Object
50
51
52
53
54
55
56
57
|
# File 'lib/cucumber/formatter/html_image.rb', line 50
def embed_image(src, label)
id = "img_#{@img_id}"
@img_id += 1
@builder.span(:class => 'embed') do |pre|
pre << %{<a href="" onclick="img=document.getElementById('#{id}'); img.style.display = (img.style.display == 'none' ? 'block' : 'none');return false">#{label}</a><br>
<img id="#{id}" style="display: none" src="#{src}"/>}
end
end
|
#empty_messages ⇒ Object
412
413
414
|
# File 'lib/cucumber/formatter/html_image.rb', line 412
def empty_messages
@delayed_messages = []
end
|
#examples_name(keyword, name) ⇒ Object
239
240
241
242
243
244
245
|
# File 'lib/cucumber/formatter/html_image.rb', line 239
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
315
316
317
|
# File 'lib/cucumber/formatter/html_image.rb', line 315
def exception(exception, status)
build_exception_detail(exception)
end
|
319
320
321
322
|
# File 'lib/cucumber/formatter/html_image.rb', line 319
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
161
162
163
164
165
166
167
168
169
170
171
172
173
|
# File 'lib/cucumber/formatter/html_image.rb', line 161
def feature_name(keyword, name)
lines = name.split(/\r?\n/)
return if lines.empty?
@builder.h2 do |h2|
@builder.span(keyword + ': ' + 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
|
#print_messages ⇒ Object
390
391
392
393
394
395
396
397
398
399
400
401
|
# File 'lib/cucumber/formatter/html_image.rb', line 390
def print_messages
return if @delayed_messages.empty?
@delayed_messages.each do |ann|
@builder.li(:class => 'step message') do
@builder << ann
end
end
empty_messages
end
|
#print_table_row_messages ⇒ Object
403
404
405
406
407
408
409
410
|
# File 'lib/cucumber/formatter/html_image.rb', line 403
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
385
386
387
388
|
# File 'lib/cucumber/formatter/html_image.rb', line 385
def puts(message)
@delayed_messages << message
end
|
#scenario_name(keyword, name, file_colon_line, source_indent) ⇒ Object
209
210
211
212
213
214
215
216
217
218
219
|
# File 'lib/cucumber/formatter/html_image.rb', line 209
def scenario_name(keyword, name, file_colon_line, source_indent)
@builder.span(:class => 'scenario_file') do
@builder << file_colon_line
end
@listing_background = false
@builder.h3(:id => "scenario_#{@scenario_number}") do
@builder.span(keyword + ':', :class => 'keyword')
@builder.text!(' ')
@builder.span(name, :class => 'val')
end
end
|
#step_name(keyword, step_match, status, source_indent, background) ⇒ Object
304
305
306
307
308
309
310
311
312
313
|
# File 'lib/cucumber/formatter/html_image.rb', line 304
def 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
|
#table_cell_value(value, status) ⇒ Object
374
375
376
377
378
379
380
381
382
383
|
# File 'lib/cucumber/formatter/html_image.rb', line 374
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)
@col_index += 1
end
|
#tag_name(tag_name) ⇒ Object
155
156
157
158
159
|
# File 'lib/cucumber/formatter/html_image.rb', line 155
def tag_name(tag_name)
@builder.text!(@tag_spacer) if @tag_spacer
@tag_spacer = ' '
@builder.span(tag_name, :class => 'tag')
end
|