Module: Cucumber::Formatter::Console
Overview
This module contains helper methods that are used by formatters that print output to the terminal.
Constant Summary
collapse
- FORMATS =
Hash.new{|hash, format| hash[format] = method(format).to_proc}
Constants included
from ANSIColor
ANSIColor::ALIASES
Instance Method Summary
collapse
-
#announce(announcement) ⇒ Object
define @delayed_announcements = [] in your Formatter if you want to activate this feature.
-
#embed(file, mime_type) ⇒ Object
-
#empty_announcements ⇒ Object
-
#format_step(keyword, step_match, status, source_indent) ⇒ Object
-
#format_string(string, status) ⇒ Object
-
#print_announcement(announcement) ⇒ Object
-
#print_announcements ⇒ Object
-
#print_counts ⇒ Object
-
#print_elements(elements, status, kind) ⇒ Object
-
#print_exception(e, status, indent) ⇒ Object
-
#print_passing_wip(options) ⇒ Object
-
#print_snippets(options) ⇒ Object
-
#print_stats(features, profiles = []) ⇒ Object
-
#print_steps(status) ⇒ Object
-
#print_table_row_announcements ⇒ Object
-
#print_tag_limit_warnings(features) ⇒ Object
Methods included from ANSIColor
cukes, define_grey, define_real_grey, green_cukes, grey, red_cukes, yellow_cukes
Methods included from Summary
#scenario_summary, #step_summary
Methods included from Duration
#format_duration
Instance Method Details
#announce(announcement) ⇒ Object
define @delayed_announcements = [] in your Formatter if you want to activate this feature
144
145
146
147
148
149
150
151
152
|
# File 'lib/cucumber/formatter/console.rb', line 144
def announce(announcement)
if @delayed_announcements
@delayed_announcements << announcement
else
@io.puts
@io.puts(format_string(announcement, :tag))
@io.flush
end
end
|
#embed(file, mime_type) ⇒ Object
138
139
140
|
# File 'lib/cucumber/formatter/console.rb', line 138
def embed(file, mime_type)
end
|
#empty_announcements ⇒ Object
171
172
173
|
# File 'lib/cucumber/formatter/console.rb', line 171
def empty_announcements
@delayed_announcements = []
end
|
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/cucumber/formatter/console.rb', line 16
def format_step(keyword, step_match, status, source_indent)
= if source_indent
c = (' # ' + step_match.file_colon_line).indent(source_indent)
format_string(c, :comment)
else
''
end
format = format_for(status, :param)
line = keyword + " " + step_match.format_args(format) +
format_string(line, status)
end
|
29
30
31
32
33
34
35
36
|
# File 'lib/cucumber/formatter/console.rb', line 29
def format_string(string, status)
fmt = format_for(status)
if Proc === fmt
fmt.call(string)
else
fmt % string
end
end
|
#print_announcement(announcement) ⇒ Object
166
167
168
169
|
# File 'lib/cucumber/formatter/console.rb', line 166
def print_announcement(announcement)
@io.puts(format_string(announcement, :tag).indent(@indent))
@io.flush
end
|
#print_announcements ⇒ Object
154
155
156
157
|
# File 'lib/cucumber/formatter/console.rb', line 154
def print_announcements()
@delayed_announcements.each {|ann| print_announcement(ann)}
empty_announcements
end
|
#print_counts ⇒ Object
60
61
62
63
|
# File 'lib/cucumber/formatter/console.rb', line 60
def print_counts
STDERR.puts("The #print_counts method is deprecated and will be removed in 0.4. Use #print_stats instead")
print_stats(nil)
end
|
#print_elements(elements, status, kind) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/cucumber/formatter/console.rb', line 42
def print_elements(elements, status, kind)
if elements.any?
@io.puts(format_string("(::) #{status} #{kind} (::)", status))
@io.puts
@io.flush
end
elements.each_with_index do |element, i|
if status == :failed
print_exception(element.exception, status, 0)
else
@io.puts(format_string(element.backtrace_line, status))
end
@io.puts
@io.flush
end
end
|
#print_exception(e, status, indent) ⇒ Object
86
87
88
|
# File 'lib/cucumber/formatter/console.rb', line 86
def print_exception(e, status, indent)
@io.puts(format_string("#{e.message} (#{e.class})\n#{e.backtrace.join("\n")}".indent(indent), status))
end
|
#print_passing_wip(options) ⇒ Object
116
117
118
119
120
121
122
123
124
125
|
# File 'lib/cucumber/formatter/console.rb', line 116
def print_passing_wip(options)
return unless options[:wip]
passed = step_mother.scenarios(:passed)
if passed.any?
@io.puts format_string("\nThe --wip switch was used, so I didn't expect anything to pass. These scenarios passed:", :failed)
print_elements(passed, :passed, "scenarios")
else
@io.puts format_string("\nThe --wip switch was used, so the failures were expected. All is good.\n", :passed)
end
end
|
#print_snippets(options) ⇒ Object
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
# File 'lib/cucumber/formatter/console.rb', line 90
def print_snippets(options)
return unless options[:snippets]
undefined = step_mother.steps(:undefined)
return if undefined.empty?
unknown_programming_language = step_mother.unknown_programming_language?
snippets = undefined.map do |step|
step_name = Undefined === step.exception ? step.exception.step_name : step.name
step_multiline_class = step.multiline_arg ? step.multiline_arg.class : nil
snippet = @step_mother.snippet_text(step.actual_keyword, step_name, step_multiline_class)
snippet
end.compact.uniq
text = "\nYou can implement step definitions for undefined steps with these snippets:\n\n"
text += snippets.join("\n\n")
@io.puts format_string(text, :undefined)
if unknown_programming_language
@io.puts format_string("\nIf you want snippets in a different programming language, just make sure a file\n" +
"with the appropriate file extension exists where cucumber looks for step definitions.", :failed)
end
@io.puts
@io.flush
end
|
#print_stats(features, profiles = []) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/cucumber/formatter/console.rb', line 65
def print_stats(features, profiles = [])
@failures = step_mother.scenarios(:failed).select { |s| s.is_a?(Cucumber::Ast::Scenario) }
if !@failures.empty?
@io.puts format_string("Failing Scenarios:", :failed)
@failures.each do |failure|
profiles_string = (profiles.map{|profile| "-p #{profile} " }).flatten unless profiles.empty?
@io.puts format_string("cucumber #{profiles_string}" + failure.file_colon_line, :failed) +
format_string(" # Scenario: " + failure.name, :comment)
end
@io.puts
end
@io.puts scenario_summary(step_mother) {|status_count, status| format_string(status_count, status)}
@io.puts step_summary(step_mother) {|status_count, status| format_string(status_count, status)}
@io.puts(format_duration(features.duration)) if features && features.duration
@io.flush
end
|
#print_steps(status) ⇒ Object
38
39
40
|
# File 'lib/cucumber/formatter/console.rb', line 38
def print_steps(status)
print_elements(step_mother.steps(status), status, 'steps')
end
|
#print_table_row_announcements ⇒ Object
159
160
161
162
163
164
|
# File 'lib/cucumber/formatter/console.rb', line 159
def print_table_row_announcements
return if @delayed_announcements.empty?
@io.print(format_string(@delayed_announcements.join(', '), :tag).indent(2))
@io.flush
empty_announcements
end
|
#print_tag_limit_warnings(features) ⇒ Object
127
128
129
130
131
132
133
134
135
136
|
# File 'lib/cucumber/formatter/console.rb', line 127
def print_tag_limit_warnings(features)
first_tag = true
@options[:tag_excess].each do |tag_name, tag_limit, tag_locations|
@io.puts if first_tag
first_tag = false
@io.puts format_string("#{tag_name} occurred #{tag_locations.length} times, but the limit was set to #{tag_limit}", :failed)
tag_locations.each {|tag_location| @io.puts format_string(" #{tag_location.file_colon_line}", :failed)}
@io.flush
end
end
|