Class: Xml::C14n::RSpecMatchers::AnalogousMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/xml/c14n/rspec_matchers.rb

Instance Method Summary collapse

Constructor Details

#initialize(expected) ⇒ AnalogousMatcher

Returns a new instance of AnalogousMatcher.



15
16
17
18
# File 'lib/xml/c14n/rspec_matchers.rb', line 15

def initialize(expected)
  @expected = expected
  @result = nil
end

Instance Method Details

#diffableObject



50
51
52
# File 'lib/xml/c14n/rspec_matchers.rb', line 50

def diffable
  true
end

#failure_messageObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/xml/c14n/rspec_matchers.rb', line 34

def failure_message
  index = 0
  @result.map do |hash|
    index += 1
    "DIFF #{index}: expected node: #{hash[:node1]}\n" \
           "        actual node  : #{hash[:node2]}\n" \
           "        diff from    : #{hash[:diff1]}\n" \
           "        diff to      : #{hash[:diff2]}\n"
  end.join("\n")
end

#failure_message_when_negatedObject



45
46
47
48
# File 'lib/xml/c14n/rspec_matchers.rb', line 45

def failure_message_when_negated
  ["expected:", @target.to_s, "not be analogous with:",
   @expected.to_s].join("\n")
end

#matches?(target) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/xml/c14n/rspec_matchers.rb', line 20

def matches?(target)
  @target = target

  @result = CompareXML.equivalent?(
    Nokogiri::XML(@target),
    Nokogiri::XML(@expected),
    { collapse_whitespace: true,
      ignore_attr_order: true,
      verbose: true },
  )

  @result.empty?
end