Module: Dalziel::Matchers
- Defined in:
- lib/dalziel.rb
Defined Under Namespace
Classes: JSONPatternMatcher, RequestMatcher, ResponseMatcher
Instance Method Summary collapse
-
#match_json_expression(pattern) ⇒ Object
Replacement for the json_expression default matcher, shows prettier output.
-
#match_json_request(pattern) ⇒ Object
Verifies outgoing request body stubbed with WebMock.
-
#match_json_response(pattern) ⇒ Object
Verifies that the response is a proper JSON response.
-
#stub_json_request(verb, url, body, status = 200) ⇒ Object
Stubs outgoing JSON requests with WebMock.
Instance Method Details
#match_json_expression(pattern) ⇒ Object
Replacement for the json_expression default matcher, shows prettier output.
Usage:
expect(json_or_hash).to match_json_expression(
user: {
id: Integer
}
)
73 74 75 |
# File 'lib/dalziel.rb', line 73 def match_json_expression(pattern) JSONPatternMatcher.new(pattern) end |
#match_json_request(pattern) ⇒ Object
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
}
)
45 46 47 |
# File 'lib/dalziel.rb', line 45 def match_json_request(pattern) RequestMatcher.new(pattern) end |
#match_json_response(pattern) ⇒ Object
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
}
)
60 61 62 |
# File 'lib/dalziel.rb', line 60 def match_json_response(pattern) ResponseMatcher.new(pattern) end |
#stub_json_request(verb, url, body, status = 200) ⇒ Object
Stubs outgoing JSON requests with WebMock.
Usage:
stub_json_request(:get, "url", user: { id: 1 })
23 24 25 26 27 28 29 |
# 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 |