Created
February 25, 2009 16:01
-
-
Save quirkey/70246 to your computer and use it in GitHub Desktop.
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
| # HTML matcher for bacon | |
| # | |
| # it 'should display document' do | |
| # body.should have_element('#document') | |
| # end | |
| # | |
| # With content matching: | |
| # | |
| # it 'should display loaded document' do | |
| # body.should have_element('#document .title', /My Document/) | |
| # end | |
| require 'nokogiri' | |
| def have_element(search, content = nil) | |
| lambda do |obj| | |
| doc = Nokogiri.parse(obj.to_s) | |
| node_set = doc.search(search) | |
| if node_set.empty? | |
| false | |
| else | |
| collected_content = node_set.collect {|t| t.content }.join(' ') | |
| case content | |
| when Regexp | |
| collected_content =~ content | |
| when String | |
| collected_content.include?(content) | |
| when nil | |
| true | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment