Skip to content

Update Rust crate mockito to 0.32 - #16

Open
renovate[bot] wants to merge 1 commit into
masterfrom
renovate/mockito-0.x
Open

Update Rust crate mockito to 0.32#16
renovate[bot] wants to merge 1 commit into
masterfrom
renovate/mockito-0.x

Conversation

@renovate

@renovate renovate Bot commented Aug 21, 2026

Copy link
Copy Markdown

This PR contains the following updates:

Package Type Update Change
mockito dev-dependencies minor 0.20.32

Release Notes

lipanski/mockito (mockito)

v0.32.5

Compare Source

  • Implement and enable a new server pool and get rid of the deadpool dependency
  • Replace the mpsc mock/server communication with Arc (more reliable in this case)
  • Split sync & async paths more clearly

v0.32.4

Compare Source

  • Introduce Mock::with_body_from_request which allows setting the response body dynamically, based on the Request object
  • Small performance improvement: replace the state Mutex with an RwLock
  • Small fixes to the documentation (thanks @​konstin)

v0.32.3

Compare Source

  • Various fixes addressing hanging/flickering tests
  • Server::new and Server::new_async now return a ServerGuard object which dereferences to Server - this is only relevant if you need to assign a type to your server
  • The server pool has been disabled and will be brought back in a future release

v0.32.2

Compare Source

  • Prevent the Mock destructor from hanging in some cases
  • Updates to the docs, clarifying the usage of _async methods

v0.32.1

Compare Source

v0.32.0

Compare Source

This is a major re-write, introducing a bunch of long awaited features:

  • [Breaking] The minimum supported Rust version was bumped to 1.65.0

  • Tests can now run in parallel as long as you use the new mockito::Server API:

    let mut server = mockito::Server::new();
    let mock = server.mock("GET", "/").with_body("test").create();
    
    // Use one of these to configure your client
    let host = server.host_with_port();
    let url = server.url();
  • You can run multiple servers/hosts at the same time:

    let mut twitter = mockito::Server::new();
    let twitter_mock = server.mock("GET", "/api").with_body("tweet").create();
    let twitter_host = twitter.host_with_port();
    
    let mut github = mockito::Server::new();
    let github_mock = server.mock("GET", "/api").with_body("repo").create();
    let github_host = github.host_with_port();
  • Support for HTTP2

  • An async interface for all actions (though the sync interface is also available):

    let mut server = Server::new_async().await;
    let mock = s
        .mock("GET", "/hello")
        .with_body("world")
        .create_async()
        .await;
    
    mock.assert_async().await;
  • The backend has been rewritten to use Hyper

This version will be backwards compatible with the previous version, but deprecation warnings have been introduced and you are encouraged to migrate, since the old API still requires running tests sequentially. Migrating to the new API is quite straighforward:

Migrating to the new API

Legacy API:

let m = mockito::mock("GET", "/").with_body("hello").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();
let m = sever.mock("GET", "/").with_body("hello").create();

// Use one of these to configure your client
let host = server.host_with_port();
let url = server.url();

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
  • Server::reset_async

...otherwise your tests will not compile and you'll see this error: Cannot start a runtime from within a runtime.

When using tokio, prefer the single-threaded runtime over the multi-threaded one.

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;
}

v0.31.1

Compare Source

  • Prevent tests from blocking endlessly when encountering HTTP parsing errors.

Thanks to @​chantra

v0.31.0

Compare Source

  • Replaced the unmaintained difference crate with the similar crate.

Thanks to @​ameliabradley

v0.30.0

Compare Source

  • Update the assert-json-diff dependency.

Thanks to @​davidpdrsn

v0.29.0

Compare Source

Thanks to @​kornelski and @​davidpdrsn

v0.28.0

Compare Source

  • Introduced the Matcher::Binary variant for matching binary content.

Thanks to @​torrefatto

v0.27.0

Compare Source

  • Added a Mock#matched() as a soft way of checking that a Mock, as opposed to the Mock#assert() method, which panics.

Thanks @​max-b

v0.26.0

Compare Source

  • [Breaking] Increased the minimum supported Rust version to 1.36.0.

v0.25.3

Compare Source

  • Fixed and issue where spaces encoded as + wouldn't be interpreted properly by Matcher::UrlEncoded.

Thanks to @​cakekindel

v0.25.2

Compare Source

  • Improve error messages and the String representation of mocks, especially when it comes to their AllOf and AnyOf parts.

Thanks to @​max-b

v0.25.1

Compare Source

  • When creating multiple mocks that match the same request, the last defined mock should be the one matched forever, once the all other mocks have reached their expected amount of hits. See #​99 and 96f3e30

v0.25.0

Compare Source

  • You can provide different mocks (and especially mock responses) for subsequent requests to the same endpoint. See #​99 and b0966f8
  • The 501 Mock Not Implemented response now comes with a content-length: 0 header, to prevent some clients from hanging.

Thanks to @​xneomac

v0.23.3

Compare Source

  • Fix compatibility with the assert-json-diff library (version 1.0.3)

v0.23.2

Compare Source

  • Fix a problem regarding the assert-json-diff library.

Thanks to @​vldm

v0.23.1

Compare Source

  • Set the connection: close header on all responses delivered by Mockito as this is the default behaviour at the moment.

v0.23.0

Compare Source

  • [Breaking] Increased the minimum supported Rust toolchain to 1.35.0.
  • Introduced the Mock#expect_at_least and Mock#expect_at_most functions to be used together with Mock#assert.
  • Bumped the percent-encoding dependency.
  • Introduced cargo fmt formatting as part of CI.

Thanks to @​kornelski @​xneomac @​thomasetter

v0.22.0

Compare Source

  • Applied the Rust 2018 edition.
  • Fixed an issue regarding usage of the AnyOf matcher for the path/query parts within a mock call.

Thanks to @​thomasetter

v0.21.0

Compare Source

  • Introduced a feature flag color (enabled by default), that controls whether the output is coloured and, more importantly, whether the colored crate is required.

Thanks to @​repi

v0.20.0

Compare Source

  • Introduced the Matcher::PartialJson and Matcher::PartialJsonString variants to match a JSON String partially (inclusion).

Thanks to @​matteosister

v0.19.0

Compare Source

  • Introduced the Mock#with_body_from_fn function, which allows generating the response body programmatically.

Thanks to @​kornelski

v0.18.0

Compare Source

  • [Breaking] The minimum supported Rust version was increased to 1.32, after upgrading the rand crate dependency to 0.7.0.
  • Introduced Matcher::AllOf, which can be used to check a set of matchers in conjunction. It works in a similar way to the existing Matcher::AnyOf.
  • Introduced Matcher::UrlEncoded to match key/value pairs in URL-encoded strings.
  • Introduced Mock#match_query to be able to match the URL query part distinctly from the path. The function supports all known matchers but works best with Matcher::UrlEncoded. The old behaviour of matching the query as part of the path argument in a mock call has been preserved, but using Mock#match_query has the effect of overriding that.

🎈 🎈 🎈

v0.17.1

Compare Source

  • Exclude CI & other unrelated files from packaging and turn the binary into an example.

Thanks to @​ignatenkobrain

v0.17.0

Compare Source

  • Support Transfer-Encoding: chunked.

Thanks to @​loyd

v0.16.0

Compare Source

  • Support HTTP/1.0 and working without Content-Length.
  • Allow overriding the Content-Length response header and skipping the response body entirely in the particular case of HEAD requests.

Thanks to @​loyd

v0.15.1

Compare Source

Thanks to @​saks

v0.15.0

Compare Source

  • [Breaking] The mock sever will get a dynamically assigned port, though it will try port 1234 first. You will need to change the way you set the server URL - from mockito::SERVER_URL or mockito::SERVER_ADDRESS to mockito::server_url() or mockito::server_address().

Thanks to @​kornelski

v0.14.1

Compare Source

  • Refactored the server checks - thanks to @​kornelski
  • Debug mode: use the log crate instead of the old custom logger - thanks to @​kornelski
  • Keep compatibility with older toolchains - thanks to @​lucab
  • Introduce clippy - thanks to @​macisamuele

v0.14.0

Compare Source

~~This is the release candidate for the 1.0.0 🎉 ~~

  • [Breaking] Fully deprecated Matcher::JSON, in favour of Matcher::Json.
  • Replace http-muncher with httparse. This fixed the issues regarding the failing Windows tests. See #​51 and #​41
  • Updated dependencies.

Thanks to @​sterlingjensen, @​otavio, @​galaxie and @​mikrostew

v0.13.0

Compare Source

  • Introduced the Matcher::AnyOf variant, which takes a vector of matchers as argument.
  • The Mock::with_body and Mock::with_body_from_file functions now support binary content.
  • Multi-valued headers (e.g. the Via header) are checked over all values. The previous implementation was looking only for the first found header value.
  • Changed the response reason phrase for non-matching requests from 501 Not Implemented to 501 Mock Not Found.
  • Changed the response reason phrase for unparseable requests from 422 Unprocessable Entity to 422 Mock Error.

Thanks to @​kornelski

v0.12.0

Compare Source

  • Introduced a coloured diff, comparing the expected request with the last unmatched request whenver the Mock::assert() method fails. Closes #​23
  • Removed the limitation on the test function name, but also rendered it impossible to create mocks from threads.

v0.11.1

Compare Source

  • Introduced Matcher::JsonString which works similarly to the existing Json matcher, except that it takes a String as an argument. This can be useful for test suites which don't expose serde_json methods.
  • Renamed Matcher::JSON to Matcher::Json and introduced a deprecation warning for the old matcher.
  • Added a debug mode to Mockito, which can be enabled by setting the MOCKITO_DEBUG environment variable before running tests.

v0.11.0

Compare Source

  • Removed the need for running tests with --test-threads=1. Tests containing mocks will still run sequentially, but this is handled internally now. Tests that don't use mocks can be run in parallel. If you're using mocks inside doctests, please check #​36

v0.10.0

Compare Source

  • Bump the serde_json dependency to ^1.0.17, which solves the JSON matcher problems when the preserve_order feature of serde_json is enabled.

Thanks to @​Diggsey

v0.9.1

Compare Source

  • Fixed compiler warnings because of useless mut.

Thanks to @​jean553

v0.9.0

Compare Source

  • Introduced the Matcher::JSON variant for matching JSON request bodies.

Thanks to @​andir

v0.8.2

Compare Source

  • Fixed a bug where tests wouldn't run without the --test-threads=1 flag any more.

Thanks to @​estin

v0.8.1

Compare Source

  • Fixed a bug where the status reason phrase was missing from the server response. This was causing problems with mocking requests that went through Hyper.

v0.8.0

Compare Source

  • Rewrote part of the internal implementation of Mockito, replacing the client/server approach with a singleton state controlled through a mutex. Long story short, this removed the need for curl and serde as dependencies and significantly improved the response time.

v0.7.2

Compare Source

  • The Mock#assert error message now prints out the last unmatched request as well:
    Expected 1 request(s) to:
    
    POST /users
    bob
    
    ...but received 0
    
    The last unmatched request was:
    
    POST /users
    content-length: 5
    alice
    
  • Turned request headers into Vec, instead of HashMap to solve the sorting problem once and for all.
  • Namespaced the internal API with /mockito.

v0.7.1

Compare Source

  • Introduced the Mock#match_body method for matching the request body by using the usual Matcher variants.

v0.7.0

Compare Source

  • Introduced the Mock#assert method to assert that a mock was called. You can use Mock#expect to specify the number of requests you're expecting. Check the docs for more details.
  • [Breaking] Mocks will be automatically cleaned up whenever their lifetime ends. This is the more Rusty approach to having to call Mock#remove or reset explicitly. You'll want to assign your mock to a variable in order to establish its lifetime. Check the docs for examples.
  • [Breaking] The Mock#remove method has been removed (or better said, it's private now). You can use std::mem::drop if you really need to remove a mock before its lifetime ends.
  • [Breaking] The Mock#create_for method has been removed. Normal Rust closures { ... } and the lifetimes should replace this just fine.
  • [Breaking] Builder-pattern methods of the Mock struct are now returning Mock instead of &mut Mock.
  • Established clearer boundries between the mock server and the mock client.

v0.6.0

Compare Source

  • Introduce a new matcher: Match::Regex(String), for matching the request path or headers with a regular expression.
  • Extend the matcher logic to matching the request path (supports all matchers now).
  • Fix a bug in the request processing for large bodies.

Thanks to @​estin

v0.5.0

Compare Source

  • Replaced hyper with curl + http-muncher: resulted in a significant speed improvement and support for Windows.

v0.4.2

Compare Source

  • Fix a bug where response headers were unordered & duplicate header field names were not allowed.

Thanks to @​alyssais

v0.4.1

Compare Source

  • Run the mock server on 127.0.0.1 (instead of 0.0.0.0).

Thanks to @​alyssais

v0.4.0

Compare Source

  • Update serde suite to v1.
  • Rewrite internal server to talk JSON (via serde).
  • Expose the mockito::start() method so Mockito can be used as a standalone mock server (API documentation on that is missing though).

v0.3.0

Compare Source

  • Introduced advanced header matchers: Matcher::Any to match only by the field name and Matcher::Missing to match the absence of a particular header. These are used within the Mock::match_header call.
  • The old behaviour of matching the header value by &str was kept backwards compatible.

Configuration

📅 Schedule: (UTC)

  • Branch creation
    • At any time (no schedule defined)
  • Automerge
    • At any time (no schedule defined)

🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about this update again.


  • If you want to rebase/retry this PR, check this box

This PR was generated by Mend Renovate. View the repository job log.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants