Sha256: b9d8dc096f335bc3a549dce5860f9700adf1565cb4e40659c17665af968d2012

Contents?: true

Size: 785 Bytes

Versions: 6

Compression:

Stored size: 785 Bytes

Contents

require 'nokogiri'

module APIMatchers
  module ResponseBody
    class HaveXmlNode < Base
      def matches?(actual)
        value = false
        @actual = actual
        xml = Nokogiri::XML(response_body)

        node_set = xml.xpath("//#{@expected_node}")
        if node_set
          node_set.each do |node|
            if @with_value
              value = (node.text == @with_value.to_s)
            elsif @expected_including_text
              value = (node.text.to_s.include?(@expected_including_text))
            else
              value = node.text.present?
            end
            # if value is true, time to return
            return value if value
          end
        end
        # at this point, it failed to match
        return value
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
api_matchers-0.6.2 lib/api_matchers/response_body/have_xml_node.rb
api_matchers-0.6.1 lib/api_matchers/response_body/have_xml_node.rb
api_matchers-0.6.0 lib/api_matchers/response_body/have_xml_node.rb
api_matchers-0.5.1 lib/api_matchers/response_body/have_xml_node.rb
api_matchers-0.5.0 lib/api_matchers/response_body/have_xml_node.rb
api_matchers-0.4.0 lib/api_matchers/response_body/have_xml_node.rb