Top Level Namespace

Included Modules

Extended Modules

Defined in:

Method Summary

Method Detail

def delete(path : String, headers : HTTP::Headers | Nil = nil, body : String | Nil = nil) : HTTP::Client::Response #

Sends a DELETE request to the specified path.

Parameters

  • path : The URL path to request
  • headers : Optional HTTP headers
  • body : Optional request body

Example

delete "/example"
response.status_code.should eq 200

[View source]
def get(path : String, headers : HTTP::Headers | Nil = nil, body : String | Nil = nil) : HTTP::Client::Response #

Sends a GET request to the specified path.

Parameters

  • path : The URL path to request
  • headers : Optional HTTP headers
  • body : Optional request body

Example

get "/example"
response.status_code.should eq 200

[View source]
def head(path : String, headers : HTTP::Headers | Nil = nil, body : String | Nil = nil) : HTTP::Client::Response #

Sends a HEAD request to the specified path.

Parameters

  • path : The URL path to request
  • headers : Optional HTTP headers
  • body : Optional request body

Example

head "/example"
response.status_code.should eq 200

[View source]
def patch(path : String, headers : HTTP::Headers | Nil = nil, body : String | Nil = nil) : HTTP::Client::Response #

Sends a PATCH request to the specified path.

Parameters

  • path : The URL path to request
  • headers : Optional HTTP headers
  • body : Optional request body

Example

patch "/example"
response.status_code.should eq 200

[View source]
def post(path : String, headers : HTTP::Headers | Nil = nil, body : String | Nil = nil) : HTTP::Client::Response #

Sends a POST request to the specified path.

Parameters

  • path : The URL path to request
  • headers : Optional HTTP headers
  • body : Optional request body

Example

post "/example"
response.status_code.should eq 200

[View source]
def put(path : String, headers : HTTP::Headers | Nil = nil, body : String | Nil = nil) : HTTP::Client::Response #

Sends a PUT request to the specified path.

Parameters

  • path : The URL path to request
  • headers : Optional HTTP headers
  • body : Optional request body

Example

put "/example"
response.status_code.should eq 200

[View source]
def response : HTTP::Client::Response #

Returns the response from the last HTTP request.

This method provides access to the HTTP::Client::Response object from the most recent test request. Use it to make assertions about the response status, body, headers, and cookies.

Example

get "/users"

response.status_code.should eq 200
response.body.should contain "John"
response.headers["Content-Type"].should eq "application/json"

Available Response Properties

  • status_code : Int32 - HTTP status code (200, 404, etc.)
  • status : HTTP::Status - Status as enum (HTTP::Status::OK, etc.)
  • body : String - Response body content
  • headers : HTTP::Headers - Response headers
  • cookies : HTTP::Cookies - Response cookies
  • success? : Bool - True if status is 2xx
  • content_type : String? - Content-Type header value

Raises NilAssertionError if called before making a request.


[View source]
def with_session(&) : Nil #

Creates a new session, yields it to the block, and ensures cleanup.

All spec-kemal HTTP requests (get, post, etc.) made within the block will automatically include this session's cookie, simulating an authenticated user.

The session is automatically destroyed when the block exits, even if an exception is raised.

Parameters

Yields a Kemal::Session instance for setting session values.

Example

it "requires login" do
  get "/dashboard"
  response.status_code.should eq 401
end

it "shows dashboard for logged-in user" do
  with_session do |session|
    session.int("user_id", 123)
    session.string("username", "alice")
    session.bool("admin", false)

    get "/dashboard"
    response.status_code.should eq 200
    response.body.should contain "Welcome, alice"
  end
end

Available Session Methods

session.string("key", "value") # Store a String
session.int("key", 42)         # Store an Int32
session.bigint("key", 123_i64) # Store an Int64
session.float("key", 3.14)     # Store a Float64
session.bool("key", true)      # Store a Bool
session.object("key", user)    # Store any JSON-serializable object

Notes

  • The session is destroyed after the block, simulating logout
  • Each with_session call creates a fresh session
  • Nested with_session calls will destroy the outer session

[View source]