Created
January 31, 2012 16:47
-
-
Save greis/1711522 to your computer and use it in GitHub Desktop.
Cucumber table diff for partial rows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
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
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