Skip to content

Instantly share code, notes, and snippets.

@pimpin
pimpin / have_xml.rb
Last active November 30, 2022 17:37 — forked from faun/have_xml.rb
require 'nokogiri'
RSpec::Matchers.define :have_xml do |xpath, text|
match do |body|
doc = Nokogiri::XML::Document.parse(body)
nodes = doc.xpath(xpath)
expect(nodes).to_not be_empty
if text
nodes.each do |node|
cdata = node.children.find { |e| e.cdata? }
value_to_check = node.text