pub struct TestResponse { /* private fields */ }Expand description
One response, with its body already read.
The body is collected on construction so every assertion can be &self and
chain. A streaming body can only be read once, and a harness that made you
think about that would be a harness that made you think about the wrong
thing.
Implementations§
Source§impl TestResponse
impl TestResponse
Sourcepub fn status(&self) -> StatusCode
pub fn status(&self) -> StatusCode
The status.
Sourcepub fn json(&self) -> Value
pub fn json(&self) -> Value
The body as JSON.
§Panics
If it will not parse — printing what arrived, because that is nearly always an error response the test did not expect.
Sourcepub fn json_as<T: DeserializeOwned>(&self) -> T
pub fn json_as<T: DeserializeOwned>(&self) -> T
Sourcepub fn assert_status(&self, expected: StatusCode) -> &Self
pub fn assert_status(&self, expected: StatusCode) -> &Self
Panic unless the status is exactly this.
§Panics
If it is not — printing the body, which is where the reason is.
Sourcepub fn assert_created(&self) -> &Self
pub fn assert_created(&self) -> &Self
Sourcepub fn assert_no_content(&self) -> &Self
pub fn assert_no_content(&self) -> &Self
Sourcepub fn assert_not_found(&self) -> &Self
pub fn assert_not_found(&self) -> &Self
Sourcepub fn assert_forbidden(&self) -> &Self
pub fn assert_forbidden(&self) -> &Self
Sourcepub fn assert_invalid(&self) -> &Self
pub fn assert_invalid(&self) -> &Self
Sourcepub fn assert_json_path(&self, path: &str, expected: impl Into<Value>) -> &Self
pub fn assert_json_path(&self, path: &str, expected: impl Into<Value>) -> &Self
Panic unless the JSON at path equals expected.
path is dotted, and an index is a segment: data.0.title.
§Panics
If the path is absent or holds something else.
Sourcepub fn assert_json_missing(&self, path: &str) -> &Self
pub fn assert_json_missing(&self, path: &str) -> &Self
Panic unless there is nothing at path.
For asserting a field was not serialised — a password hash, an internal id.
§Panics
If something is there.
Sourcepub fn assert_contains(&self, text: &str) -> &Self
pub fn assert_contains(&self, text: &str) -> &Self
Sourcepub fn assert_header(&self, name: &str, expected: &str) -> &Self
pub fn assert_header(&self, name: &str, expected: &str) -> &Self
Sourcepub fn assert_header_missing(&self, name: &str) -> &Self
pub fn assert_header_missing(&self, name: &str) -> &Self
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§
impl<T> Actor for T
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> Event for T
impl<T> Event for T
Source§fn event_name() -> &'static strwhere
Self: Sized,
fn event_name() -> &'static strwhere
Self: Sized,
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