class
Amber::Testing::TestResponse
- Amber::Testing::TestResponse
- Reference
- Object
Overview
Wraps the result of an HTTP request made through the testing helpers. Provides convenient methods for asserting status codes, parsing JSON, and inspecting response headers and body content.
Defined in:
amber/testing/test_response.crConstructors
-
.from_client_response(response : HTTP::Client::Response) : TestResponse
Build a TestResponse from a raw HTTP::Client::Response.
- .new(status_code : Int32, body : String, headers : HTTP::Headers)
Instance Method Summary
- #body : String
-
#client_error? : Bool
Returns true if the status code is in the 4xx range.
-
#content_type : String | Nil
Returns the Content-Type header value if present, nil otherwise.
- #headers : HTTP::Headers
-
#json : JSON::Any
Parse the response body as JSON.
-
#redirect? : Bool
Returns true if the status code is in the 3xx range.
-
#redirect_url : String | Nil
Returns the value of the Location header if present, nil otherwise.
-
#server_error? : Bool
Returns true if the status code is in the 5xx range.
- #status_code : Int32
-
#successful? : Bool
Returns true if the status code is in the 2xx range.
Constructor Detail
Build a TestResponse from a raw HTTP::Client::Response.
Instance Method Detail
Returns the Content-Type header value if present, nil otherwise.
Parse the response body as JSON. Raises JSON::ParseException if the body is not valid JSON.
Returns the value of the Location header if present, nil otherwise. Useful for checking redirect targets.