Releases: lipanski/mockito
Releases Β· lipanski/mockito
1.5.0
1.4.0
1.3.1
1.3.0
- Introduced
Server::new_with_opts
,Server::new_with_opts_async
and theServerOpts
struct to allow configuring the server host, port and enabling auto-asserts (see next item) - Added the
assert_on_drop
server option that allows you to automatically callassert()
whenever your mocks go out of scope (defaults to false) - Expose
Server::socket_address()
to return the raw serverSocketAddr
- Use only required features for dependencies
- Accept
hyper::header::HeaderValue
as amatch_header()
value
Thanks to @andrewtoth @alexander-jackson
1.2.0
- [Breaking] The minimum supported Rust version was bumped to 1.68.0
- The server pool was limited to 20 servers for
mac_os
targets to prevent hitting the file descriptor limit
Thanks to @kornelski
1.1.1
1.1.0
- Enable the server pool properly and set the server pool size to 50
1.0.2
- Print the query part in last unmatched request diffs.
- Make it more obvious in the docs that the path includes the query element.
1.0.1
- Fixed an issue where
futures::future::join_all
would block the server pool. Server::reset_async
has been deprecated in favour ofServer::reset
since the former doesn't have an async implementation any more.
1.0.0
π 7 years and 63 releases later, it's finally time for the 1.0 π
Changes
- [Breaking] The legacy interface was removed in this version
- [Breaking]
Mock::with_body_from_fn
was renamed toMock::with_chunked_body
- the former is still supported with a deprecation warning - Mocks are only cleared when the server is dropped, not when the mock is dropped - this means you don't have to assign mocks to variables any more (unless you want to call other methods on them)
- Introduced the
Mock::remove
andMock::remove_async
methods to remove mocks on demand
Major changes since 0.31
- Tests can now run in parallel
- Support for HTTP2
- An async interface for all actions (though the sync interface is also available)
- Mock multiple server/hosts at the same time
For a list of all the changes please check the release log.
Migrating to the new API
Legacy API:
let m1 = mockito::mock("GET", "/hello").with_body("hello").create();
let m2 = mockito::mock("GET", "/bye").with_body("bye").create();
// Use one of these to configure your client
let host = mockito:server_address();
let url = mockito::server_url();
New API:
let mut server = mockito::Server::new();
server.mock("GET", "/hello").with_body("hello").create();
server.mock("GET", "/bye").with_body("bye").create();
// Use one of these to configure your client
let host = server.host_with_port();
let url = server.url();
If you can't migrate to the new API in one go, consider using version 0.32.5, which supports both the legacy API as well as the new API.
Migrating to the async API
In order to write async tests, you'll need to use the _async
methods:
Server::new_async
Mock::create_async
Mock::assert_async
Mock::matched_async
Mock::remove_async
Server::reset_async
...otherwise your tests will not compile and you'll see this error:
Cannot block the current thread from within a runtime. This happens because a function attempted
to block the current thread while the thread is being used to drive asynchronous tasks.
Example:
#[tokio::test]
async fn test_simple_route_mock_async() {
let mut server = Server::new_async().await;
let m1 = server.mock("GET", "/a").with_body("aaa").create_async().await;
let m2 = server.mock("GET", "/b").with_body("bbb").create_async().await;
let (m1, m2) = futures::join!(m1, m2);
// You can use `Mock::assert_async` to verify that your mock was called
// m1.assert_async().await;
// m2.assert_async().await;
}