Class: Matchers::JSON::JSONPathHasArray

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

Instance Method Summary collapse

Methods included from JSONPath

#json_path_valid?, #value_on_path

Constructor Details

#initialize(json_path, json_array) ⇒ JSONPathHasArray

Returns a new instance of JSONPathHasArray.



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

def initialize(json_path, json_array)
  @json_path = json_path
  @json_array = json_array.is_a?(Array) ? json_array : ::JSON.parse(json_array)
end

Instance Method Details

#matches?(document_s) ⇒ Boolean

Returns:

  • (Boolean)


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

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