Expand description
Test helpers for Larust apps - an HTTP test client, actingAs-style
auth simulation, and a per-test-binary migrated database - added as a
[dev-dependencies] entry, never shipped to production.
Structs§
- Sent
Mail - Laravel’s
Mail::fake()/assertSent()- re-exported directly fromlarust-mail(not throughlarust_support::mail, which is the production facade apps see; callingfake()from real app code would silently and permanently stop that process from ever sending real mail again). Seelarust_mail::fake’s own doc comments for the full design rationale. A rendered, already-sent (recorded, not dispatched) email - the output of aMailable, not the typed instance itself. Recording the instance would requireMailable: 'static, which would force every Mailable (including the realWelcomeMail<'a>, which borrows itsUser) to own its data instead of borrowing - a breaking constraint this design avoids entirely. - Test
Client - Drives a real
axum::Routerin-process (viatower::ServiceExt::oneshot- no TCP binding) and automatically threads the session cookie between requests, eliminating the boilerplate every hand-rolled test in this codebase repeats: building aRequestby hand, extractingSet-Cookie, and re-attaching it to every subsequent call. - Test
Response - A
TestClientresponse with the body already buffered into an ownedString- every existing hand-rolled test in this codebase repeats the sameaxum::body::to_bytes(...).await.unwrap().to_vec()+String::from_utf8(...).unwrap()dance at nearly every assertion site; this does it once, at construction, instead.
Functions§
- assert_
not_ sent - Laravel’s
Mail::fake()/assertSent()- re-exported directly fromlarust-mail(not throughlarust_support::mail, which is the production facade apps see; callingfake()from real app code would silently and permanently stop that process from ever sending real mail again). Seelarust_mail::fake’s own doc comments for the full design rationale. Panics if any recordedMsatisfiespredicate. Same lock-then-drop- before-asserting shape asassert_sent, for the same reason. - assert_
sent - Laravel’s
Mail::fake()/assertSent()- re-exported directly fromlarust-mail(not throughlarust_support::mail, which is the production facade apps see; callingfake()from real app code would silently and permanently stop that process from ever sending real mail again). Seelarust_mail::fake’s own doc comments for the full design rationale. Panics unless at least one recordedMsatisfiespredicate. - fake
- Laravel’s
Mail::fake()/assertSent()- re-exported directly fromlarust-mail(not throughlarust_support::mail, which is the production facade apps see; callingfake()from real app code would silently and permanently stop that process from ever sending real mail again). Seelarust_mail::fake’s own doc comments for the full design rationale. Activates recording - everysend()call for the rest of this process records instead of dispatching (log/smtp), regardless ofmail_driver. Idempotent: a second call in the same process is a no-op (first-writer-wins, matching every other process-wide registry in this codebase -larust_orm::connect(), the route-name registry, the event-listener registry). The recorded list from the first activation keeps accumulating; nothing resets it. - test_db
- Connects to a fresh, migrated SQLite database for tests (Rust’s own
natural test-isolation boundary:
cargo testalready compiles eachtests/*.rsfile as a separate process, so this is one database per test file, not per test function - every#[tokio::test]fn in the same file shares it). - test_
transaction - Laravel’s
RefreshDatabase(notDatabaseTransactions- see below): runsbodyagainst a brand-new, freshly migrated, fully isolated SQLite database that nothing else ever touches. Unliketest_db()(additive, one shared database across every#[tokio::test]fn in the same test binary), eachtest_transaction()call gets its own dedicated database file and doesn’t need the “one test per file” workaround every other process-wide mechanism in this crate relies on