background(background)
click to toggle source
def background(background)
replay
@statement = background
end
done()
click to toggle source
eof()
click to toggle source
examples(examples)
click to toggle source
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
def feature(feature)
print_comments(feature.comments, '')
print_tags(feature.tags, '')
@io.puts "#{feature.keyword}: #{feature.name}"
print_description(feature.description, ' ', false)
end
match(match)
click to toggle source
def match(match)
@match = match
print_statement
print_step('executing', @match.arguments, @match.location, false)
end
print_statement()
click to toggle source
def print_statement
return if @statement.nil?
calculate_location_indentations
@io.puts
print_comments(@statement.comments, ' ')
print_tags(@statement.tags, ' ') if @statement.respond_to?(:tags)
@io.write " #{@statement.keyword}: #{@statement.name}"
location = @executing ? "#{@uri}:#{@statement.line}" : nil
@io.puts indented_location(location, true)
print_description(@statement.description, ' ')
@statement = nil
end
print_step(status, arguments, location, proceed)
click to toggle source
def print_step(status, arguments, location, proceed)
step = proceed ? @steps.shift : @steps[0]
text_format = format(status)
arg_format = arg_format(status)
print_comments(step.comments, ' ')
@io.write(' ')
@io.write(text_format.text(step.keyword))
@step_printer.write_step(@io, text_format, arg_format, step.name, arguments)
@io.puts(indented_location(location, proceed))
doc_string(step.doc_string) if step.doc_string
table(step.rows) if step.rows
end
print_steps()
click to toggle source
def print_steps
while(@steps.any?)
print_step('skipped', [], nil, true)
end
end
replay()
click to toggle source
def replay
print_statement
print_steps
end
result(result)
click to toggle source
def result(result)
@io.write(up(1))
print_step(result.status, @match.arguments, @match.location, true)
end
scenario(scenario)
click to toggle source
def scenario(scenario)
replay
@statement = scenario
end
scenario_outline(scenario_outline)
click to toggle source
def scenario_outline(scenario_outline)
replay
@statement = scenario_outline
end
step(step)
click to toggle source
def step(step)
@steps << step
end
table(rows)
click to toggle source
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
def uri(uri)
@uri = uri
end
calculate_location_indentations()
click to toggle source
def calculate_location_indentations
line_widths = ([@statement] + @steps).map {|step| (step.keyword+step.name).unpack("U*").length}
max_line_width = line_widths.max
@indentations = line_widths.map{|w| max_line_width - w}
end
color(cell, statuses, col)
click to toggle source
def color(cell, statuses, col)
if statuses
self.__send__(statuses[col], escape_cell(cell)) + reset
else
escape_cell(cell)
end
end
doc_string(doc_string)
click to toggle source
def doc_string(doc_string)
@io.puts " \"\"\"" + doc_string.content_type + "\n" + escape_triple_quotes(indent(doc_string.value, ' ')) + "\n \"\"\""
end
escape_triple_quotes(s)
click to toggle source
def escape_triple_quotes(s)
s.gsub(TRIPLE_QUOTES, '\"\"\"')
end
exception(exception)
click to toggle source
def exception(exception)
exception_text = "#{exception.message} (#{exception.class})\n#{(exception.backtrace || []).join("\n")}".gsub(/^/, ' ')
@io.puts(failed(exception_text))
end
indent(string, indentation)
click to toggle source
def indent(string, indentation)
string.gsub(START, indentation)
end
indented_location(location, proceed)
click to toggle source
def indented_location(location, proceed)
indentation = proceed ? @indentations.shift : @indentations[0]
location ? (' ' * indentation + ' ' + comments + "# #{location}" + reset) : ''
end
print_description(description, indent, newline=true)
click to toggle source
def print_description(description, indent, newline=true)
if description != ""
@io.puts indent(description, indent)
@io.puts if newline
end
end