Sha256: c11e80a358294d1f1712ba2a3dde4835de74ab7c9d124c796b484316667e0cdf

Contents?: true

Size: 836 Bytes

Versions: 1

Compression:

Stored size: 836 Bytes

Contents

require 'json'
require 'active_support/core_ext/hash'

module APIMatchers
  module ResponseBody
    class HaveJsonNode < Base
      def matches?(actual)
        @actual = actual
        json = begin
          JSON.parse(response_body)
        rescue
          {}
        end

        begin
          options = {}
          options[:node] = @expected_node.to_s
          unless @with_value.nil?
            options[:value] = @with_value
          end

          node = Core::FindInJSON.new(json).find( options )

          if @expected_including_text
            node.to_s.include?(@expected_including_text)
          else
            # the node is present
            true
          end
        rescue ::APIMatchers::Core::Exceptions::KeyNotFound
          # the key was not found
          false
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
api_matchers-0.1.1 lib/api_matchers/response_body/have_json_node.rb