Class: JsonSpec::Matchers::HaveJsonPath

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

Instance Method Summary collapse

Methods included from Helpers

#generate_normalized_json, #normalize_json, #parse_json

Constructor Details

#initialize(path) ⇒ HaveJsonPath

Returns a new instance of HaveJsonPath.



119
120
121
# File 'lib/json_spec/matchers.rb', line 119

def initialize(path)
  @path = path
end

Instance Method Details

#descriptionObject



140
141
142
# File 'lib/json_spec/matchers.rb', line 140

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

#failure_message_for_shouldObject



132
133
134
# File 'lib/json_spec/matchers.rb', line 132

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

#failure_message_for_should_notObject



136
137
138
# File 'lib/json_spec/matchers.rb', line 136

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

#matches?(json) ⇒ Boolean

Returns:

  • (Boolean)


123
124
125
126
127
128
129
130
# File 'lib/json_spec/matchers.rb', line 123

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