Skip to content

Mock

A handle to the mocks one Server.mock call registered.

One call may register several items; this handle covers all of them, and its methods act on the whole set.

Methods

received() -> Array[Request]

Every request any of this handle's mocks matched, in the order received.

Example

server.mock
  - method: POST
    path: /users
    respond:
      status: 201
  do |handle|
    http.post (server.url / "/users") body: hello
    let reqs = handle.received()
    assert_eq $reqs.len 1
    assert_eq $reqs[0].method "POST"

unmount()

Unmounts every mock this handle registered, so they match nothing further.

Unmounting already-unmounted mocks does nothing.

verify()

Re-checks every expect: this handle's items carry against the requests received so far.

This is the check a scoped mock block runs on exit, available early.

Errors

Raises when any item's expect: is unsatisfied. The message lists every unsatisfied item, one per line.