Class: JsonSpec::Matchers::HaveJsonPath

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/json_spec/matchers/have_json_path.rb

Instance Method Summary collapse

Methods included from Helpers

#generate_normalized_json, #load_json, #normalize_json, #parse_json

Constructor Details

#initialize(path) ⇒ HaveJsonPath

Returns a new instance of HaveJsonPath.



6
7
8
# File 'lib/json_spec/matchers/have_json_path.rb', line 6

def initialize(path)
  @path = path
end

Instance Method Details

#descriptionObject



27
28
29
# File 'lib/json_spec/matchers/have_json_path.rb', line 27

def description
  %(have JSON path "#{@path}")
end

#failure_messageObject Also known as: failure_message_for_should



17
18
19
# File 'lib/json_spec/matchers/have_json_path.rb', line 17

def failure_message
  %(Expected JSON path "#{@path}")
end

#failure_message_when_negatedObject Also known as: failure_message_for_should_not



22
23
24
# File 'lib/json_spec/matchers/have_json_path.rb', line 22

def failure_message_when_negated
  %(Expected no JSON path "#{@path}")
end

#matches?(json) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
# File 'lib/json_spec/matchers/have_json_path.rb', line 10

def matches?(json)
  parse_json(json, @path)
  true
rescue JsonSpec::MissingPath
  false
end