Skip to content

Instantly share code, notes, and snippets.

@jameslafa
Created July 26, 2013 08:37
Show Gist options
  • Save jameslafa/6087268 to your computer and use it in GitHub Desktop.
Save jameslafa/6087268 to your computer and use it in GitHub Desktop.
Counting elements using capybara and rspec
RSpec::Matchers.define :match_exactly do |expected_match_count, selector|
match do |context|
matching = context.all(selector)
@matched = matching.size
@matched == expected_match_count
end
failure_message_for_should do
"expected '#{selector}' to match exactly #{expected_match_count} elements, but matched #{@matched}"
end
failure_message_for_should_not do
"expected '#{selector}' to NOT match exactly #{expected_match_count} elements, but it did"
end
end
# To use it :
# page.should match_exactly(12, "input")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment