Skip to content

Instantly share code, notes, and snippets.

@diasjorge
Created February 3, 2010 15:01
Show Gist options
  • Save diasjorge/293662 to your computer and use it in GitHub Desktop.
Save diasjorge/293662 to your computer and use it in GitHub Desktop.
module Webrat
module Matchers
class HaveXpath #:nodoc:
def initialize(expected, options = {}, &block)
@expected = expected
@options = options
@handler = options.delete(:handler)
@block = block
end
def nokogiri_matches(stringlike)
if Nokogiri::XML::NodeSet === stringlike
@query = query.gsub(%r'^//', './/')
else
@query = query
end
add_options_conditions_to(@query)
@document = Webrat::XML.document(stringlike)
@document.xpath(@query, @handler)
end
end
end
end
module CustomHandler
class MatchHref
def match_href(list, expression)
list.find_all { |node| node['href'] =~ /#{expression}/ }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment