Skip to content

Instantly share code, notes, and snippets.

@hynkle
Created April 21, 2011 19:56
Show Gist options
  • Save hynkle/935341 to your computer and use it in GitHub Desktop.
Save hynkle/935341 to your computer and use it in GitHub Desktop.
step definition for table rows in cucumber w/ capybara
# The overall effect of this is to assert that there exists a row where all of the strings
# specified can be found in one of its tds.
#
# Then I should see "foo" and "bar" within a row
# Then I should see "foo", "bar", and "baz" within a row
Then /^I should see ((?:"(?:[^"]+)"(?: |, | and |, and ))*"(?:[^"]+)") (?:within|in) a row$/ do |list|
cell_xpaths = list.scan(/"(?:[^"])+"/).map{|cell_content| %(td/descendant-or-self::*[text()=#{cell_content}])}
page.should have_xpath %{//tr/#{cell_xpaths.join %(/ancestor::tr[1]/)}}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment