module
Amber::Testing::Assertions
Overview
Custom assertion helpers for use in Crystal specs.
These complement the built-in should matchers with
domain-specific assertions for HTTP responses.
describe "API" do
include Amber::Testing::Assertions
include Amber::Testing::RequestHelpers
it "returns success" do
response = get("/api/status")
assert_response_status(response, 200)
assert_response_success(response)
assert_json_content_type(response)
end
end
Defined in:
amber/testing/assertions.crInstance Method Summary
-
#assert_body_contains(response : TestResponse, text : String)
Assert that the response body contains the given string.
-
#assert_content_type(response : TestResponse, type : String)
Assert that the response Content-Type contains the expected type string.
-
#assert_header(response : TestResponse, key : String, value : String)
Assert that a specific response header is present with the expected value.
-
#assert_html_content_type(response : TestResponse)
Assert that the response Content-Type is HTML.
-
#assert_json_body(response : TestResponse) : JSON::Any
Assert that the response body is valid JSON and return the parsed result.
-
#assert_json_content_type(response : TestResponse)
Assert that the response Content-Type is JSON.
-
#assert_redirect_to(response : TestResponse, path : String)
Assert that a TestResponse is a redirect to the given URL.
-
#assert_response_client_error(response : TestResponse)
Assert that a TestResponse is a client error (4xx).
-
#assert_response_not_found(response : TestResponse)
Assert that a TestResponse is a not found error (404).
-
#assert_response_redirect(response : TestResponse)
Assert that a TestResponse is a redirect (3xx).
-
#assert_response_server_error(response : TestResponse)
Assert that a TestResponse is a server error (5xx).
-
#assert_response_status(response : TestResponse, status : Int32)
Assert that a TestResponse has the given status code.
-
#assert_response_success(response : TestResponse)
Assert that a TestResponse is successful (2xx).
Instance Method Detail
Assert that the response body contains the given string.
Assert that the response Content-Type contains the expected type string.
Assert that a specific response header is present with the expected value.
Assert that the response Content-Type is HTML.
Assert that the response body is valid JSON and return the parsed result.
Assert that the response Content-Type is JSON.
Assert that a TestResponse is a redirect to the given URL.
Assert that a TestResponse is a client error (4xx).
Assert that a TestResponse is a not found error (404).
Assert that a TestResponse is a redirect (3xx).
Assert that a TestResponse is a server error (5xx).
Assert that a TestResponse has the given status code.
Assert that a TestResponse is successful (2xx).