Created
          July 26, 2013 08:37 
        
      - 
      
- 
        Save jameslafa/6087268 to your computer and use it in GitHub Desktop. 
    Counting elements using capybara and rspec
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | 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