class
Amber::Testing::ContextBuilder
- Amber::Testing::ContextBuilder
- Reference
- Object
Overview
Builds HTTP::Server::Context objects for testing without a real HTTP server.
Uses a builder pattern so you can chain calls to configure the request
before calling #build to produce the context.
context = Amber::Testing::ContextBuilder.new
.method("POST")
.path("/users")
.header("Content-Type", "application/json")
.json_body({name: "Alice"})
.build
Defined in:
amber/testing/context_builder.crConstructors
Instance Method Summary
-
#body(b : String) : self
Set the request body as a raw string.
-
#build : HTTP::Server::Context
Build and return the HTTP::Server::Context.
-
#build_with_io : Tuple(HTTP::Server::Context, IO::Memory)
Build and return a tuple of {context, io} so callers can read the raw response bytes from the IO after processing.
-
#header(key : String, value : String) : self
Add a single header to the request.
-
#json_body(data) : self
Set the request body as JSON and automatically set the Content-Type header.
-
#method(m : String) : self
Set the HTTP method (GET, POST, PUT, PATCH, DELETE, etc.)
-
#params(p : Hash(String, String)) : self
Add multiple query parameters from a hash.
-
#path(p : String) : self
Set the request path.
-
#query_param(key : String, value : String) : self
Add a query parameter that will be appended to the path.
Constructor Detail
Instance Method Detail
Build and return the HTTP::Server::Context. The context is backed by an IO::Memory so the response can be read back after processing.
Build and return a tuple of {context, io} so callers can read the raw response bytes from the IO after processing.
Set the request body as JSON and automatically set the Content-Type header.
Set the HTTP method (GET, POST, PUT, PATCH, DELETE, etc.)
Add multiple query parameters from a hash.
Add a query parameter that will be appended to the path.