Module: JsonAssertions

Defined in:
lib/json_assertions.rb

Defined Under Namespace

Classes: JsonResponseTester

Instance Method Summary collapse

Instance Method Details

#assert_json_array_size(expected, path, message = nil) ⇒ Object



33
34
35
# 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) ⇒ Object



16
17
18
# 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) ⇒ Object



29
30
31
# 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) ⇒ Object



37
38
39
# 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) ⇒ Object



21
22
23
# 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) ⇒ Object



25
26
27
# 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_responseObject

Parse the response body for you.



12
13
14
# File 'lib/json_assertions.rb', line 12

def json_response
  JSON.parse response.body
end

#pretty_json(json) ⇒ Object

Prettifies json



6
7
8
9
# File 'lib/json_assertions.rb', line 6

def pretty_json(json)
  hash = JSON.parse json
  JSON.pretty_generate(hash)
end

#with_json(json, &block) ⇒ Object



41
42
43
# File 'lib/json_assertions.rb', line 41

def with_json(json, &block)
  block.call JsonResponseTester.new(json, self)
end