Parent

Gherkin::Formatter::PrettyFormatter

Constants

START
TRIPLE_QUOTES

Public Class Methods

new(io, monochrome) click to toggle source
# File lib/gherkin/formatter/pretty_formatter.rb, line 15
def initialize(io, monochrome)
  @io = io
  @monochrome = monochrome
  @format = MonochromeFormat.new #@monochrome ? MonochromeFormat.new : AnsiColorFormat.new
end

Public Instance Methods

background(comments, keyword, name, description, line) click to toggle source
# File lib/gherkin/formatter/pretty_formatter.rb, line 29
def background(comments, keyword, name, description, line)
  @io.puts
  print_comments(comments, '  ')
  @io.puts "  #{keyword}: #{name}#{indented_element_uri!(keyword, name, line)}"
  print_description(description, '    ')
end
eof() click to toggle source
# File lib/gherkin/formatter/pretty_formatter.rb, line 81
def eof
end
examples(comments, tags, keyword, name, description, line, examples_table) click to toggle source
# File lib/gherkin/formatter/pretty_formatter.rb, line 48
def examples(comments, tags, keyword, name, description, line, examples_table)
  @io.puts
  print_comments(comments, '    ')
  print_tags(tags, '    ')
  @io.puts "    #{keyword}: #{name}"
  print_description(description, '    ')
  table(examples_table)
end
feature(comments, tags, keyword, name, description, uri) click to toggle source
# File lib/gherkin/formatter/pretty_formatter.rb, line 21
def feature(comments, tags, keyword, name, description, uri)
  @uri = uri
  print_comments(comments, '')
  print_tags(tags, '')
  @io.puts "#{keyword}: #{name}"
  print_description(description, '  ', false)
end
scenario(comments, tags, keyword, name, description, line) click to toggle source
# File lib/gherkin/formatter/pretty_formatter.rb, line 36
def scenario(comments, tags, keyword, name, description, line)
  @io.puts
  print_comments(comments, '  ')
  print_tags(tags, '  ')
  @io.puts "  #{keyword}: #{name}#{indented_element_uri!(keyword, name, line)}"
  print_description(description, '    ')
end
scenario_outline(comments, tags, keyword, name, description, line) click to toggle source
# File lib/gherkin/formatter/pretty_formatter.rb, line 44
def scenario_outline(comments, tags, keyword, name, description, line)
  scenario(comments, tags, keyword, name, description, line)
end
step(comments, keyword, name, line, multiline_arg, status, exception, arguments, stepdef_location) click to toggle source
# File lib/gherkin/formatter/pretty_formatter.rb, line 57
def step(comments, keyword, name, line, multiline_arg, status, exception, arguments, stepdef_location)
  status_param = "#{status}_param" if status
  name = Gherkin::Formatter::Argument.format(name, @format, (arguments || [])) 

  step = "#{keyword}#{name}"
  step = self.__send__(status, step, @monochrome) if status

  print_comments(comments, '    ')
  @io.puts("    #{step}#{indented_step_location!(stepdef_location)}")
  case multiline_arg
  when String
    py_string(multiline_arg)
  when Array
    table(multiline_arg)
  when NilClass
  else
    raise "Bad multiline_arg: #{multiline_arg.inspect}"
  end
end
steps(steps) click to toggle source

This method can be invoked before a scenario, to ensure location arguments are aligned

# File lib/gherkin/formatter/pretty_formatter.rb, line 85
def steps(steps)
  @step_lengths = steps.map {|keyword, name| (keyword+name).unpack("U*").length}
  @max_step_length = @step_lengths.max
  @step_index = -1
end
syntax_error(state, event, legal_events, line) click to toggle source
# File lib/gherkin/formatter/pretty_formatter.rb, line 77
def syntax_error(state, event, legal_events, line)
  raise "SYNTAX ERROR"
end
table(rows) click to toggle source
# File lib/gherkin/formatter/pretty_formatter.rb, line 91
def table(rows)
  cell_lengths = rows.map do |row| 
    row.cells.map do |cell| 
      escape_cell(cell).unpack("U*").length
    end
  end
  max_lengths = cell_lengths.transpose.map { |col_lengths| col_lengths.max }.flatten

  rows.each_with_index do |row, i|
    row.comments.each do |comment|
      @io.puts "      #{comment}"
    end
    j = -1
    @io.puts '      | ' + row.cells.zip(max_lengths).map { |cell, max_length|
      j += 1
      color(cell, nil, j) + ' ' * (max_length - cell_lengths[i][j])
    }.join(' | ') + ' |'
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.