Skip to content

Instantly share code, notes, and snippets.

@hassox
Created September 1, 2010 00:18
Show Gist options
  • Select an option

  • Save hassox/560013 to your computer and use it in GitHub Desktop.

Select an option

Save hassox/560013 to your computer and use it in GitHub Desktop.
Rspec::Matchers.define :match_nokogiri_selector do |selector|
match do |doc|
doc.at(selector) != nil
end
failure_message_for_should do |doc|
"expected #{selector} to be found in \n#{doc.to_xml}"
end
failure_message_for_should_not do |doc|
"expected that #{selector} would not be found in #{doc.to_xml}"
end
description do
"match a selector of a nokogiri document"
end
end
## Example
xml = Nokogiri.XML(File.read(xml_path))
xml.should match_nokogiri_selector "section article[class='stuff'] h1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment