Class: Cucumber::Formatter::Pretty
Overview
The formatter used for --format pretty
(the default formatter).
This formatter prints features to plain text - exactly how they were parsed, just prettier. That means with proper indentation and alignment of table columns.
If the output is STDOUT (and not a file), there are bright colours to watch too.
Constant Summary
Constants included
from ANSIColor
ANSIColor::ALIASES
Term::ANSIColor::ATTRIBUTES, Term::ANSIColor::ATTRIBUTE_NAMES, Term::ANSIColor::COLORED_REGEXP
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#after_background(_background) ⇒ Object
-
#after_feature_element(_feature_element) ⇒ Object
-
#after_features(features) ⇒ Object
-
#after_multiline_arg(_multiline_arg) ⇒ Object
-
#after_outline_table(_outline_table) ⇒ Object
-
#after_table_cell(_cell) ⇒ Object
-
#after_table_row(table_row) ⇒ Object
-
#after_tags(_tags) ⇒ Object
-
#after_test_step(test_step, result) ⇒ Object
-
#background_name(keyword, name, file_colon_line, source_indent) ⇒ Object
-
#before_background(_background) ⇒ Object
-
#before_examples_array(_examples_array) ⇒ 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_table_row(_table_row) ⇒ Object
-
#before_test_case(_test_case) ⇒ Object
-
#comment_line(comment_line) ⇒ Object
-
#doc_string(string) ⇒ Object
-
#examples_name(keyword, name) ⇒ Object
-
#exception(exception, status) ⇒ Object
-
#feature_name(keyword, name) ⇒ Object
-
#initialize(runtime, path_or_io, options) ⇒ Pretty
constructor
A new instance of Pretty.
-
#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
#escape_cell
Methods included from Io
ensure_dir, ensure_file, ensure_io
Methods included from Console
#collect_snippet_data, #do_print_passing_wip, #do_print_profile_information, #do_print_snippets, #embed, #empty_messages, #exception_message_string, #format_step, #format_string, #linebreaks, #print_element_messages, #print_elements, #print_exception, #print_message, #print_messages, #print_passing_wip, #print_profile_information, #print_snippets, #print_statistics, #print_steps, #print_table_row_messages, #puts
Methods included from ANSIColor
#cukes, define_grey, define_real_grey, #green_cukes, #red_cukes, #yellow_cukes
attributes, coloring=, coloring?, included, #uncolored
Methods included from Duration
#format_duration
Constructor Details
#initialize(runtime, path_or_io, options) ⇒ Pretty
Returns a new instance of Pretty.
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/cucumber/formatter/pretty.rb', line 27
def initialize(runtime, path_or_io, options)
@runtime, @io, @options = runtime, ensure_io(path_or_io), options
@config = runtime.configuration
@exceptions = []
@indent = 0
@prefixes = options[:prefixes] || {}
@delayed_messages = []
@previous_step_keyword = nil
@snippets_input = []
@counts = ConsoleCounts.new(runtime.configuration)
@issues = ConsoleIssues.new(runtime.configuration)
end
|
Instance Attribute Details
#indent=(value) ⇒ Object
Sets the attribute indent
24
25
26
|
# File 'lib/cucumber/formatter/pretty.rb', line 24
def indent=(value)
@indent = value
end
|
#runtime ⇒ Object
Returns the value of attribute runtime.
25
26
27
|
# File 'lib/cucumber/formatter/pretty.rb', line 25
def runtime
@runtime
end
|
Instance Method Details
#after_background(_background) ⇒ Object
95
96
97
98
99
100
|
# File 'lib/cucumber/formatter/pretty.rb', line 95
def after_background(_background)
print_messages
@in_background = nil
@io.puts
@io.flush
end
|
#after_feature_element(_feature_element) ⇒ Object
83
84
85
86
87
|
# File 'lib/cucumber/formatter/pretty.rb', line 83
def after_feature_element(_feature_element)
print_messages
@io.puts
@io.flush
end
|
#after_features(features) ⇒ Object
44
45
46
|
# File 'lib/cucumber/formatter/pretty.rb', line 44
def after_features(features)
print_summary(features)
end
|
#after_multiline_arg(_multiline_arg) ⇒ Object
184
185
186
|
# File 'lib/cucumber/formatter/pretty.rb', line 184
def after_multiline_arg(_multiline_arg)
@table = nil
end
|
#after_outline_table(_outline_table) ⇒ Object
125
126
127
128
|
# File 'lib/cucumber/formatter/pretty.rb', line 125
def after_outline_table(_outline_table)
@table = nil
@indent = 4
end
|
#after_table_cell(_cell) ⇒ Object
203
204
205
206
|
# File 'lib/cucumber/formatter/pretty.rb', line 203
def after_table_cell(_cell)
return unless @table
@col_index += 1
end
|
#after_table_row(table_row) ⇒ Object
194
195
196
197
198
199
200
201
|
# File 'lib/cucumber/formatter/pretty.rb', line 194
def after_table_row(table_row)
return if !@table || @hide_this_step
print_table_row_messages
@io.puts
if table_row.exception && !@exceptions.include?(table_row.exception)
print_exception(table_row.exception, table_row.status, @indent)
end
end
|
58
59
60
61
62
63
|
# File 'lib/cucumber/formatter/pretty.rb', line 58
def after_tags(_tags)
if @indent == 1
@io.puts
@io.flush
end
end
|
#after_test_step(test_step, result) ⇒ Object
223
224
225
|
# File 'lib/cucumber/formatter/pretty.rb', line 223
def after_test_step(test_step, result)
collect_snippet_data(test_step, result)
end
|
#background_name(keyword, name, file_colon_line, source_indent) ⇒ Object
102
103
104
|
# File 'lib/cucumber/formatter/pretty.rb', line 102
def background_name(keyword, name, file_colon_line, source_indent)
print_feature_element_name(keyword, name, file_colon_line, source_indent)
end
|
#before_background(_background) ⇒ Object
89
90
91
92
93
|
# File 'lib/cucumber/formatter/pretty.rb', line 89
def before_background(_background)
@indent = 2
@scenario_indent = 2
@in_background = true
end
|
#before_examples_array(_examples_array) ⇒ Object
106
107
108
109
110
|
# File 'lib/cucumber/formatter/pretty.rb', line 106
def before_examples_array(_examples_array)
@indent = 4
@io.puts
@visiting_first_example_name = true
end
|
#before_feature(_feature) ⇒ Object
48
49
50
51
|
# File 'lib/cucumber/formatter/pretty.rb', line 48
def before_feature(_feature)
@exceptions = []
@indent = 0
end
|
#before_feature_element(_feature_element) ⇒ Object
78
79
80
81
|
# File 'lib/cucumber/formatter/pretty.rb', line 78
def before_feature_element(_feature_element)
@indent = 2
@scenario_indent = 2
end
|
#before_features(_features) ⇒ Object
40
41
42
|
# File 'lib/cucumber/formatter/pretty.rb', line 40
def before_features(_features)
print_profile_information
end
|
#before_multiline_arg(multiline_arg) ⇒ Object
179
180
181
182
|
# File 'lib/cucumber/formatter/pretty.rb', line 179
def before_multiline_arg(multiline_arg)
return if @options[:no_multiline] || @hide_this_step
@table = multiline_arg
end
|
#before_outline_table(outline_table) ⇒ Object
121
122
123
|
# File 'lib/cucumber/formatter/pretty.rb', line 121
def before_outline_table(outline_table)
@table = outline_table
end
|
#before_step(step) ⇒ Object
134
135
136
137
138
|
# File 'lib/cucumber/formatter/pretty.rb', line 134
def before_step(step)
@current_step = step
@indent = 6
print_messages
end
|
#before_step_result(_keyword, _step_match, _multiline_arg, status, exception, _source_indent, background, _file_colon_line) ⇒ Object
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
# File 'lib/cucumber/formatter/pretty.rb', line 140
def before_step_result(_keyword, _step_match, _multiline_arg, status, exception, _source_indent, background, _file_colon_line)
@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
end
|
#before_table_row(_table_row) ⇒ Object
188
189
190
191
192
|
# File 'lib/cucumber/formatter/pretty.rb', line 188
def before_table_row(_table_row)
return if !@table || @hide_this_step
@col_index = 0
@io.print ' |'.indent(@indent - 2)
end
|
#before_test_case(_test_case) ⇒ Object
219
220
221
|
# File 'lib/cucumber/formatter/pretty.rb', line 219
def before_test_case(_test_case)
@previous_step_keyword = nil
end
|
53
54
55
56
|
# File 'lib/cucumber/formatter/pretty.rb', line 53
def ()
@io.puts(.indent(@indent))
@io.flush
end
|
#doc_string(string) ⇒ Object
164
165
166
167
168
169
170
|
# File 'lib/cucumber/formatter/pretty.rb', line 164
def doc_string(string)
return if @options[:no_multiline] || @hide_this_step
s = %{"""\n#{string}\n"""}.indent(@indent)
s = s.split("\n").map { |l| l =~ /^\s+$/ ? '' : l }.join("\n")
@io.puts(format_string(s, @current_step.status))
@io.flush
end
|
#examples_name(keyword, name) ⇒ Object
112
113
114
115
116
117
118
119
|
# File 'lib/cucumber/formatter/pretty.rb', line 112
def examples_name(keyword, name)
@io.puts unless @visiting_first_example_name
@visiting_first_example_name = false
@io.puts(" #{keyword}: #{name}")
@io.flush
@indent = 6
@scenario_indent = 6
end
|
#exception(exception, status) ⇒ Object
172
173
174
175
176
177
|
# File 'lib/cucumber/formatter/pretty.rb', line 172
def exception(exception, status)
return if @hide_this_step
print_messages
print_exception(exception, status, @indent)
@io.flush
end
|
#feature_name(keyword, name) ⇒ Object
72
73
74
75
76
|
# File 'lib/cucumber/formatter/pretty.rb', line 72
def feature_name(keyword, name)
@io.puts("#{keyword}: #{name}")
@io.puts
@io.flush
end
|
#scenario_name(keyword, name, file_colon_line, source_indent) ⇒ Object
130
131
132
|
# File 'lib/cucumber/formatter/pretty.rb', line 130
def scenario_name(keyword, name, file_colon_line, source_indent)
print_feature_element_name(keyword, name, file_colon_line, source_indent)
end
|
#step_name(keyword, step_match, status, source_indent, _background, _file_colon_line) ⇒ Object
156
157
158
159
160
161
162
|
# File 'lib/cucumber/formatter/pretty.rb', line 156
def step_name(keyword, step_match, status, source_indent, _background, _file_colon_line)
return if @hide_this_step
source_indent = nil unless @options[:source]
name_to_report = format_step(keyword, step_match, status, source_indent)
@io.puts(name_to_report.indent(@scenario_indent + 2))
print_messages
end
|
#table_cell_value(value, status) ⇒ Object
208
209
210
211
212
213
214
215
216
217
|
# File 'lib/cucumber/formatter/pretty.rb', line 208
def table_cell_value(value, status)
return if !@table || @hide_this_step
status ||= @status || :passed
width = @table.col_width(@col_index)
cell_text = escape_cell(value.to_s || '')
padded = cell_text + (' ' * (width - cell_text.unpack('U*').length))
prefix = cell_prefix(status)
@io.print(' ' + format_string("#{prefix}#{padded}", status) + ::Cucumber::Term::ANSIColor.reset(' |'))
@io.flush
end
|
#tag_name(tag_name) ⇒ Object
65
66
67
68
69
70
|
# File 'lib/cucumber/formatter/pretty.rb', line 65
def tag_name(tag_name)
tag = format_string(tag_name, :tag).indent(@indent)
@io.print(tag)
@io.flush
@indent = 1
end
|