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"

src/testing.qz:154

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).

src/testing.qz:168

def self.remove_dots(path: String) -> String

path without its . and .. segments (RFC 3986 §5.2.4).

src/testing.qz:239

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.

src/testing.qz:352

Methods

def cookies -> Hash[String, String]

The cookies kept, by name.

src/testing.qz:171

def last_target -> String

The target of the last request (/users?page=2), which relative redirects resolve against.

src/testing.qz:175

def last? -> HTTP::Server::Response?

The last response, or nil before any request.

src/testing.qz:178

def last -> HTTP::Server::Response

The last response.

src/testing.qz:181

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).

src/testing.qz:184

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.

src/testing.qz:190

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.

src/testing.qz:194

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.

src/testing.qz:198

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.

src/testing.qz:202

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.

src/testing.qz:211

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).

src/testing.qz:259

def session -> Hash[String, String]

The session's values, as the application last saved them (empty without a session cookie that decrypts).

src/testing.qz:283

def flash -> Hash[Symbol, String]

The flash the next request will see.

src/testing.qz:294

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.

src/testing.qz:309

def session_key -> String?

The session cookie's name: given, else the first cookie that decrypts as a session.

src/testing.qz:323