Class: Daddy::Formatter::Html
- Inherits:
-
Object
- Object
- Daddy::Formatter::Html
show all
- Includes:
- Cucumber::Formatter::Duration, Cucumber::Formatter::Io, DaddyHtml, ERB::Util
- Defined in:
- lib/daddy/formatter/html.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, file_colon_line) ⇒ 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, file_colon_line) ⇒ Object
-
#before_steps(steps) ⇒ Object
-
#before_table_row(table_row) ⇒ 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 DaddyHtml
#after_menu, #before_menu, #feature_dir, #feature_id, #magic_comment?, #make_menu_for_publish, #should_expand, #title
Constructor Details
#initialize(runtime, path_or_io, options) ⇒ Html
Returns a new instance of Html.
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/daddy/formatter/html.rb', line 17
def initialize(runtime, path_or_io, options)
@io = ensure_io(path_or_io, "html")
@runtime = runtime
@options = options
@buffer = {}
@builder = create_builder(@io)
@feature_number = 0
@step_number = 0
@header_red = nil
@delayed_messages = []
@inside_outline = false
end
|
Instance Method Details
#after_background(background) ⇒ Object
149
150
151
152
|
# File 'lib/daddy/formatter/html.rb', line 149
def after_background(background)
@in_background = nil
@builder << '</div>'
end
|
97
98
99
100
101
|
# File 'lib/daddy/formatter/html.rb', line 97
def ()
unless ()
@builder << '</pre>'
end
end
|
#after_examples(examples) ⇒ Object
213
214
215
|
# File 'lib/daddy/formatter/html.rb', line 213
def after_examples(examples)
@builder << '</div>'
end
|
#after_feature(feature) ⇒ Object
87
88
89
|
# File 'lib/daddy/formatter/html.rb', line 87
def after_feature(feature)
@builder << '</div>'
end
|
#after_feature_element(feature_element) ⇒ Object
172
173
174
175
|
# File 'lib/daddy/formatter/html.rb', line 172
def after_feature_element(feature_element)
@builder << '</div>'
@open_step_list = true
end
|
#after_features(features) ⇒ Object
62
63
64
65
66
67
68
|
# File 'lib/daddy/formatter/html.rb', line 62
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/daddy/formatter/html.rb', line 328
def after_multiline_arg(multiline_arg)
return if @hide_this_step || @skip_step
if ::Cucumber::Ast::Table === multiline_arg
@builder << '</table>'
end
end
|
#after_outline_table(outline_table) ⇒ Object
203
204
205
206
207
|
# File 'lib/daddy/formatter/html.rb', line 203
def after_outline_table(outline_table)
@builder << '</table>'
@outline_row = nil
@inside_outline = false
end
|
#after_step(step) ⇒ Object
238
239
240
|
# File 'lib/daddy/formatter/html.rb', line 238
def after_step(step)
move_progress
end
|
#after_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background, file_colon_line) ⇒ Object
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
300
|
# File 'lib/daddy/formatter/html.rb', line 267
def after_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background, file_colon_line)
return if @hide_this_step
if status == :undefined
keyword = @step.actual_keyword if @step.respond_to?(:actual_keyword)
step_multiline_class = @step.multiline_arg ? @step.multiline_arg.class : nil
@builder.pre do |pre|
pre << @runtime.snippet_text(keyword,step_match.instance_variable_get("@name") || '',step_multiline_class)
end
end
@builder << '</li>'
unless status == :undefined
step_file = step_match.file_colon_line
step_contents = "<div class=\"step_contents\"><pre>"
step_file.gsub(/^([^:]*\.rb):(\d*)/) do
line_index = $2.to_i - 1
file = $1.force_encoding('UTF-8')
if file.start_with?('daddy-') or file.start_with?('/daddy-')
file = '/usr/local/lib/ruby/gems/2.0.0/gems/' + file
end
File.readlines(File.expand_path(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.force_encoding('UTF-8')
end
print_messages
end
|
#after_steps(steps) ⇒ Object
229
230
231
|
# File 'lib/daddy/formatter/html.rb', line 229
def after_steps(steps)
@builder << '</ol>'
end
|
#after_table_row(table_row) ⇒ Object
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
|
# File 'lib/daddy/formatter/html.rb', line 350
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
move_progress
end
|
110
111
112
|
# File 'lib/daddy/formatter/html.rb', line 110
def after_tags(tags)
@tag_spacer = nil
end
|
#background_name(keyword, name, file_colon_line, source_indent) ⇒ Object
154
155
156
157
158
159
160
161
|
# File 'lib/daddy/formatter/html.rb', line 154
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
144
145
146
147
|
# File 'lib/daddy/formatter/html.rb', line 144
def before_background(background)
@in_background = true
@builder << '<div class="background">'
end
|
91
92
93
94
95
|
# File 'lib/daddy/formatter/html.rb', line 91
def ()
unless ()
@builder << '<pre class="comment">'
end
end
|
#before_examples(examples) ⇒ Object
209
210
211
|
# File 'lib/daddy/formatter/html.rb', line 209
def before_examples(examples)
@builder << '<div class="examples">'
end
|
#before_feature(feature) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/daddy/formatter/html.rb', line 70
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
163
164
165
166
167
168
169
170
|
# File 'lib/daddy/formatter/html.rb', line 163
def before_feature_element(feature_element)
@scenario_red = false
css_class = {
::Cucumber::Ast::Scenario => 'scenario',
::Cucumber::Ast::ScenarioOutline => 'scenario outline'
}[feature_element.class]
@builder << "<div class='#{css_class}'>"
end
|
#before_features(features) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/daddy/formatter/html.rb', line 30
def before_features(features)
@step_count = features.step_count
@builder.declare!(:DOCTYPE, :html)
@builder << '<html>'
@builder.head do
@builder.meta('http-equiv' => 'Content-Type', :content => 'text/html;charset=utf-8')
@builder.title title
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(title)
end
@builder.div(:id => 'summary') do
@builder.p('',:id => 'totals')
@builder.p('',:id => 'duration')
@builder.div(:id => 'expand-collapse') do
@builder.p('すべて開く', :id => 'expander')
@builder.p('すべて閉じる', :id => 'collapser')
end
end
end
end
|
#before_multiline_arg(multiline_arg) ⇒ Object
321
322
323
324
325
326
|
# File 'lib/daddy/formatter/html.rb', line 321
def before_multiline_arg(multiline_arg)
return if @hide_this_step || @skip_step
if ::Cucumber::Ast::Table === multiline_arg
@builder << '<table>'
end
end
|
#before_outline_table(outline_table) ⇒ Object
197
198
199
200
201
|
# File 'lib/daddy/formatter/html.rb', line 197
def before_outline_table(outline_table)
@inside_outline = true
@outline_row = 0
@builder << '<table>'
end
|
#before_step(step) ⇒ Object
233
234
235
236
|
# File 'lib/daddy/formatter/html.rb', line 233
def before_step(step)
@step_number += 1
@step = step
end
|
#before_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background, file_colon_line) ⇒ Object
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
|
# File 'lib/daddy/formatter/html.rb', line 242
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 class='step #{status} expand'>"
else
@builder << "<li class='step #{status}'>"
end
end
|
#before_steps(steps) ⇒ Object
225
226
227
|
# File 'lib/daddy/formatter/html.rb', line 225
def before_steps(steps)
@builder << '<ol style="display: none;">'
end
|
#before_table_row(table_row) ⇒ Object
343
344
345
346
347
348
|
# File 'lib/daddy/formatter/html.rb', line 343
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
|
103
104
105
106
107
108
|
# File 'lib/daddy/formatter/html.rb', line 103
def ()
unless ()
@builder.text!()
@builder.br
end
end
|
#doc_string(string) ⇒ Object
335
336
337
338
339
340
|
# File 'lib/daddy/formatter/html.rb', line 335
def doc_string(string)
return if @hide_this_step
@builder.pre(:class => 'val') do |pre|
@builder << string
end
end
|
#empty_messages ⇒ Object
407
408
409
|
# File 'lib/daddy/formatter/html.rb', line 407
def empty_messages
@delayed_messages = []
end
|
#examples_name(keyword, name) ⇒ Object
217
218
219
220
221
222
223
|
# File 'lib/daddy/formatter/html.rb', line 217
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
311
312
313
314
|
# File 'lib/daddy/formatter/html.rb', line 311
def exception(exception, status)
return if @hide_this_step
build_exception_detail(exception)
end
|
316
317
318
319
|
# File 'lib/daddy/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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
# File 'lib/daddy/formatter/html.rb', line 120
def feature_name(keyword, name)
title = feature_dir(@feature, true) + @feature.file.split('/').last.gsub(/\.feature/, '')
lines = name.split(/\r?\n/)
@builder.h2 do |h2|
@builder.span(:class => 'val') do
@builder << title
if Daddy.config.use_feature_name?
subtitle = lines.first.to_s.strip
unless subtitle.blank?
@builder.span('(' + subtitle + ')', :class => 'feature_subtitle')
end
end
end
end
if lines.size > 1
@builder.div(:class => 'narrative') do
@builder << lines[1..-1].join("\n")
end
end
end
|
#print_messages ⇒ Object
391
392
393
394
395
396
397
398
399
400
401
402
|
# File 'lib/daddy/formatter/html.rb', line 391
def print_messages
return if @delayed_messages.empty?
@delayed_messages.each_with_index do |ann, i|
@builder.li(:class => 'message', :style => 'display: none;') do
@builder << ann
end
end
empty_messages
end
|
#print_table_row_messages ⇒ Object
404
405
|
# File 'lib/daddy/formatter/html.rb', line 404
def print_table_row_messages
end
|
#puts(message) ⇒ Object
386
387
388
389
|
# File 'lib/daddy/formatter/html.rb', line 386
def puts(message)
@delayed_messages << message
end
|
#scenario_name(keyword, name, file_colon_line, source_indent) ⇒ Object
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
# File 'lib/daddy/formatter/html.rb', line 177
def scenario_name(keyword, name, file_colon_line, source_indent)
@step_number_in_scenario = 0
@builder.span(:class => 'scenario_file', :style => 'display: none;') do
@builder << file_colon_line
end
@listing_background = false
lines = name.split("\n")
@builder.h3 do
@builder.span(lines[0], :class => 'val')
end
if lines.size > 1
@builder.div(:class => 'narrative', :style => 'display: none;') do
@builder << lines[1..-1].join("\n")
end
end
end
|
#step_name(keyword, step_match, status, source_indent, background, file_colon_line) ⇒ Object
302
303
304
305
306
307
308
309
|
# File 'lib/daddy/formatter/html.rb', line 302
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
375
376
377
378
379
380
381
382
383
384
|
# File 'lib/daddy/formatter/html.rb', line 375
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
114
115
116
117
118
|
# File 'lib/daddy/formatter/html.rb', line 114
def tag_name(tag_name)
@builder.text!(@tag_spacer) if @tag_spacer
@tag_spacer = ' '
@builder.span(tag_name, :class => 'tag')
end
|