Created
January 14, 2010 21:02
-
-
Save biot023/277508 to your computer and use it in GitHub Desktop.
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
class HaveXpathContaining < Struct.new( :xpath, :contents ) | |
def matches?( page ) | |
if self.contents.blank? | |
page.has_xpath?( self.xpath + "[not( text() )]" ) || page.has_xpath?( self.xpath + "[string-length( normalize-space( . ) ) = 0]" ) | |
else | |
page.has_xpath?( self.xpath + "[contains( ., '#{ self.contents }' )]" ) | |
end | |
end | |
def failure_message | |
"Page should have matched XPath #{ self.xpath.inspect } with contents #{ self.contents.inspect }, but didn't" | |
end | |
end | |
def have_xpath_containing( xpath, contents ) | |
HaveXpathContaining.new( xpath, contents ) | |
end | |
######################################################## | |
# Use like: | |
page.should have_xpath_containing( "//@a[@id = "remove"]", "Remove Item" ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment