Class: Cucumber::Formatter::Usage
Defined Under Namespace
Classes: StepDefKey
Constant Summary
Constants included
from Console
Console::FORMATS
Constants included
from ANSIColor
ANSIColor::ALIASES
Instance Attribute Summary
Attributes inherited from Progress
#step_mother
Instance Method Summary
collapse
-
#add_unused_stepdefs ⇒ Object
-
#after_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background) ⇒ Object
-
#aggregate_info ⇒ Object
-
#before_step(step) ⇒ Object
-
#before_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background) ⇒ Object
-
#initialize(step_mother, io, options) ⇒ Usage
constructor
-
#max_length ⇒ Object
-
#max_step_length ⇒ Object
-
#max_stepdef_length ⇒ Object
-
#print_step_definition(stepdef_key) ⇒ Object
-
#print_steps(stepdef_key) ⇒ Object
-
#print_summary(features) ⇒ Object
Methods included from Console
#announce, #format_step, #format_string, #print_counts, #print_elements, #print_exception, #print_passing_wip, #print_snippets, #print_stats, #print_tag_limit_warnings, #record_tag_occurrences
Methods included from ANSIColor
define_grey, define_real_grey, #grey
Methods included from Duration
#format_duration
Methods inherited from Progress
#after_features, #after_outline_table, #before_feature_element, #before_outline_table, #table_cell_value
Constructor Details
#initialize(step_mother, io, options) ⇒ Usage
Returns a new instance of Usage.
25
26
27
28
29
30
|
# File 'lib/cucumber/formatter/usage.rb', line 25
def initialize(step_mother, io, options)
@step_mother = step_mother
@io = io
@options = options
@stepdef_to_match = Hash.new{|h,stepdef_key| h[stepdef_key] = []}
end
|
Instance Method Details
#add_unused_stepdefs ⇒ Object
131
132
133
134
135
136
|
# File 'lib/cucumber/formatter/usage.rb', line 131
def add_unused_stepdefs
@step_mother.unmatched_step_definitions.each do |step_definition|
stepdef_key = StepDefKey.new(step_definition.regexp_source, step_definition.file_colon_line)
@stepdef_to_match[stepdef_key] = []
end
end
|
#after_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/cucumber/formatter/usage.rb', line 40
def after_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background)
duration = Time.now - @step_duration
if step_match.name.nil? stepdef_key = StepDefKey.new(step_match.step_definition.regexp_source, step_match.step_definition.file_colon_line)
@stepdef_to_match[stepdef_key] << {
:keyword => keyword,
:step_match => step_match,
:status => status,
:file_colon_line => @step.file_colon_line,
:duration => duration
}
end
super
end
|
#aggregate_info ⇒ Object
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/cucumber/formatter/usage.rb', line 118
def aggregate_info
@stepdef_to_match.each do |key, steps|
if steps.empty?
key.status = :skipped
key.mean_duration = 0
else
key.status = Ast::StepInvocation.worst_status(steps.map{|step| step[:status]})
total_duration = steps.inject(0) {|sum, step| step[:duration] + sum}
key.mean_duration = total_duration / steps.length
end
end
end
|
#before_step(step) ⇒ Object
32
33
34
|
# File 'lib/cucumber/formatter/usage.rb', line 32
def before_step(step)
@step = step
end
|
#before_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background) ⇒ Object
36
37
38
|
# File 'lib/cucumber/formatter/usage.rb', line 36
def before_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background)
@step_duration = Time.now
end
|
#max_length ⇒ Object
104
105
106
|
# File 'lib/cucumber/formatter/usage.rb', line 104
def max_length
[max_stepdef_length, max_step_length].compact.max
end
|
#max_step_length ⇒ Object
112
113
114
115
116
|
# File 'lib/cucumber/formatter/usage.rb', line 112
def max_step_length
@stepdef_to_match.values.flatten.map do |step|
step[:keyword].jlength + step[:step_match].format_args.jlength
end.max
end
|
#max_stepdef_length ⇒ Object
108
109
110
|
# File 'lib/cucumber/formatter/usage.rb', line 108
def max_stepdef_length
@stepdef_to_match.keys.flatten.map{|key| key.regexp_source.jlength}.max
end
|
#print_step_definition(stepdef_key) ⇒ Object
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/cucumber/formatter/usage.rb', line 79
def print_step_definition(stepdef_key)
@io.print format_string(sprintf("%.7f", stepdef_key.mean_duration), :skipped) + " " unless @options[:dry_run]
@io.print format_string(stepdef_key.regexp_source, stepdef_key.status)
if @options[:source]
indent = max_length - stepdef_key.regexp_source.jlength
= " # #{stepdef_key.file_colon_line}".indent(indent)
@io.print(format_string(, :comment))
end
@io.puts
end
|
#print_steps(stepdef_key) ⇒ Object
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/cucumber/formatter/usage.rb', line 90
def print_steps(stepdef_key)
@stepdef_to_match[stepdef_key].each do |step|
@io.print " "
@io.print format_string(sprintf("%.7f", step[:duration]), :skipped) + " " unless @options[:dry_run]
@io.print format_step(step[:keyword], step[:step_match], step[:status], nil)
if @options[:source]
indent = max_length - (step[:keyword].jlength + step[:step_match].format_args.jlength)
= " # #{step[:file_colon_line]}".indent(indent)
@io.print(format_string(, :comment))
end
@io.puts
end
end
|
#print_summary(features) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/cucumber/formatter/usage.rb', line 56
def print_summary(features)
add_unused_stepdefs
aggregate_info
if @options[:dry_run]
keys = @stepdef_to_match.keys.sort {|a,b| a.regexp_source <=> b.regexp_source}
else
keys = @stepdef_to_match.keys.sort {|a,b| a.mean_duration <=> b.mean_duration}.reverse
end
keys.each do |stepdef_key|
print_step_definition(stepdef_key)
if @stepdef_to_match[stepdef_key].any?
print_steps(stepdef_key)
else
@io.puts(" " + format_string("NOT MATCHED BY ANY STEPS", :failed))
end
end
@io.puts
super
end
|