diff --git a/examples/config/tests/common/mod.rs b/examples/config/tests/common/mod.rs index 43832aab..77ee8264 100644 --- a/examples/config/tests/common/mod.rs +++ b/examples/config/tests/common/mod.rs @@ -49,6 +49,5 @@ pub fn test_hello() { let mut request = MockRequest::new(Method::Get, "/hello"); let mut response = request.dispatch_with(&rocket); - assert_eq!(response.body().and_then(|b| b.into_string()), - Some("Hello, world!".to_string())); + assert_eq!(response.body_string(), Some("Hello, world!".into())); } diff --git a/examples/content_types/src/tests.rs b/examples/content_types/src/tests.rs index 5e9f5e85..c15ed0f6 100644 --- a/examples/content_types/src/tests.rs +++ b/examples/content_types/src/tests.rs @@ -14,7 +14,7 @@ fn test(method: Method, uri: &str, header: H, status: Status, body: String) let mut response = request.dispatch_with(&rocket); assert_eq!(response.status(), status); - assert_eq!(response.body().and_then(|b| b.into_string()), Some(body)); + assert_eq!(response.body_string(), Some(body)); } #[test] diff --git a/examples/cookies/src/tests.rs b/examples/cookies/src/tests.rs index 0528d963..f979ad54 100644 --- a/examples/cookies/src/tests.rs +++ b/examples/cookies/src/tests.rs @@ -31,7 +31,7 @@ fn test_body(optional_cookie: Option>, expected_body: String) { let mut response = request.dispatch_with(&rocket); assert_eq!(response.status(), Status::Ok); - assert_eq!(response.body().and_then(|b| b.into_string()), Some(expected_body)); + assert_eq!(response.body_string(), Some(expected_body)); } #[test] diff --git a/examples/errors/src/tests.rs b/examples/errors/src/tests.rs index 4cfd4567..9d12e8a2 100644 --- a/examples/errors/src/tests.rs +++ b/examples/errors/src/tests.rs @@ -10,7 +10,7 @@ fn test(uri: &str, status: Status, body: String) { let mut response = req.dispatch_with(&rocket); assert_eq!(response.status(), status); - assert_eq!(response.body().and_then(|b| b.into_string()), Some(body)); + assert_eq!(response.body_string(), Some(body)); } #[test] diff --git a/examples/extended_validation/src/tests.rs b/examples/extended_validation/src/tests.rs index 8d096be4..db4f91ad 100644 --- a/examples/extended_validation/src/tests.rs +++ b/examples/extended_validation/src/tests.rs @@ -17,7 +17,7 @@ fn test_login(user: &str, pass: &str, age: &str, status: Status, body: T) let mut response = req.dispatch_with(&rocket); assert_eq!(response.status(), status); - let body_str = response.body().and_then(|body| body.into_string()); + let body_str = response.body_string(); if let Some(expected_str) = body.into() { assert!(body_str.map_or(false, |s| s.contains(expected_str))); } diff --git a/examples/forms/src/tests.rs b/examples/forms/src/tests.rs index 65b33677..0ef8b559 100644 --- a/examples/forms/src/tests.rs +++ b/examples/forms/src/tests.rs @@ -12,7 +12,7 @@ fn test_login(username: &str, password: &str, age: isize, status: Status, .body(&format!("username={}&password={}&age={}", username, password, age)); let mut response = req.dispatch_with(&rocket); - let body_str = response.body().and_then(|body| body.into_string()); + let body_str = response.body_string(); println!("Checking: {:?}/{:?}/{:?}/{:?}", username, password, age, body_str); assert_eq!(response.status(), status); diff --git a/examples/from_request/src/main.rs b/examples/from_request/src/main.rs index f9d4d813..ec613a7c 100644 --- a/examples/from_request/src/main.rs +++ b/examples/from_request/src/main.rs @@ -50,7 +50,7 @@ mod test { let mut response = req.dispatch_with(&rocket); let expect = format!("Your request contained {} headers!", headers.len()); - assert_eq!(response.body().and_then(|b| b.into_string()), Some(expect)); + assert_eq!(response.body_string(), Some(expect)); } #[test] diff --git a/examples/handlebars_templates/src/tests.rs b/examples/handlebars_templates/src/tests.rs index c72a116b..ddce9328 100644 --- a/examples/handlebars_templates/src/tests.rs +++ b/examples/handlebars_templates/src/tests.rs @@ -34,14 +34,12 @@ fn test_root() { for method in &[Post, Put, Delete, Options, Trace, Connect, Patch] { let req = MockRequest::new(*method, "/"); run_test!(req, |mut response: Response| { - assert_eq!(response.status(), Status::NotFound); - let mut map = ::std::collections::HashMap::new(); map.insert("path", "/"); - let expected = Template::render("error/404", &map).to_string(); + let expected_body = Template::render("error/404", &map).to_string(); - let body_string = response.body().and_then(|body| body.into_string()); - assert_eq!(body_string, Some(expected)); + assert_eq!(response.status(), Status::NotFound); + assert_eq!(response.body_string(), Some(expected_body)); }); } } @@ -59,8 +57,7 @@ fn test_name() { }; let expected = Template::render("index", &context).to_string(); - let body_string = response.body().and_then(|body| body.into_string()); - assert_eq!(body_string, Some(expected)); + assert_eq!(response.body_string(), Some(expected)); }); } @@ -74,8 +71,6 @@ fn test_404() { let mut map = ::std::collections::HashMap::new(); map.insert("path", "/hello/"); let expected = Template::render("error/404", &map).to_string(); - - let body_string = response.body().and_then(|body| body.into_string()); - assert_eq!(body_string, Some(expected)); + assert_eq!(response.body_string(), Some(expected)); }); } diff --git a/examples/hello_alt_methods/src/tests.rs b/examples/hello_alt_methods/src/tests.rs index 1703900f..47cd1d6e 100644 --- a/examples/hello_alt_methods/src/tests.rs +++ b/examples/hello_alt_methods/src/tests.rs @@ -12,7 +12,7 @@ fn test(method: Method, status: Status, body_prefix: Option<&str>) { assert_eq!(response.status(), status); if let Some(expected_body_string) = body_prefix { - let body_str = response.body().and_then(|body| body.into_string()).unwrap(); + let body_str = response.body_string().unwrap(); assert!(body_str.starts_with(expected_body_string)); } } diff --git a/examples/hello_person/src/tests.rs b/examples/hello_person/src/tests.rs index e7768534..2bd6dbc4 100644 --- a/examples/hello_person/src/tests.rs +++ b/examples/hello_person/src/tests.rs @@ -7,8 +7,7 @@ fn test(uri: &str, expected: String) { let rocket = rocket::ignite().mount("/", routes![super::hello, super::hi]); let mut req = MockRequest::new(Get, uri); let mut response = req.dispatch_with(&rocket); - - assert_eq!(response.body().and_then(|b| b.into_string()), Some(expected)); + assert_eq!(response.body_string(), Some(expected)); } fn test_404(uri: &str) { diff --git a/examples/hello_ranks/src/tests.rs b/examples/hello_ranks/src/tests.rs index 22ed979f..66e4afed 100644 --- a/examples/hello_ranks/src/tests.rs +++ b/examples/hello_ranks/src/tests.rs @@ -5,10 +5,8 @@ use rocket::http::Method::*; fn test(uri: &str, expected: String) { let rocket = rocket::ignite().mount("/", routes![super::hello, super::hi]); let mut req = MockRequest::new(Get, uri); - let mut response = req.dispatch_with(&rocket); - let body_str = response.body().and_then(|body| body.into_string()); - assert_eq!(body_str, Some(expected)); + assert_eq!(response.body_string(), Some(expected)); } #[test] diff --git a/examples/hello_tls/src/tests.rs b/examples/hello_tls/src/tests.rs index 94b54e03..abb31f89 100644 --- a/examples/hello_tls/src/tests.rs +++ b/examples/hello_tls/src/tests.rs @@ -8,6 +8,5 @@ fn hello_world() { let mut req = MockRequest::new(Get, "/"); let mut response = req.dispatch_with(&rocket); - let body_str = response.body().and_then(|body| body.into_string()); - assert_eq!(body_str, Some("Hello, world!".to_string())); + assert_eq!(response.body_string(), Some("Hello, world!".into())); } diff --git a/examples/hello_world/src/tests.rs b/examples/hello_world/src/tests.rs index 94b54e03..abb31f89 100644 --- a/examples/hello_world/src/tests.rs +++ b/examples/hello_world/src/tests.rs @@ -8,6 +8,5 @@ fn hello_world() { let mut req = MockRequest::new(Get, "/"); let mut response = req.dispatch_with(&rocket); - let body_str = response.body().and_then(|body| body.into_string()); - assert_eq!(body_str, Some("Hello, world!".to_string())); + assert_eq!(response.body_string(), Some("Hello, world!".into())); } diff --git a/examples/manual_routes/src/tests.rs b/examples/manual_routes/src/tests.rs index 452bdcb9..2c964c91 100644 --- a/examples/manual_routes/src/tests.rs +++ b/examples/manual_routes/src/tests.rs @@ -9,7 +9,7 @@ fn test(uri: &str, content_type: ContentType, status: Status, body: String) { let mut response = request.dispatch_with(&rocket); assert_eq!(response.status(), status); - assert_eq!(response.body().and_then(|b| b.into_string()), Some(body)); + assert_eq!(response.body_string(), Some(body)); } #[test] @@ -50,7 +50,7 @@ fn test_upload() { let mut request = MockRequest::new(Get, "/upload"); let mut response = request.dispatch_with(&rocket); assert_eq!(response.status(), Status::Ok); - assert_eq!(response.body().and_then(|b| b.into_string()), Some(expected_body)); + assert_eq!(response.body_string(), Some(expected_body)); } #[test] diff --git a/examples/optional_redirect/src/tests.rs b/examples/optional_redirect/src/tests.rs index c8680f1d..6dc38077 100644 --- a/examples/optional_redirect/src/tests.rs +++ b/examples/optional_redirect/src/tests.rs @@ -9,8 +9,7 @@ fn test_200(uri: &str, expected_body: &str) { let mut response = request.dispatch_with(&rocket); assert_eq!(response.status(), Status::Ok); - assert_eq!(response.body().and_then(|b| b.into_string()), - Some(expected_body.to_string())); + assert_eq!(response.body_string(), Some(expected_body.to_string())); } fn test_303(uri: &str, expected_location: &str) { diff --git a/examples/optional_result/src/tests.rs b/examples/optional_result/src/tests.rs index f3d79148..5d63fcfd 100644 --- a/examples/optional_result/src/tests.rs +++ b/examples/optional_result/src/tests.rs @@ -9,8 +9,7 @@ fn test_200() { let mut response = request.dispatch_with(&rocket); assert_eq!(response.status(), Status::Ok); - assert_eq!(response.body().and_then(|b| b.into_string()), - Some("Hello, Sergio!".to_string())); + assert_eq!(response.body_string(), Some("Hello, Sergio!".into())); } #[test] diff --git a/examples/query_params/src/tests.rs b/examples/query_params/src/tests.rs index 0ac9a887..2a194ed5 100644 --- a/examples/query_params/src/tests.rs +++ b/examples/query_params/src/tests.rs @@ -16,45 +16,44 @@ macro_rules! run_test { #[test] fn age_and_name_params() { - run_test!("?age=10&name=john", |mut response: Response| { - let body_str = response.body().and_then(|body| body.into_string()); - assert_eq!(body_str, Some("Hello, 10 year old named john!".to_string())); - }); + run_test!("?age=10&name=john", |mut response: Response| { + assert_eq!(response.body_string(), + Some("Hello, 10 year old named john!".into())); + }); } #[test] fn age_param_only() { - run_test!("?age=10", |response: Response| { - assert_eq!(response.status(), Status::NotFound); - }); + run_test!("?age=10", |response: Response| { + assert_eq!(response.status(), Status::NotFound); + }); } #[test] fn name_param_only() { - run_test!("?name=John", |mut response: Response| { - let body_str = response.body().and_then(|body| body.into_string()); - assert_eq!(body_str, Some("Hello John!".to_string())); - }); + run_test!("?name=John", |mut response: Response| { + assert_eq!(response.body_string(), Some("Hello John!".into())); + }); } #[test] fn no_params() { - run_test!("", |response: Response| { - assert_eq!(response.status(), Status::NotFound); - }); + run_test!("", |response: Response| { + assert_eq!(response.status(), Status::NotFound); + }); - run_test!("?", |response: Response| { - assert_eq!(response.status(), Status::NotFound); - }); + run_test!("?", |response: Response| { + assert_eq!(response.status(), Status::NotFound); + }); } #[test] fn non_existent_params() { - run_test!("?x=y", |response: Response| { - assert_eq!(response.status(), Status::NotFound); - }); + run_test!("?x=y", |response: Response| { + assert_eq!(response.status(), Status::NotFound); + }); - run_test!("?age=10&name=john&complete=true", |response: Response| { - assert_eq!(response.status(), Status::NotFound); - }); + run_test!("?age=10&name=john&complete=true", |response: Response| { + assert_eq!(response.status(), Status::NotFound); + }); } diff --git a/examples/raw_sqlite/src/tests.rs b/examples/raw_sqlite/src/tests.rs index 4f290935..9fda4e0f 100644 --- a/examples/raw_sqlite/src/tests.rs +++ b/examples/raw_sqlite/src/tests.rs @@ -8,6 +8,5 @@ fn hello() { let mut req = MockRequest::new(Get, "/"); let mut response = req.dispatch_with(&rocket); - let body_str = response.body().and_then(|body| body.into_string()); - assert_eq!(body_str, Some("Rocketeer".to_string())); + assert_eq!(response.body_string(), Some("Rocketeer".into())); } diff --git a/examples/redirect/src/tests.rs b/examples/redirect/src/tests.rs index f14e85eb..9a80c074 100644 --- a/examples/redirect/src/tests.rs +++ b/examples/redirect/src/tests.rs @@ -31,8 +31,8 @@ fn test_root() { #[test] fn test_login() { run_test!("/login", |mut response: Response| { - let body_string = response.body().and_then(|body| body.into_string()); - assert_eq!(body_string, Some("Hi! Please log in before continuing.".to_string())); + assert_eq!(response.body_string(), + Some("Hi! Please log in before continuing.".to_string())); assert_eq!(response.status(), Status::Ok); }); } diff --git a/examples/state/src/tests.rs b/examples/state/src/tests.rs index 7986d52a..5ab86781 100644 --- a/examples/state/src/tests.rs +++ b/examples/state/src/tests.rs @@ -12,8 +12,7 @@ fn register_hit(rocket: &Rocket) { fn get_count(rocket: &Rocket) -> usize { let mut req = MockRequest::new(Get, "/count"); let mut response = req.dispatch_with(&rocket); - let body_string = response.body().and_then(|b| b.into_string()).unwrap(); - body_string.parse().unwrap() + response.body_string().and_then(|s| s.parse().ok()).unwrap() } #[test] diff --git a/examples/testing/src/main.rs b/examples/testing/src/main.rs index 0ca16f63..e2eb6530 100644 --- a/examples/testing/src/main.rs +++ b/examples/testing/src/main.rs @@ -25,8 +25,6 @@ mod test { let mut req = MockRequest::new(Get, "/"); let mut response = req.dispatch_with(&rocket); assert_eq!(response.status(), Status::Ok); - - let body_string = response.body().and_then(|b| b.into_string()); - assert_eq!(body_string, Some("Hello, world!".to_string())); + assert_eq!(response.body_string(), Some("Hello, world!".into())); } } diff --git a/examples/uuid/src/tests.rs b/examples/uuid/src/tests.rs index 47d4011e..0d1640cc 100644 --- a/examples/uuid/src/tests.rs +++ b/examples/uuid/src/tests.rs @@ -9,7 +9,7 @@ fn test(uri: &str, expected: &str) { let mut req = MockRequest::new(Get, uri); let mut res = req.dispatch_with(&rocket); - assert_eq!(res.body().and_then(|b| b.into_string()), Some(expected.into())); + assert_eq!(res.body_string(), Some(expected.into())); } fn test_404(uri: &str) { diff --git a/lib/src/response/responder.rs b/lib/src/response/responder.rs index d8b0ebd7..5af34fd6 100644 --- a/lib/src/response/responder.rs +++ b/lib/src/response/responder.rs @@ -173,9 +173,7 @@ pub trait Responder<'r> { /// use rocket::http::ContentType; /// /// let mut response = "Hello".respond().unwrap(); -/// -/// let body_string = response.body().and_then(|b| b.into_string()); -/// assert_eq!(body_string, Some("Hello".to_string())); +/// assert_eq!(response.body_string(), Some("Hello".into())); /// /// let content_type: Vec<_> = response.headers().get("Content-Type").collect(); /// assert_eq!(content_type.len(), 1); diff --git a/lib/src/response/response.rs b/lib/src/response/response.rs index 156b9237..2b436975 100644 --- a/lib/src/response/response.rs +++ b/lib/src/response/response.rs @@ -829,10 +829,7 @@ impl<'r> Response<'r> { /// assert!(response.body().is_none()); /// /// response.set_sized_body(Cursor::new("Hello, world!")); - /// - /// let body_string = response.body().and_then(|b| b.into_string()); - /// assert_eq!(body_string, Some("Hello, world!".to_string())); - /// assert!(response.body().is_some()); + /// assert_eq!(response.body_string(), Some("Hello, world!".to_string())); /// ``` #[inline(always)] pub fn body(&mut self) -> Option> { @@ -846,6 +843,29 @@ impl<'r> Response<'r> { } } + /// Consumes `self's` body and reads it into a string. If `self` doesn't + /// have a body, reading fails, or string conversion (for non-UTF-8 bodies) + /// fails, returns `None`. Note that `self`'s `body` is consumed after a + /// call to this method. + /// + /// # Example + /// + /// ```rust + /// use std::io::Cursor; + /// use rocket::Response; + /// + /// let mut response = Response::new(); + /// assert!(response.body().is_none()); + /// + /// response.set_sized_body(Cursor::new("Hello, world!")); + /// assert_eq!(response.body_string(), Some("Hello, world!".to_string())); + /// assert!(response.body().is_none()); + /// ``` + #[inline(always)] + pub fn body_string(&mut self) -> Option { + self.take_body().and_then(|b| b.into_string()) + } + /// Moves the body of `self` out and returns it, if there is one, leaving no /// body in its place. /// @@ -901,9 +921,7 @@ impl<'r> Response<'r> { /// /// let mut response = Response::new(); /// response.set_sized_body(Cursor::new("Hello, world!")); - /// - /// let body_string = response.body().and_then(|b| b.into_string()); - /// assert_eq!(body_string, Some("Hello, world!".to_string())); + /// assert_eq!(response.body_string(), Some("Hello, world!".to_string())); /// ``` #[inline] pub fn set_sized_body(&mut self, mut body: B) @@ -929,9 +947,7 @@ impl<'r> Response<'r> { /// /// let mut response = Response::new(); /// response.set_streamed_body(repeat(97).take(5)); - /// - /// let body_string = response.body().and_then(|b| b.into_string()); - /// assert_eq!(body_string, Some("aaaaa".to_string())); + /// assert_eq!(response.body_string(), Some("aaaaa".to_string())); /// ``` #[inline(always)] pub fn set_streamed_body(&mut self, body: B) where B: io::Read + 'r { @@ -949,9 +965,7 @@ impl<'r> Response<'r> { /// /// let mut response = Response::new(); /// response.set_chunked_body(repeat(97).take(5), 10); - /// - /// let body_string = response.body().and_then(|b| b.into_string()); - /// assert_eq!(body_string, Some("aaaaa".to_string())); + /// assert_eq!(response.body_string(), Some("aaaaa".to_string())); /// ``` #[inline(always)] pub fn set_chunked_body(&mut self, body: B, chunk_size: u64) @@ -974,8 +988,7 @@ impl<'r> Response<'r> { /// let mut response = Response::new(); /// response.set_raw_body(body); /// - /// let body_string = response.body().and_then(|b| b.into_string()); - /// assert_eq!(body_string, Some("Hello!".to_string())); + /// assert_eq!(response.body_string(), Some("Hello!".to_string())); /// ``` #[inline(always)] pub fn set_raw_body(&mut self, body: Body) { diff --git a/lib/src/testing.rs b/lib/src/testing.rs index a7e71eb8..733d00ff 100644 --- a/lib/src/testing.rs +++ b/lib/src/testing.rs @@ -96,11 +96,8 @@ //! let mut req = MockRequest::new(Get, "/"); //! let mut response = req.dispatch_with(&rocket); //! -//! // Write the body out as a string. -//! let body_str = response.body().and_then(|b| b.into_string()); -//! -//! // Check that the body contains what we expect. -//! assert_eq!(body_str, Some("Hello, world!".to_string())); +//! // Check that the body contains the string we expect. +//! assert_eq!(response.body_string(), Some("Hello, world!".into())); //! } //! } //! ``` @@ -260,8 +257,7 @@ impl<'r> MockRequest<'r> { /// let mut req = MockRequest::new(Get, "/"); /// let mut response = req.dispatch_with(&rocket); /// - /// let body_str = response.body().and_then(|b| b.into_string()); - /// assert_eq!(body_str, Some("Hello, world!".to_string())); + /// assert_eq!(response.body_string(), Some("Hello, world!".into())); /// # } /// ``` pub fn dispatch_with<'s>(&'s mut self, rocket: &'r Rocket) -> Response<'s> { diff --git a/lib/tests/form_method-issue-45.rs b/lib/tests/form_method-issue-45.rs index 2189484a..0100dfae 100644 --- a/lib/tests/form_method-issue-45.rs +++ b/lib/tests/form_method-issue-45.rs @@ -32,8 +32,7 @@ mod tests { .body("_method=patch&form_data=Form+data"); let mut response = req.dispatch_with(&rocket); - let body_str = response.body().and_then(|b| b.into_string()); - assert_eq!(body_str, Some("OK".to_string())); + assert_eq!(response.body_string(), Some("OK".into())); } #[test] diff --git a/lib/tests/form_value_decoding-issue-82.rs b/lib/tests/form_value_decoding-issue-82.rs index 69e8817c..32e5260b 100644 --- a/lib/tests/form_value_decoding-issue-82.rs +++ b/lib/tests/form_value_decoding-issue-82.rs @@ -30,9 +30,8 @@ mod tests { .body(format!("form_data={}", raw)); let mut response = req.dispatch_with(&rocket); - let body_string = response.body().and_then(|b| b.into_string()); assert_eq!(response.status(), Status::Ok); - assert_eq!(Some(decoded.to_string()), body_string); + assert_eq!(Some(decoded.to_string()), response.body_string()); } #[test] diff --git a/lib/tests/precise-content-type-matching.rs b/lib/tests/precise-content-type-matching.rs index 2bcc9a20..8a717555 100644 --- a/lib/tests/precise-content-type-matching.rs +++ b/lib/tests/precise-content-type-matching.rs @@ -48,7 +48,7 @@ mod tests { } let mut response = req.dispatch_with(&rocket); - let body_str = response.body().and_then(|b| b.into_string()); + let body_str = response.body_string(); let body: Option<&'static str> = $body; match body { Some(string) => assert_eq!(body_str, Some(string.to_string())), diff --git a/lib/tests/query-and-non-query-dont-collide.rs b/lib/tests/query-and-non-query-dont-collide.rs index a7fff33f..45105251 100644 --- a/lib/tests/query-and-non-query-dont-collide.rs +++ b/lib/tests/query-and-non-query-dont-collide.rs @@ -29,13 +29,11 @@ mod tests { fn assert_no_collision(rocket: &Rocket) { let mut req = MockRequest::new(Get, "/?field=query"); let mut response = req.dispatch_with(&rocket); - let body_str = response.body().and_then(|b| b.into_string()); - assert_eq!(body_str, Some("query".to_string())); + assert_eq!(response.body_string(), Some("query".into())); let mut req = MockRequest::new(Get, "/"); let mut response = req.dispatch_with(&rocket); - let body_str = response.body().and_then(|b| b.into_string()); - assert_eq!(body_str, Some("no query".to_string())); + assert_eq!(response.body_string(), Some("no query".into())); } #[test] diff --git a/lib/tests/remote-rewrite.rs b/lib/tests/remote-rewrite.rs index 56c99402..4ef8b494 100644 --- a/lib/tests/remote-rewrite.rs +++ b/lib/tests/remote-rewrite.rs @@ -33,7 +33,7 @@ mod remote_rewrite_tests { let mut response = req.dispatch_with(&rocket); assert_eq!(response.status(), Status::Ok); - let body_str = response.body().and_then(|b| b.into_string()); + let body_str = response.body_string(); match ip { Some(ip) => assert_eq!(body_str, Some(format!("{}:{}", ip, port))), None => assert_eq!(body_str, Some(KNOWN_IP.into())) diff --git a/lib/tests/segments-issues-41-86.rs b/lib/tests/segments-issues-41-86.rs index ff61f75b..834b92e1 100644 --- a/lib/tests/segments-issues-41-86.rs +++ b/lib/tests/segments-issues-41-86.rs @@ -52,8 +52,7 @@ mod tests { let mut req = MockRequest::new(Get, format!("{}/{}", prefix, path)); let mut response = req.dispatch_with(&rocket); - let body_str = response.body().and_then(|b| b.into_string()); - assert_eq!(body_str, Some(path.into())); + assert_eq!(response.body_string(), Some(path.into())); } } }