class Cucumber::Formatter::Pretty

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.

Attributes

indent[W]
runtime[R]

Public Class Methods

new(runtime, path_or_io, options) click to toggle source
# File lib/cucumber/formatter/pretty.rb, line 26
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

Public Instance Methods

after_background(_background) click to toggle source
# File lib/cucumber/formatter/pretty.rb, line 94
def after_background(_background)
  print_messages
  @in_background = nil
  @io.puts
  @io.flush
end
after_feature_element(_feature_element) click to toggle source
# File lib/cucumber/formatter/pretty.rb, line 82
def after_feature_element(_feature_element)
  print_messages
  @io.puts
  @io.flush
end
after_features(features) click to toggle source
# File lib/cucumber/formatter/pretty.rb, line 43
def after_features(features)
  print_summary(features)
end
after_multiline_arg(_multiline_arg) click to toggle source
# File lib/cucumber/formatter/pretty.rb, line 183
def after_multiline_arg(_multiline_arg)
  @table = nil
end
after_outline_table(_outline_table) click to toggle source
# File lib/cucumber/formatter/pretty.rb, line 124
def after_outline_table(_outline_table)
  @table = nil
  @indent = 4
end
after_table_cell(_cell) click to toggle source
# File lib/cucumber/formatter/pretty.rb, line 202
def after_table_cell(_cell)
  return unless @table
  @col_index += 1
end
after_table_row(table_row) click to toggle source
# File lib/cucumber/formatter/pretty.rb, line 193
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
after_tags(_tags) click to toggle source
# File lib/cucumber/formatter/pretty.rb, line 57
def after_tags(_tags)
  if @indent == 1
    @io.puts
    @io.flush
  end
end
after_test_step(test_step, result) click to toggle source
# File lib/cucumber/formatter/pretty.rb, line 222
def after_test_step(test_step, result)
  collect_snippet_data(test_step, result)
end
background_name(keyword, name, file_colon_line, source_indent) click to toggle source
# File lib/cucumber/formatter/pretty.rb, line 101
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) click to toggle source
# File lib/cucumber/formatter/pretty.rb, line 88
def before_background(_background)
  @indent = 2
  @scenario_indent = 2
  @in_background = true
end
before_examples_array(_examples_array) click to toggle source
# File lib/cucumber/formatter/pretty.rb, line 105
def before_examples_array(_examples_array)
  @indent = 4
  @io.puts
  @visiting_first_example_name = true
end
before_feature(_feature) click to toggle source
# File lib/cucumber/formatter/pretty.rb, line 47
def before_feature(_feature)
  @exceptions = []
  @indent = 0
end
before_feature_element(_feature_element) click to toggle source
# File lib/cucumber/formatter/pretty.rb, line 77
def before_feature_element(_feature_element)
  @indent = 2
  @scenario_indent = 2
end
before_features(_features) click to toggle source
# File lib/cucumber/formatter/pretty.rb, line 39
def before_features(_features)
  print_profile_information
end
before_multiline_arg(multiline_arg) click to toggle source
# File lib/cucumber/formatter/pretty.rb, line 178
def before_multiline_arg(multiline_arg)
  return if @options[:no_multiline] || @hide_this_step
  @table = multiline_arg
end
before_outline_table(outline_table) click to toggle source
# File lib/cucumber/formatter/pretty.rb, line 120
def before_outline_table(outline_table)
  @table = outline_table
end
before_step(step) click to toggle source
# File lib/cucumber/formatter/pretty.rb, line 133
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) click to toggle source
# File lib/cucumber/formatter/pretty.rb, line 139
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) click to toggle source
# File lib/cucumber/formatter/pretty.rb, line 187
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) click to toggle source
# File lib/cucumber/formatter/pretty.rb, line 218
def before_test_case(_test_case)
  @previous_step_keyword = nil
end
comment_line(comment_line) click to toggle source
# File lib/cucumber/formatter/pretty.rb, line 52
def comment_line(comment_line)
  @io.puts(comment_line.indent(@indent))
  @io.flush
end
doc_string(string) click to toggle source
# File lib/cucumber/formatter/pretty.rb, line 163
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) click to toggle source
# File lib/cucumber/formatter/pretty.rb, line 111
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) click to toggle source
# File lib/cucumber/formatter/pretty.rb, line 171
def exception(exception, status)
  return if @hide_this_step
  print_messages
  print_exception(exception, status, @indent)
  @io.flush
end
feature_name(keyword, name) click to toggle source
# File lib/cucumber/formatter/pretty.rb, line 71
def feature_name(keyword, name)
  @io.puts("#{keyword}: #{name}")
  @io.puts
  @io.flush
end
scenario_name(keyword, name, file_colon_line, source_indent) click to toggle source
# File lib/cucumber/formatter/pretty.rb, line 129
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) click to toggle source
# File lib/cucumber/formatter/pretty.rb, line 155
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) click to toggle source
# File lib/cucumber/formatter/pretty.rb, line 207
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) click to toggle source
# File lib/cucumber/formatter/pretty.rb, line 64
def tag_name(tag_name)
  tag = format_string(tag_name, :tag).indent(@indent)
  @io.print(tag)
  @io.flush
  @indent = 1
end

Private Instance Methods

cell_prefix(status) click to toggle source
# File lib/cucumber/formatter/pretty.rb, line 242
def cell_prefix(status)
  @prefixes[status]
end
print_feature_element_name(keyword, name, file_colon_line, source_indent) click to toggle source
print_summary(features) click to toggle source