Skip to content

Commit

Permalink
Rename Mock::with_body_from_fn to Mock::with_chunked_body
Browse files Browse the repository at this point in the history
  • Loading branch information
lipanski committed Mar 11, 2023
1 parent ed338fa commit 5a7c96e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,17 +319,28 @@ 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 {
self.inner.response.body = Body::FnWithWriter(Arc::new(callback));
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.
///
Expand Down
2 changes: 1 addition & 1 deletion tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
Expand Down

0 comments on commit 5a7c96e

Please sign in to comment.