Skip to main content

Crate larust_testing

Crate larust_testing 

Source
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§

SentMail
Laravel’s Mail::fake()/assertSent() - re-exported directly from larust-mail (not through larust_support::mail, which is the production facade apps see; calling fake() from real app code would silently and permanently stop that process from ever sending real mail again). See larust_mail::fake’s own doc comments for the full design rationale. A rendered, already-sent (recorded, not dispatched) email - the output of a Mailable, not the typed instance itself. Recording the instance would require Mailable: 'static, which would force every Mailable (including the real WelcomeMail<'a>, which borrows its User) to own its data instead of borrowing - a breaking constraint this design avoids entirely.
TestClient
Drives a real axum::Router in-process (via tower::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 a Request by hand, extracting Set-Cookie, and re-attaching it to every subsequent call.
TestResponse
A TestClient response with the body already buffered into an owned String - every existing hand-rolled test in this codebase repeats the same axum::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 from larust-mail (not through larust_support::mail, which is the production facade apps see; calling fake() from real app code would silently and permanently stop that process from ever sending real mail again). See larust_mail::fake’s own doc comments for the full design rationale. Panics if any recorded M satisfies predicate. Same lock-then-drop- before-asserting shape as assert_sent, for the same reason.
assert_sent
Laravel’s Mail::fake()/assertSent() - re-exported directly from larust-mail (not through larust_support::mail, which is the production facade apps see; calling fake() from real app code would silently and permanently stop that process from ever sending real mail again). See larust_mail::fake’s own doc comments for the full design rationale. Panics unless at least one recorded M satisfies predicate.
fake
Laravel’s Mail::fake()/assertSent() - re-exported directly from larust-mail (not through larust_support::mail, which is the production facade apps see; calling fake() from real app code would silently and permanently stop that process from ever sending real mail again). See larust_mail::fake’s own doc comments for the full design rationale. Activates recording - every send() call for the rest of this process records instead of dispatching (log/smtp), regardless of mail_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 test already compiles each tests/*.rs file 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 (not DatabaseTransactions - see below): runs body against a brand-new, freshly migrated, fully isolated SQLite database that nothing else ever touches. Unlike test_db() (additive, one shared database across every #[tokio::test] fn in the same test binary), each test_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