class Bezel::Testing::Client
A browser for tests: requests to one endpoint (the Host
www.example.com), keeping the cookies the responses set (a Max-Age
of zero or less deletes one; Expires is not read), sending them with
the next.
c = Bezel::Testing::Client.new(TApp)
c.post("/login", params: {"email" => "ann@example.com", "password" => "secret"})
c.flash[:info] # => "Welcome": the next request shows it, and takes it
c.follow_redirect
c.session["user_id"] # => "1"
Class methods
def self.new(endpoint: Type[Bezel::Endpoint], app: Bezel::App = …, *, session_key: String? = …) -> Bezel::Testing::Client
A client of endpoint in app; session_key names the session's
cookie (found by itself among the cookies otherwise: the one that
decrypts).
def self.remove_dots(path: String) -> String
path without its . and .. segments (RFC 3986 §5.2.4).
def self.expired?(set_cookie: String) -> Bool
Whether a Set-Cookie value deletes its cookie: its last valid
Max-Age (an optional - and digits; another value is ignored, RFC
6265) is zero or less.
Methods
def cookies -> Hash[String, String]
The cookies kept, by name.
def last_target -> String
The target of the last request (/users?page=2), which relative
redirects resolve against.
def last? -> HTTP::Server::Response?
The last response, or nil before any request.
def last -> HTTP::Server::Response
The last response.
def get(path: String, *, params: Hash[String, String | Array[String]] = …, headers: Hash[String, String] = …) -> HTTP::Server::Response
A GET of path (params added to its query).
def post(path: String, *, params: Hash[String, String | Array[String]] = …, json: JSON::Value? = …, headers: Hash[String, String] = …) -> HTTP::Server::Response
A POST of params as a form, or of json as a JSON body.
def put(path: String, *, params: Hash[String, String | Array[String]] = …, json: JSON::Value? = …, headers: Hash[String, String] = …) -> HTTP::Server::Response
A PUT: post's arguments.
def patch(path: String, *, params: Hash[String, String | Array[String]] = …, json: JSON::Value? = …, headers: Hash[String, String] = …) -> HTTP::Server::Response
A PATCH: post's arguments.
def delete(path: String, *, params: Hash[String, String | Array[String]] = …, json: JSON::Value? = …, headers: Hash[String, String] = …) -> HTTP::Server::Response
A DELETE: post's arguments.
def follow_redirect(res: HTTP::Server::Response = …) -> HTTP::Server::Response
A GET of where res redirects to, resolved as a browser does against
the last request's target (?page=2, edit, ../x,
//www.example.com/x, http://www.example.com:80/x; an empty or
fragment-only location is the last target again), dot segments
removed; Test::AssertionFailed for another host or a location that
is no HTTP one (mailto:). The fragment is dropped.
def request(method: String, target: String, body: String = …, headers: Hash[String, String] = …) -> HTTP::Server::Response
A request of method to target with body and headers (the
cookies and a Host added).
def session -> Hash[String, String]
The session's values, as the application last saved them (empty without a session cookie that decrypts).
def flash -> Hash[Symbol, String]
The flash the next request will see.
def login_as(values: Hash[String, String]) -> Void
Logs in as an application that keeps its user in the session does:
the session's cookie written with values added ({"user_id" => "7"}), as if a login had put them. Needs the session's cookie name:
session_key:, or a response that set it.
def session_key -> String?
The session cookie's name: given, else the first cookie that decrypts as a session.