pub struct TestResponse { /* private fields */ }Expand description
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.
Implementations§
Source§impl TestResponse
impl TestResponse
pub fn status(&self) -> StatusCode
pub fn body(&self) -> &str
pub fn header(&self, name: &str) -> Option<&str>
Sourcepub fn csrf_token(&self) -> Option<String>
pub fn csrf_token(&self) -> Option<String>
Scrapes the hidden _csrf_token field’s value out of the response
body (reuses larust_http::csrf::FIELD_NAME rather than a
hardcoded string), for a test that fetched a form page and now
needs the token to submit it via crate::TestClient::post_form -
the exact manual step every CSRF-protected test in this codebase
performed by hand before this crate existed.
Sourcepub fn meta_csrf_token(&self) -> Option<String>
pub fn meta_csrf_token(&self) -> Option<String>
Scrapes the CSRF token out of the shared layout’s
<meta name="csrf-token" content="..."> tag instead of a hidden
form field - for a page with no @csrf-rendered <form> at all
(e.g. one whose only interaction is a JS-driven fetch(), like a
@wire(...)-mounted component’s wire:model/wire:submit sync),
the same way the real client runtime
(crates/larust-live/assets/wire-runtime.js) itself reads it.
Sourcepub fn assert_status(&self, expected: StatusCode) -> &Self
pub fn assert_status(&self, expected: StatusCode) -> &Self
Panics (with the actual vs. expected status in the message) unless
the response has expected’s status - matching this codebase’s
plain assert!/assert_eq! style, just packaged for chaining.
Sourcepub fn assert_redirect_to(&self, path: &str) -> &Self
pub fn assert_redirect_to(&self, path: &str) -> &Self
Asserts a 3xx status whose Location header equals path exactly
(Laravel’s assertRedirect($path)).
Sourcepub fn assert_body_contains(&self, needle: &str) -> &Self
pub fn assert_body_contains(&self, needle: &str) -> &Self
Asserts the response body contains needle (Laravel’s
assertSee($text)).
Auto Trait Implementations§
impl Forget for TestResponse
impl Freeze for TestResponse
impl Move for TestResponse
impl RefUnwindSafe for TestResponse
impl Send for TestResponse
impl Sync for TestResponse
impl Unpin for TestResponse
impl UnsafeUnpin for TestResponse
impl UnwindSafe for TestResponse
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more