Class: Cucumber::Formatter::Pretty

Inherits:
Object
  • Object
show all
Includes:
Console, Io, FileUtils, Gherkin::Formatter::Escaping
Defined in:
lib/cucumber/formatter/pretty.rb

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

Constant Summary

Constants included from ANSIColor

ANSIColor::ALIASES

Constants included from Term::ANSIColor

Term::ANSIColor::ATTRIBUTES, Term::ANSIColor::ATTRIBUTE_NAMES, Term::ANSIColor::COLORED_REGEXP

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from Io

#ensure_dir, #ensure_file, #ensure_io

Methods included from Console

#collect_failing_scenarios, #embed, #empty_messages, #format_step, #format_string, #linebreaks, #print_elements, #print_exception, #print_failing_scenarios, #print_message, #print_messages, #print_passing_wip, #print_profile_information, #print_snippets, #print_stats, #print_steps, #print_table_row_messages, #puts

Methods included from ANSIColor

#cukes, define_grey, define_real_grey, #green_cukes, #grey, #red_cukes, #yellow_cukes

Methods included from Term::ANSIColor

attributes, coloring=, coloring?, #uncolored

Methods included from Summary

#scenario_summary, #step_summary

Methods included from Duration

#format_duration

Constructor Details

- (Pretty) initialize(runtime, path_or_io, options)



23
24
25
26
27
28
29
# File 'lib/cucumber/formatter/pretty.rb', line 23

def initialize(runtime, path_or_io, options)
  @runtime, @io, @options = runtime, ensure_io(path_or_io, "pretty"), options
  @exceptions = []
  @indent = 0
  @prefixes = options[:prefixes] || {}
  @delayed_messages = []
end

Instance Attribute Details

- (Object) indent=(value) (writeonly)

Sets the attribute indent



20
21
22
# File 'lib/cucumber/formatter/pretty.rb', line 20

def indent=(value)
  @indent = value
end

- (Object) runtime (readonly)

Returns the value of attribute runtime



21
22
23
# File 'lib/cucumber/formatter/pretty.rb', line 21

def runtime
  @runtime
end

Instance Method Details

- (Object) after_background(background)



85
86
87
88
89
# File 'lib/cucumber/formatter/pretty.rb', line 85

def after_background(background)
  @in_background = nil
  @io.puts
  @io.flush
end

- (Object) after_feature_element(feature_element)



74
75
76
77
# File 'lib/cucumber/formatter/pretty.rb', line 74

def after_feature_element(feature_element)
  @io.puts
  @io.flush
end

- (Object) after_features(features)



35
36
37
# File 'lib/cucumber/formatter/pretty.rb', line 35

def after_features(features)
  print_summary(features)
end

- (Object) after_multiline_arg(multiline_arg)



173
174
175
# File 'lib/cucumber/formatter/pretty.rb', line 173

def after_multiline_arg(multiline_arg)
  @table = nil
end

- (Object) after_outline_table(outline_table)



116
117
118
119
# File 'lib/cucumber/formatter/pretty.rb', line 116

def after_outline_table(outline_table)
  @table = nil
  @indent = 4
end

- (Object) after_table_cell(cell)



192
193
194
195
# File 'lib/cucumber/formatter/pretty.rb', line 192

def after_table_cell(cell)
  return unless @table
  @col_index += 1
end

- (Object) after_table_row(table_row)



183
184
185
186
187
188
189
190
# File 'lib/cucumber/formatter/pretty.rb', line 183

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

- (Object) after_tags(tags)



49
50
51
52
53
54
# File 'lib/cucumber/formatter/pretty.rb', line 49

def after_tags(tags)
  if @indent == 1
    @io.puts
    @io.flush
  end
end

- (Object) background_name(keyword, name, file_colon_line, source_indent)



91
92
93
# File 'lib/cucumber/formatter/pretty.rb', line 91

def background_name(keyword, name, file_colon_line, source_indent)
  print_feature_element_name(keyword, name, file_colon_line, source_indent)
end

- (Object) before_background(background)



79
80
81
82
83
# File 'lib/cucumber/formatter/pretty.rb', line 79

def before_background(background)
  @indent = 2
  @scenario_indent = 2
  @in_background = true
end

- (Object) before_examples_array(examples_array)



95
96
97
98
99
# File 'lib/cucumber/formatter/pretty.rb', line 95

def before_examples_array(examples_array)
  @indent = 4
  @io.puts
  @visiting_first_example_name = true
end

- (Object) before_feature(feature)



39
40
41
42
# File 'lib/cucumber/formatter/pretty.rb', line 39

def before_feature(feature)
  @exceptions = []
  @indent = 0
end

- (Object) before_feature_element(feature_element)



69
70
71
72
# File 'lib/cucumber/formatter/pretty.rb', line 69

def before_feature_element(feature_element)
  @indent = 2
  @scenario_indent = 2
end

- (Object) before_features(features)



31
32
33
# File 'lib/cucumber/formatter/pretty.rb', line 31

def before_features(features)
  print_profile_information
end

- (Object) before_multiline_arg(multiline_arg)



168
169
170
171
# File 'lib/cucumber/formatter/pretty.rb', line 168

def before_multiline_arg(multiline_arg)
  return if @options[:no_multiline] || @hide_this_step
  @table = multiline_arg
end

- (Object) before_outline_table(outline_table)



112
113
114
# File 'lib/cucumber/formatter/pretty.rb', line 112

def before_outline_table(outline_table)
  @table = outline_table
end

- (Object) before_step(step)



125
126
127
128
# File 'lib/cucumber/formatter/pretty.rb', line 125

def before_step(step)
  @current_step = step
  @indent = 6
end

- (Object) before_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background, file_colon_line)



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/cucumber/formatter/pretty.rb', line 130

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

- (Object) before_table_row(table_row)



177
178
179
180
181
# File 'lib/cucumber/formatter/pretty.rb', line 177

def before_table_row(table_row)
  return if !@table || @hide_this_step
  @col_index = 0
  @io.print '  |'.indent(@indent-2)
end

- (Object) comment_line(comment_line)



44
45
46
47
# File 'lib/cucumber/formatter/pretty.rb', line 44

def comment_line(comment_line)
  @io.puts(comment_line.indent(@indent))
  @io.flush
end

- (Object) doc_string(string)



154
155
156
157
158
159
160
# File 'lib/cucumber/formatter/pretty.rb', line 154

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

- (Object) examples_name(keyword, name)



101
102
103
104
105
106
107
108
109
110
# File 'lib/cucumber/formatter/pretty.rb', line 101

def examples_name(keyword, name)
  @io.puts unless @visiting_first_example_name
  @visiting_first_example_name = false
  names = name.strip.empty? ? [name.strip] : name.split("\n")
  @io.puts("    #{keyword}: #{names[0]}")
  names[1..-1].each {|s| @io.puts "      #{s}" } unless names.empty?
  @io.flush
  @indent = 6
  @scenario_indent = 6
end

- (Object) exception(exception, status)



162
163
164
165
166
# File 'lib/cucumber/formatter/pretty.rb', line 162

def exception(exception, status)
  return if @hide_this_step
  print_exception(exception, status, @indent)
  @io.flush
end

- (Object) feature_name(keyword, name)



63
64
65
66
67
# File 'lib/cucumber/formatter/pretty.rb', line 63

def feature_name(keyword, name)
  @io.puts("#{keyword}: #{name}")
  @io.puts
  @io.flush
end

- (Object) scenario_name(keyword, name, file_colon_line, source_indent)



121
122
123
# File 'lib/cucumber/formatter/pretty.rb', line 121

def scenario_name(keyword, name, file_colon_line, source_indent)
  print_feature_element_name(keyword, name, file_colon_line, source_indent)
end

- (Object) step_name(keyword, step_match, status, source_indent, background, file_colon_line)



146
147
148
149
150
151
152
# File 'lib/cucumber/formatter/pretty.rb', line 146

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

- (Object) table_cell_value(value, status)



197
198
199
200
201
202
203
204
205
206
# File 'lib/cucumber/formatter/pretty.rb', line 197

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

- (Object) tag_name(tag_name)



56
57
58
59
60
61
# File 'lib/cucumber/formatter/pretty.rb', line 56

def tag_name(tag_name)
  tag = format_string(tag_name, :tag).indent(@indent)
  @io.print(tag)
  @io.flush
  @indent = 1
end