Skip to content

Instantly share code, notes, and snippets.

@greis
Created January 31, 2012 16:47
Show Gist options
  • Save greis/1711522 to your computer and use it in GitHub Desktop.
Save greis/1711522 to your computer and use it in GitHub Desktop.
Cucumber table diff for partial rows
Then /^the table should contain the following rows:$/ do |table|
table_element = find('table.standard')
headers = table_element.all('thead th').map(&:text)
result = table_element.all('tbody tr').map do |tr|
{}.tap do |hash|
tds = tr.all('td').map(&:text)
headers.each_with_index do |header, i|
hash[header] = tds[i]
end
end
end
table.diff!(result, surplus_row: false)
end
@briandunn
Copy link

parsing a table is even easier than that. You don't have to fold the rows into hashes yourself, the table method will do that for you. https://github.com/hashrocket/tms/blob/master/features/support/table.rb#L8

@greis
Copy link
Author

greis commented Jan 31, 2012

good to know, the code becomes clearer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment