class Amber::Testing::TestResponse

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.cr

Constructors

Instance Method Summary

Constructor Detail

def self.from_client_response(response : HTTP::Client::Response) : TestResponse #

Build a TestResponse from a raw HTTP::Client::Response.


[View source]
def self.new(status_code : Int32, body : String, headers : HTTP::Headers) #

[View source]

Instance Method Detail

def body : String #

[View source]
def client_error? : Bool #

Returns true if the status code is in the 4xx range.


[View source]
def content_type : String | Nil #

Returns the Content-Type header value if present, nil otherwise.


[View source]
def headers : HTTP::Headers #

[View source]
def json : JSON::Any #

Parse the response body as JSON. Raises JSON::ParseException if the body is not valid JSON.


[View source]
def redirect? : Bool #

Returns true if the status code is in the 3xx range.


[View source]
def redirect_url : String | Nil #

Returns the value of the Location header if present, nil otherwise. Useful for checking redirect targets.


[View source]
def server_error? : Bool #

Returns true if the status code is in the 5xx range.


[View source]
def status_code : Int32 #

[View source]
def successful? : Bool #

Returns true if the status code is in the 2xx range.


[View source]