Skip to main content

Module fake

Module fake 

Source
Expand description

Queue::fake() — a queue that records instead of running.

Application tests need this far more than they need a real queue. What a controller test wants to know is “did registering a user dispatch the welcome email?”, not “does the welcome email work?” — that is the job’s own test. So the fake accepts pushes, remembers them, and never hands anything to a worker.

ⓘ
let queue = fake();
client.post("/register", &[("email", "ada@example.com")]).await.assert_ok();
queue.assert_pushed("send-welcome-email");

The assertions panic with a message that lists what was pushed, because “assertion failed” on its own leaves you re-running the test with print statements.

Structs§

FakeQueue
A queue that records dispatches and runs nothing.

Functions§

fake
The Rust spelling of Laravel’s Queue::fake().