File: matcher_methods.rb

package info (click to toggle)
ruby-test-xml 0.1.8-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 184 kB
  • sloc: ruby: 781; makefile: 4
file content (29 lines) | stat: -rw-r--r-- 899 bytes parent folder | download | duplicates (3)
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