Class: Matchers::JSON::DocumentContainsJSONPath

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

Instance Method Summary collapse

Methods included from JSONPath

#json_path_valid?, #value_on_path

Constructor Details

#initialize(json_path) ⇒ DocumentContainsJSONPath

Returns a new instance of DocumentContainsJSONPath.



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

def initialize(json_path)
  @json_path = json_path
end

Instance Method Details

#matches?(document_s) ⇒ Boolean

Exceptions caught by JSON Parser will be thrown up the stack ::JSON::ParserError in the case of invalid JSON

Parameters:

  • document_s (String)
    • the document given as String

Returns:

  • (Boolean)


13
14
15
16
# File 'lib/matchers/json/document_contains_json_path.rb', line 13

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