1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
module TestXml
# This module implements the actual matchers with their conditions.
module MatcherMethods
def self.xml_contain(subject, pattern)
actual, expected = parse_xml(subject, pattern)
actual.match?(expected, true)
end
def self.xml_equal(subject, pattern)
actual, expected = parse_xml(subject, pattern)
actual.match?(expected, true) && expected.match?(actual, true)
end
def self.xml_structure_contain(subject, pattern)
actual, expected = parse_xml(subject, pattern)
actual.match?(expected)
end
def self.xml_structure_equal(subject, pattern)
actual, expected = parse_xml(subject, pattern)
actual.match?(expected) && expected.match?(actual)
end
private
def self.parse_xml(subject, pattern)
[Nokogiri::XML.parse(subject).root, Nokogiri::XML.parse(pattern).root]
end
end
end
|