Skip to content

Instantly share code, notes, and snippets.

@msassak
Created April 8, 2010 06:10
Show Gist options
  • Select an option

  • Save msassak/359828 to your computer and use it in GitHub Desktop.

Select an option

Save msassak/359828 to your computer and use it in GitHub Desktop.
require 'cucumber'
require 'cucumber/ast/table'
def dittoize(table)
rows = table.rows
rows.each_cons(2) do |upper, lower|
next unless lower.any? { |cell| cell == "''" }
lower.each_with_index do |cell, idx|
lower[idx] = upper[idx] if cell == "''"
end
end
Cucumber::Ast::Table.new([table.headers] + rows)
end
raw = [["zip"], ["12345"], ["''"]]
t = Cucumber::Ast::Table.new(raw)
puts t
puts dittoize(t)
complex = [["zip", "phone"],
["12345", "3135551212"],
["''", "1234567890"],
["54321", "''"],
["''", "''"],
["''", "123"]]
t = Cucumber::Ast::Table.new(complex)
puts t
puts dittoize(t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment