Top Level Namespace
Included Modules
- Spec::Expectations
- Spec::Methods
Extended Modules
- Spec::Expectations
- Spec::Methods
Defined in:
Method Summary
-
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.
-
head(path : String, headers : HTTP::Headers | Nil = nil, body : String | Nil = nil) : HTTP::Client::Response
Sends a HEAD 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.
-
with_session(&) : Nil
Creates a new session, yields it to the block, and ensures cleanup.
Method Detail
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
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 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.
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