Class: APIMatchers::ResponseBody::HaveJsonNode

Inherits:
Base
  • Object
show all
Includes:
Core::Parser
Defined in:
lib/api_matchers/response_body/have_json_node.rb

Instance Attribute Summary

Attributes inherited from Base

#actual, #expected_node, #setup

Instance Method Summary collapse

Methods included from Core::Parser

#json

Methods inherited from Base

#added_message, #failure_message, #failure_message_when_negated, #including_text, #initialize, #response_body, #with

Constructor Details

This class inherits a constructor from APIMatchers::ResponseBody::Base

Instance Method Details

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/api_matchers/response_body/have_json_node.rb', line 9

def matches?(actual)
  @actual = actual

  begin
    node = Core::FindInJSON.new(json).find(node: @expected_node.to_s, value: @with_value)

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