Class: Matchers::JSON::JSONPathHasObject

Inherits:
Object
  • Object
show all
Includes:
JSONPath
Defined in:
lib/matchers/json/json_path_has_object.rb

Instance Method Summary collapse

Methods included from JSONPath

#json_path_valid?, #value_on_path

Constructor Details

#initialize(json_path, json_object) ⇒ JSONPathHasObject

Returns a new instance of JSONPathHasObject.



6
7
8
9
# File 'lib/matchers/json/json_path_has_object.rb', line 6

def initialize(json_path, json_object)
  @json_path = json_path
  @json_object = json_object.is_a?(Hash) ? json_object : ::JSON.parse(json_object)
end

Instance Method Details

#matches?(document_s) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
# File 'lib/matchers/json/json_path_has_object.rb', line 11

def matches?(document_s)
  json_hash = ::JSON.parse(document_s)
  value_on_path(json_hash, @json_path) == @json_object
end