pub struct TestResponse {
pub status: StatusCode,
pub headers: HeaderMap,
pub body: Bytes,
pub view: Option<String>,
}Expand description
A response with Laravel-style assertions; they panic with the status and
the start of the body, and return &Self so they can be chained.
Fields§
§status: StatusCodeThe response status.
headers: HeaderMapThe response headers.
body: BytesThe response body, read in full.
view: Option<String>The template the page was rendered from, if it was a view.
Implementations§
Source§impl TestResponse
impl TestResponse
Sourcepub fn json<T: DeserializeOwned>(&self) -> T
pub fn json<T: DeserializeOwned>(&self) -> T
The body as JSON; panics if it isn’t.
Sourcepub fn header(&self, name: &str) -> Option<&str>
pub fn header(&self, name: &str) -> Option<&str>
The value of header name; None when it’s missing or not text.
Sourcepub fn assert_status(&self, expected: u16) -> &Self
pub fn assert_status(&self, expected: u16) -> &Self
Panics unless the status is expected.
Sourcepub fn assert_not_found(&self) -> &Self
pub fn assert_not_found(&self) -> &Self
Panics unless the status is 404.
Sourcepub fn assert_forbidden(&self) -> &Self
pub fn assert_forbidden(&self) -> &Self
Panics unless the status is 403.
Panics unless the status is 401.
Sourcepub fn assert_redirect(&self, to: &str) -> &Self
pub fn assert_redirect(&self, to: &str) -> &Self
A 3xx redirect whose Location is to.
Sourcepub fn assert_hx_redirect(&self, to: &str) -> &Self
pub fn assert_hx_redirect(&self, to: &str) -> &Self
An HX-Redirect to to (HTMX requests).
Sourcepub fn assert_see(&self, text: &str) -> &Self
pub fn assert_see(&self, text: &str) -> &Self
The body contains text (as written, e.g. already HTML-escaped).
Sourcepub fn assert_dont_see(&self, text: &str) -> &Self
pub fn assert_dont_see(&self, text: &str) -> &Self
Panics if the body contains text (as written, e.g. already HTML-escaped).
Sourcepub fn assert_view(&self, name: &str) -> &Self
pub fn assert_view(&self, name: &str) -> &Self
Panics unless the page was rendered from name (e.g.
"products/index.html").
Sourcepub fn json_path(&self, path: &str) -> Value
pub fn json_path(&self, path: &str) -> Value
The value at path in the JSON body: keys and indexes separated by
dots (data.0.name); null when it isn’t there.
Sourcepub fn assert_json_path(&self, path: &str, expected: impl Serialize) -> &Self
pub fn assert_json_path(&self, path: &str, expected: impl Serialize) -> &Self
Panics unless the JSON body has expected at path
(assert_json_path("data.0.name", "Coffee")).
Sourcepub fn assert_json(&self, expected: Value) -> &Self
pub fn assert_json(&self, expected: Value) -> &Self
Panics unless the JSON body contains expected: every key of an
object in expected must be there with that value (other keys may be
too); arrays must match item by item.
Sourcepub fn assert_header(&self, name: &str, value: &str) -> &Self
pub fn assert_header(&self, name: &str, value: &str) -> &Self
Panics unless header name is exactly value.
Sourcepub fn assert_invalid(&self, field: &str) -> &Self
pub fn assert_invalid(&self, field: &str) -> &Self
A 422 validation response (HTMX or JSON) with an error for field.
Trait Implementations§
Source§impl Clone for TestResponse
impl Clone for TestResponse
Auto Trait Implementations§
impl !Freeze 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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