pub struct TestResponse {
pub status: StatusCode,
pub headers: HeaderMap,
pub body: Vec<u8>,
}Fields§
§status: StatusCode§headers: HeaderMap§body: Vec<u8>Raw response body bytes — binary-safe. Prefer the body_bytes /
body_text accessors over reading this field directly so test code
reads symmetric with the other helpers.
Implementations§
Source§impl TestResponse
impl TestResponse
pub fn assert_status(&self, expected: u16) -> &Self
pub fn assert_ok(&self) -> &Self
pub fn assert_created(&self) -> &Self
pub fn assert_no_content(&self) -> &Self
pub fn assert_bad_request(&self) -> &Self
pub fn assert_forbidden(&self) -> &Self
pub fn assert_not_found(&self) -> &Self
pub fn assert_unprocessable(&self) -> &Self
pub fn assert_too_many_requests(&self) -> &Self
pub fn assert_server_error(&self) -> &Self
pub fn assert_redirect(&self) -> &Self
pub fn assert_redirect_to(&self, location: &str) -> &Self
pub fn assert_header(&self, name: &str, value: &str) -> &Self
pub fn assert_header_present(&self, name: &str) -> &Self
pub fn assert_header_missing(&self, name: &str) -> &Self
pub fn header(&self, name: &str) -> Option<String>
Sourcepub fn body_bytes(&self) -> &[u8] ⓘ
pub fn body_bytes(&self) -> &[u8] ⓘ
Raw response body — binary-safe. Use this for CBOR / protobuf /
msgpack / anything else that isn’t UTF-8 text. The body_text
accessor lossy-decodes via String::from_utf8_lossy and replaces
invalid sequences with U+FFFD, which silently corrupts binary
payloads and breaks downstream decoders.
pub fn body_text(&self) -> String
Sourcepub fn assert_body_bytes(&self, expected: impl AsRef<[u8]>) -> &Self
pub fn assert_body_bytes(&self, expected: impl AsRef<[u8]>) -> &Self
Assert the raw body equals expected byte-for-byte. Use for binary
protocols where assert_body (UTF-8) would mangle the comparison.
pub fn json<T: DeserializeOwned>(&self) -> T
pub fn json_value(&self) -> Value
pub fn assert_contains(&self, needle: &str) -> &Self
pub fn assert_dont_contain(&self, needle: &str) -> &Self
Sourcepub fn assert_see(&self, text: &str) -> &Self
pub fn assert_see(&self, text: &str) -> &Self
Laravel-style alias for assert_contains.
pub fn assert_dont_see(&self, text: &str) -> &Self
Sourcepub fn assert_json(&self, expected: Value) -> &Self
pub fn assert_json(&self, expected: Value) -> &Self
Assert the response is JSON and equals the given value.
Sourcepub fn assert_json_path(&self, path: &str, expected: Value) -> &Self
pub fn assert_json_path(&self, path: &str, expected: Value) -> &Self
Assert a dot-path inside the JSON body equals expected.
Example: assert_json_path("data.user.name", json!("Alice")).
Sourcepub fn assert_json_fragment(&self, subset: Value) -> &Self
pub fn assert_json_fragment(&self, subset: Value) -> &Self
Assert the JSON body contains every key/value in subset (recursive
partial match — extra fields are ignored).
Sourcepub fn assert_validation_error(&self, field: &str) -> &Self
pub fn assert_validation_error(&self, field: &str) -> &Self
Assert the JSON body’s errors.<field> array contains an error.
Pairs with Anvilforge’s validation error shape.
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
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