Skip to content

Instantly share code, notes, and snippets.

@biot023
Created January 14, 2010 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save biot023/277508 to your computer and use it in GitHub Desktop.
Save biot023/277508 to your computer and use it in GitHub Desktop.
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