Skip to content

Instantly share code, notes, and snippets.

@kalleth
Created May 1, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kalleth/55072ab22a7ff833e475 to your computer and use it in GitHub Desktop.
Save kalleth/55072ab22a7ff833e475 to your computer and use it in GitHub Desktop.
matcher for table rows containing
require 'rspec/matchers'
module Suite
class Table < Struct.new(:table)
def rows
@rows ||= table.all('tbody tr').map do |tr|
tr.all('td').map(&:text)
end
end
end
end
RSpec::Matchers.define :have_row_containing do |expected|
match do |actual|
table = Suite::Table.new(actual)
table.rows.any? do |row|
(expected - row).empty?
end
end
end
it "contains the person in the list" do
people_table = page.find('table#people')
expect(people_table).to have_row_containing(['John Smith', 'Administrator'])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment