Class: Cucumber::Formatter::Pretty
Overview
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 Console
Console::FORMATS
Constants included
from ANSIColor
ANSIColor::ALIASES
Instance Attribute Summary collapse
Attributes inherited from Ast::Visitor
#options, #step_mother
Instance Method Summary
collapse
-
#initialize(step_mother, io, options) ⇒ Pretty
constructor
A new instance of Pretty.
-
#visit_background(background) ⇒ Object
-
#visit_background_name(keyword, name, file_colon_line, source_indent) ⇒ Object
-
#visit_comment(comment) ⇒ Object
-
#visit_comment_line(comment_line) ⇒ Object
-
#visit_examples_name(keyword, name) ⇒ Object
-
#visit_exception(exception, status) ⇒ Object
-
#visit_feature(feature) ⇒ Object
-
#visit_feature_element(feature_element) ⇒ Object
-
#visit_feature_element_name(keyword, name, file_colon_line, source_indent) ⇒ Object
-
#visit_feature_name(name) ⇒ Object
-
#visit_features(features) ⇒ Object
-
#visit_multiline_arg(multiline_arg) ⇒ Object
-
#visit_py_string(string) ⇒ Object
-
#visit_scenario_name(keyword, name, file_colon_line, source_indent) ⇒ Object
-
#visit_step(step) ⇒ Object
-
#visit_step_name(keyword, step_match, status, source_indent, background) ⇒ Object
-
#visit_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background) ⇒ Object
-
#visit_table_cell(cell) ⇒ Object
-
#visit_table_cell_value(value, status) ⇒ Object
-
#visit_table_row(table_row) ⇒ Object
-
#visit_tag_name(tag_name) ⇒ Object
-
#visit_tags(tags) ⇒ Object
Methods included from Console
#announce, #format_step, #format_string, #print_counts, #print_elements, #print_exception, #print_passing_wip, #print_snippets, #print_stats, #print_steps, #print_tag_limit_warnings, #record_tag_occurrences
Methods included from ANSIColor
define_grey, define_real_grey, #grey
Methods included from Duration
#format_duration
#announce, #matches_scenario_names?, #visit_examples, #visit_examples_array, #visit_outline_table, #visit_steps
Constructor Details
#initialize(step_mother, io, options) ⇒ Pretty
Returns a new instance of Pretty.
16
17
18
19
20
21
22
23
|
# File 'lib/cucumber/formatter/pretty.rb', line 16
def initialize(step_mother, io, options)
super(step_mother)
@io = io
@options = options
@exceptions = []
@indent = 0
@prefixes = options[:prefixes] || {}
end
|
Instance Attribute Details
#indent=(value) ⇒ Object
Sets the attribute indent
14
15
16
|
# File 'lib/cucumber/formatter/pretty.rb', line 14
def indent=(value)
@indent = value
end
|
Instance Method Details
#visit_background(background) ⇒ Object
85
86
87
88
89
90
91
92
93
|
# File 'lib/cucumber/formatter/pretty.rb', line 85
def visit_background(background)
@indent = 2
@scenario_indent = 2
@in_background = true
super
@in_background = nil
@io.puts
@io.flush
end
|
#visit_background_name(keyword, name, file_colon_line, source_indent) ⇒ Object
95
96
97
|
# File 'lib/cucumber/formatter/pretty.rb', line 95
def visit_background_name(keyword, name, file_colon_line, source_indent)
visit_feature_element_name(keyword, name, file_colon_line, source_indent)
end
|
46
47
48
|
# File 'lib/cucumber/formatter/pretty.rb', line 46
def ()
.accept(self)
end
|
50
51
52
53
|
# File 'lib/cucumber/formatter/pretty.rb', line 50
def ()
@io.puts(.indent(@indent))
@io.flush
end
|
#visit_examples_name(keyword, name) ⇒ Object
99
100
101
102
103
104
105
106
|
# File 'lib/cucumber/formatter/pretty.rb', line 99
def visit_examples_name(keyword, name)
names = name.empty? ? [name] : name.split("\n")
@io.puts("\n #{keyword} #{names[0]}")
names[1..-1].each {|s| @io.puts " #{s}" }
@io.flush
@indent = 6
@scenario_indent = 6
end
|
#visit_exception(exception, status) ⇒ Object
153
154
155
156
|
# File 'lib/cucumber/formatter/pretty.rb', line 153
def visit_exception(exception, status)
print_exception(exception, status, @indent)
@io.flush
end
|
#visit_feature(feature) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/cucumber/formatter/pretty.rb', line 30
def visit_feature(feature)
@exceptions = []
@indent = 0
if @options[:autoformat]
file = File.join(@options[:autoformat], feature.file)
dir = File.dirname(file)
mkdir_p(dir) unless File.directory?(dir)
File.open(file, Cucumber.file_mode('w')) do |io|
@io = io
super
end
else
super
end
end
|
#visit_feature_element(feature_element) ⇒ Object
76
77
78
79
80
81
82
83
|
# File 'lib/cucumber/formatter/pretty.rb', line 76
def visit_feature_element(feature_element)
record_tag_occurrences(feature_element, @options)
@indent = 2
@scenario_indent = 2
super
@io.puts
@io.flush
end
|
#visit_feature_element_name(keyword, name, file_colon_line, source_indent) ⇒ Object
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/cucumber/formatter/pretty.rb', line 112
def visit_feature_element_name(keyword, name, file_colon_line, source_indent)
@io.puts if @scenario_indent == 6
names = name.empty? ? [name] : name.split("\n")
line = "#{keyword} #{names[0]}".indent(@scenario_indent)
@io.print(line)
if @options[:source]
= " # #{file_colon_line}".indent(source_indent)
@io.print(format_string(, :comment))
end
@io.puts
names[1..-1].each {|s| @io.puts " #{s}"}
@io.flush
end
|
#visit_feature_name(name) ⇒ Object
70
71
72
73
74
|
# File 'lib/cucumber/formatter/pretty.rb', line 70
def visit_feature_name(name)
@io.puts(name)
@io.puts
@io.flush
end
|
#visit_features(features) ⇒ Object
25
26
27
28
|
# File 'lib/cucumber/formatter/pretty.rb', line 25
def visit_features(features)
super
print_summary(features) unless @options[:autoformat]
end
|
#visit_multiline_arg(multiline_arg) ⇒ Object
147
148
149
150
151
|
# File 'lib/cucumber/formatter/pretty.rb', line 147
def visit_multiline_arg(multiline_arg)
return if @options[:no_multiline]
@table = multiline_arg
super
end
|
#visit_py_string(string) ⇒ Object
168
169
170
171
172
173
|
# File 'lib/cucumber/formatter/pretty.rb', line 168
def visit_py_string(string)
s = %{"""\n#{string}\n"""}.indent(@indent)
s = s.split("\n").map{|l| l =~ /^\s+$/ ? '' : l}.join("\n")
@io.puts(format_string(s, @status))
@io.flush
end
|
#visit_scenario_name(keyword, name, file_colon_line, source_indent) ⇒ Object
108
109
110
|
# File 'lib/cucumber/formatter/pretty.rb', line 108
def visit_scenario_name(keyword, name, file_colon_line, source_indent)
visit_feature_element_name(keyword, name, file_colon_line, source_indent)
end
|
#visit_step(step) ⇒ Object
126
127
128
129
|
# File 'lib/cucumber/formatter/pretty.rb', line 126
def visit_step(step)
@indent = 6
super
end
|
#visit_step_name(keyword, step_match, status, source_indent, background) ⇒ Object
141
142
143
144
145
|
# File 'lib/cucumber/formatter/pretty.rb', line 141
def visit_step_name(keyword, step_match, status, source_indent, background)
source_indent = nil unless @options[:source]
formatted_step_name = format_step(keyword, step_match, status, source_indent)
@io.puts(formatted_step_name.indent(@scenario_indent + 2))
end
|
#visit_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background) ⇒ Object
131
132
133
134
135
136
137
138
139
|
# File 'lib/cucumber/formatter/pretty.rb', line 131
def visit_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background)
if exception
return if @exceptions.index(exception)
@exceptions << exception
end
return if status != :failed && @in_background ^ background
@status = status
super
end
|
#visit_table_cell(cell) ⇒ Object
175
176
177
178
|
# File 'lib/cucumber/formatter/pretty.rb', line 175
def visit_table_cell(cell)
super
@col_index += 1
end
|
#visit_table_cell_value(value, status) ⇒ Object
180
181
182
183
184
185
186
187
188
|
# File 'lib/cucumber/formatter/pretty.rb', line 180
def visit_table_cell_value(value, status)
status ||= @status || :passed
width = @table.col_width(@col_index)
cell_text = value.to_s || ''
padded = cell_text + (' ' * (width - cell_text.jlength))
prefix = cell_prefix(status)
@io.print(' ' + format_string("#{prefix}#{padded}", status) + ::Term::ANSIColor.reset(" |"))
@io.flush
end
|
#visit_table_row(table_row) ⇒ Object
158
159
160
161
162
163
164
165
166
|
# File 'lib/cucumber/formatter/pretty.rb', line 158
def visit_table_row(table_row)
@col_index = 0
@io.print ' |'.indent(@indent-2)
super
@io.puts
if table_row.exception && !@exceptions.index(table_row.exception)
print_exception(table_row.exception, :failed, @indent)
end
end
|
#visit_tag_name(tag_name) ⇒ Object
63
64
65
66
67
68
|
# File 'lib/cucumber/formatter/pretty.rb', line 63
def visit_tag_name(tag_name)
tag = format_string("@#{tag_name}", :tag).indent(@indent)
@io.print(tag)
@io.flush
@indent = 1
end
|
55
56
57
58
59
60
61
|
# File 'lib/cucumber/formatter/pretty.rb', line 55
def visit_tags(tags)
tags.accept(self)
if @indent == 1
@io.puts
@io.flush
end
end
|