module JsonAssertions

Public Instance Methods

assert_json_array_size(expected, path, message=nil) click to toggle source
# File lib/json_assertions.rb, line 33
def assert_json_array_size(expected, path, message=nil)
  assert_equal expected, JsonResponseTester.new(json_response, self).value_at(path).size, message
end
assert_json_equal(expected, path, message=nil) click to toggle source
# File lib/json_assertions.rb, line 16
def assert_json_equal(expected, path, message=nil)
  JsonResponseTester.new(json_response, self).equal(expected, path, message)
end
assert_json_has(path, message=nil) click to toggle source
# File lib/json_assertions.rb, line 29
def assert_json_has(path, message=nil)
  JsonResponseTester.new(json_response, self).must_have(path, message)
end
assert_json_is_array(path, message=nil) click to toggle source
# File lib/json_assertions.rb, line 37
def assert_json_is_array(path, message=nil)
  JsonResponseTester.new(json_response, self).is_array?(path, message)
end
assert_json_match(regex, path, message=nil) click to toggle source
# File lib/json_assertions.rb, line 21
def assert_json_match(regex, path, message=nil)
  JsonResponseTester.new(json_response, self).matches(regex, path, message)
end
assert_json_missing(path, message=nil) click to toggle source
# File lib/json_assertions.rb, line 25
def assert_json_missing(path, message=nil)
  JsonResponseTester.new(json_response, self).must_not_have(path, message)
end
json_response() click to toggle source

Parse the response body for you.

# File lib/json_assertions.rb, line 12
def json_response
  JSON.parse response.body
end
pretty_json(json) click to toggle source

Prettifies json

# File lib/json_assertions.rb, line 6
def pretty_json(json)
  hash = JSON.parse json
  JSON.pretty_generate(hash)
end
with_json(json, &block) click to toggle source
# File lib/json_assertions.rb, line 41
def with_json(json, &block)
  block.call JsonResponseTester.new(json, self)
end