Well, as it seems, there is no support out of the box, I wrote this custom matches:
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
Now you can do things like:
describe "initial page load", :type => :request do it "has 12 inputs" do visit "/" page.should match_exactly(12, "input") end end
and get the output, for example:
1) initial page load has 12 inputs Failure/Error: page.should match_exactly(12, "input") expected 'input' to match exactly 12 elements, but matched 13
Now this is a trick, I will consider this part of Capybara.
merryprankster Jul 25 '11 at 10:20 2011-07-25 10:20
source share