Last active
August 29, 2015 14:01
-
-
Save ravinggenius/298aac91bd7989a81332 to your computer and use it in GitHub Desktop.
Helpers for dealing with tables when integration testing with Capybara
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
module StepHelpers | |
def table_for(table_or_id) | |
if table_or_id.is_a?(Capybara::Node::Element) | |
table_or_id | |
else | |
find("##{table_or_id}") | |
end | |
end | |
def row_containing_text(table_or_id, text) | |
table_for(table_or_id).find(:xpath, "tbody//tr[(* | *//*)[contains(text(), '#{text}')]]") | |
end | |
def table_row_hash(table_or_id, text) | |
table = table_for(table_or_id) | |
row = row_containing_text(table, text) | |
table.all('thead th').zip(row.all('th, td')).inject({}) do |memo, (header, cell)| | |
memo.merge(header.text => cell.text) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment