Created
May 1, 2015 13:58
-
-
Save kalleth/55072ab22a7ff833e475 to your computer and use it in GitHub Desktop.
matcher for table rows containing
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
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