Top Level Namespace
Included Modules
- Spec::Expectations
- Spec::Methods
Extended Modules
- Spec::Expectations
- Spec::Methods
Defined in:
Method Summary
-
connect_websocket(path : String, headers : HTTP::Headers | Nil = nil, sec_key : String | Nil = nil, origin : String | Nil = nil, &block : HTTP::WebSocket -> Nil) : Nil
Duplex WebSocket: runs Kemal ws code on a real connection, then gives you a client [HTTP::WebSocket].
-
delete(path : String, headers : HTTP::Headers | Nil = nil, body : String | Nil = nil) : HTTP::Client::Response
Sends a DELETE request to the specified path.
-
get(path : String, headers : HTTP::Headers | Nil = nil, body : String | Nil = nil) : HTTP::Client::Response
Sends a GET request to the specified path.
-
get(path : String, headers : HTTP::Headers | Nil = nil, body : String | Nil = nil, *, websocket : Bool) : HTTP::Client::Response
[GET] with a WebSocket-style handshake.
-
head(path : String, headers : HTTP::Headers | Nil = nil, body : String | Nil = nil) : HTTP::Client::Response
Sends a HEAD request to the specified path.
-
options(path : String, headers : HTTP::Headers | Nil = nil, body : String | Nil = nil) : HTTP::Client::Response
Sends a OPTIONS request to the specified path.
-
patch(path : String, headers : HTTP::Headers | Nil = nil, body : String | Nil = nil) : HTTP::Client::Response
Sends a PATCH request to the specified path.
-
post(path : String, headers : HTTP::Headers | Nil = nil, body : String | Nil = nil) : HTTP::Client::Response
Sends a POST request to the specified path.
-
put(path : String, headers : HTTP::Headers | Nil = nil, body : String | Nil = nil) : HTTP::Client::Response
Sends a PUT request to the specified path.
-
response : HTTP::Client::Response
Returns the response from the last HTTP request.
-
websocket_request_headers(sec_key : String | Nil = nil, origin : String | Nil = nil) : HTTP::Headers
Returns headers for a valid WebSocket upgrade request.
-
with_session(&) : Nil
Creates a new session, yields it to the block, and ensures cleanup.
Method Detail
Duplex WebSocket: runs Kemal ws code on a real connection, then gives you a client [HTTP::WebSocket].
The last [response] is the 101 as seen by the client. The block can send and receive messages. After the block, the client WebSocket and connection I/Os are closed.
Sends a DELETE request to the specified path.
Parameters
path: The URL path to requestheaders: Optional HTTP headersbody: Optional request body
Example
delete "/example"
response.status_code.should eq 200
Sends a GET request to the specified path.
Parameters
path: The URL path to requestheaders: Optional HTTP headersbody: Optional request body
Example
get "/example"
response.status_code.should eq 200
[GET] with a WebSocket-style handshake. Merges [websocket_request_headers] when websocket is true
(headers override defaults for duplicate keys).
The response is still in-memory [SpecKemal.process_request] — the ws route handler (e.g. [on_message])
is not run; use [connect_websocket] for that.
Sends a HEAD request to the specified path.
Parameters
path: The URL path to requestheaders: Optional HTTP headersbody: Optional request body
Example
head "/example"
response.status_code.should eq 200
Sends a OPTIONS request to the specified path.
Parameters
path: The URL path to requestheaders: Optional HTTP headersbody: Optional request body
Example
options "/example"
response.status_code.should eq 200
Sends a PATCH request to the specified path.
Parameters
path: The URL path to requestheaders: Optional HTTP headersbody: Optional request body
Example
patch "/example"
response.status_code.should eq 200
Sends a POST request to the specified path.
Parameters
path: The URL path to requestheaders: Optional HTTP headersbody: Optional request body
Example
post "/example"
response.status_code.should eq 200
Sends a PUT request to the specified path.
Parameters
path: The URL path to requestheaders: Optional HTTP headersbody: Optional request body
Example
put "/example"
response.status_code.should eq 200
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 contentheaders : HTTP::Headers- Response headerscookies : HTTP::Cookies- Response cookiessuccess? : Bool- True if status is 2xxcontent_type : String?- Content-Type header value
Raises NilAssertionError if called before making a request.
Returns headers for a valid WebSocket upgrade request.
Use a fixed sec_key for deterministic [Sec-WebSocket-Accept] in assertions, or pass nil to use
[DEFAULT_WEBSOCKET_KEY] (RFC 6455 example value).
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_sessioncall creates a fresh session - Nested
with_sessioncalls will destroy the outer session