Class: VCR::XpathMatcher

Inherits:
Struct
  • Object
show all
Defined in:
lib/vcr/xpath_matcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#xpathObject

Returns the value of attribute xpath

Returns:

  • (Object)

    the current value of xpath



2
3
4
# File 'lib/vcr/xpath_matcher.rb', line 2

def xpath
  @xpath
end

Instance Method Details

#extract_xpath(xml) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/vcr/xpath_matcher.rb', line 17

def extract_xpath(xml)
  if xml.is_a? String
    xml = Nokogiri::XML(xml)
    xml.remove_namespaces!
  end
  xml.xpath(xpath)
end

#human_typeObject



13
14
15
# File 'lib/vcr/xpath_matcher.rb', line 13

def human_type
  "only"
end

#matches?(request, expected_request) ⇒ Boolean

Returns:

  • (Boolean)


3
4
5
6
7
8
9
10
11
# File 'lib/vcr/xpath_matcher.rb', line 3

def matches?(request, expected_request)
  node = extract_xpath(request.body)
  return false if node.blank?

  expected_node = extract_xpath(expected_request.body)
  return false if expected_node.blank?

  EquivalentXml.equivalent? node, expected_node
end