Rspec custom matchers for xml using Nokogiri XPath selector and optional content to match within selection. See matcher_spec.rb for usage.
Place have_xml.rb in your {Rails.root}/spec/support/matchers directory
Adapted from: Testing XML with rspec, xpath and libxml
Thanks for this, one note, if you're parsing xml with CDATA nodes and indentation, node.content will match the line breaks and whitespace in addition to the CDATA wrapped text. To handle that case, I rewrote your nodes.each section as:
Without that change, have_xml fails if you try, for example, this assertion:
on XML such as:
p.s. line 19 of have_xml.rb should read:
(not |response|)