From 5a7c96eaecb2c160ceb6cddaa26eec2fb7e27ac0 Mon Sep 17 00:00:00 2001 From: Florin Lipan Date: Sat, 11 Mar 2023 16:26:36 +0100 Subject: [PATCH] Rename Mock::with_body_from_fn to Mock::with_chunked_body --- src/mock.rs | 15 +++++++++++++-- tests/lib.rs | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/mock.rs b/src/mock.rs index 6802fdc..b749a86 100644 --- a/src/mock.rs +++ b/src/mock.rs @@ -319,10 +319,10 @@ impl Mock { /// ``` /// let mut s = mockito::Server::new(); /// - /// let _m = s.mock("GET", "/").with_body_from_fn(|w| w.write_all(b"hello world")); + /// let _m = s.mock("GET", "/").with_chunked_body(|w| w.write_all(b"hello world")); /// ``` /// - pub fn with_body_from_fn( + pub fn with_chunked_body( mut self, callback: impl Fn(&mut dyn io::Write) -> io::Result<()> + Send + Sync + 'static, ) -> Self { @@ -330,6 +330,17 @@ impl Mock { self } + /// + /// **DEPRECATED:** Replaced by `Mock::with_chunked_body`. + /// + #[deprecated(since = "1.0.0", note = "Use `Mock::with_chunked_body` instead")] + pub fn with_body_from_fn( + self, + callback: impl Fn(&mut dyn io::Write) -> io::Result<()> + Send + Sync + 'static, + ) -> Self { + self.with_chunked_body(callback) + } + /// /// Sets the body of the mock response dynamically while exposing the request object. /// diff --git a/tests/lib.rs b/tests/lib.rs index 6ade4d3..669225d 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -625,7 +625,7 @@ fn test_mock_with_fn_body() { let mut s = Server::new(); let _m = s .mock("GET", "/") - .with_body_from_fn(|w| { + .with_chunked_body(|w| { w.write_all(b"hel")?; w.write_all(b"lo") })