module Dalziel::Matchers
Public Instance Methods
match_json_expression(pattern)
click to toggle source
Replacement for the json_expression default matcher, shows prettier output.
Usage:
expect(json_or_hash).to match_json_expression( user: { id: Integer } )
# File lib/dalziel.rb, line 73 def match_json_expression(pattern) JSONPatternMatcher.new(pattern) end
match_json_request(pattern)
click to toggle source
Verifies outgoing request body stubbed with WebMock.
Usage:
req = stub_json_request(:get, "url", user: { id: 1 }) act expect(req).to match_json_request( foo: { bar: Integer } )
# File lib/dalziel.rb, line 45 def match_json_request(pattern) RequestMatcher.new(pattern) end
match_json_response(pattern)
click to toggle source
Verifies that the response is a proper JSON response. Optionally you can chain `status` to verify the status code.
Usage:
get "/foo/bar" expect(last_response).to match_json_response( foo: { bar: Integer } )
# File lib/dalziel.rb, line 60 def match_json_response(pattern) ResponseMatcher.new(pattern) end
stub_json_request(verb, url, body, status = 200)
click to toggle source
Stubs outgoing JSON requests with WebMock.
Usage:
stub_json_request(:get, "url", user: { id: 1 })
# File lib/dalziel.rb, line 23 def stub_json_request(verb, url, body, status = 200) stub_request(verb, url).to_return( headers: { content_type: "application/json" }, body: body.to_json, status: status, ) end