Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module XMLMatchers
- require 'libxml'
- require 'rspec/expectations'
- RSpec::Matchers.define :have_xml do |xpath, text|
- match do |body|
- parser = LibXML::XML::Parser.string body
- doc = parser.parse
- nodes = doc.find(xpath)
- return false if nodes.empty?
- if text
- return false unless nodes.any? {|node| node.content == text}
- end
- return true
- end
- failure_message_for_should do |body|
- "expected to find text '#{text}' in xml tag #{xpath} in:\n#{body}"
- end
- failure_message_for_should_not do |response|
- "expected not to find text #{text} xml tag #{xpath} in:\n#{body}"
- end
- description do
- "have xml tag #{xpath}"
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement