Parent

Class/Module Index [+]

Quicksearch

Gherkin::Formatter::PrettyFormatter

Constants

START
TRIPLE_QUOTES

Public Class Methods

new(io, monochrome, executing) click to toggle source
# File lib/gherkin/formatter/pretty_formatter.rb, line 16
def initialize(io, monochrome, executing)
  @io = io
  @step_printer = StepPrinter.new
  @monochrome = monochrome
  @executing = executing
  @background = nil
  @tag_statement = nil
  @steps = []
end

Public Instance Methods

arg_format(key) click to toggle source
# File lib/gherkin/formatter/pretty_formatter.rb, line 138
def arg_format(key)
  format("#{key}_arg")
end
background(background) click to toggle source
# File lib/gherkin/formatter/pretty_formatter.rb, line 37
def background(background)
  replay
  @statement = background
end
eof() click to toggle source
# File lib/gherkin/formatter/pretty_formatter.rb, line 155
def eof
  replay
  # NO-OP
end
examples(examples) click to toggle source
# File lib/gherkin/formatter/pretty_formatter.rb, line 76
def examples(examples)
  replay
  @io.puts
  print_comments(examples.comments, '    ')
  print_tags(examples.tags, '    ')
  @io.puts "    #{examples.keyword}: #{examples.name}"
  print_description(examples.description, '      ')
  table(examples.rows)
end
feature(feature) click to toggle source
# File lib/gherkin/formatter/pretty_formatter.rb, line 30
def feature(feature)
  print_comments(feature.comments, '')
  print_tags(feature.tags, '')
  @io.puts "#{feature.keyword}: #{feature.name}"
  print_description(feature.description, '  ', false)
end
format(key) click to toggle source
# File lib/gherkin/formatter/pretty_formatter.rb, line 142
def format(key)
  if @formats.nil?
    if @monochrome
      @formats = Hash.new(MonochromeFormat.new)
    else
      @formats = Hash.new do |formats, status|
        formats[status] = ColorFormat.new(status)
      end
    end
  end
  @formats[key]
end
match(match) click to toggle source
# File lib/gherkin/formatter/pretty_formatter.rb, line 90
def match(match)
  @match = match
  print_statement
  print_step('executing', @match.arguments, @match.location, false)
end
replay() click to toggle source
# File lib/gherkin/formatter/pretty_formatter.rb, line 52
def replay
  print_statement
  print_steps
end
result(result) click to toggle source
# File lib/gherkin/formatter/pretty_formatter.rb, line 96
def result(result)
  @io.write(up(1))
  print_step(result.status, @match.arguments, @match.location, true)
end
scenario(scenario) click to toggle source
# File lib/gherkin/formatter/pretty_formatter.rb, line 42
def scenario(scenario)
  replay
  @statement = scenario
end
scenario_outline(scenario_outline) click to toggle source
# File lib/gherkin/formatter/pretty_formatter.rb, line 47
def scenario_outline(scenario_outline)
  replay
  @statement = scenario_outline
end
step(step) click to toggle source
# File lib/gherkin/formatter/pretty_formatter.rb, line 86
def step(step)
  @steps << step
end
table(rows) click to toggle source
# File lib/gherkin/formatter/pretty_formatter.rb, line 160
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.value}"
    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
uri(uri) click to toggle source
# File lib/gherkin/formatter/pretty_formatter.rb, line 26
def uri(uri)
  @uri = uri
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.