alexliesenfeld / httpmock

HTTP mocking library for Rust.
MIT License
435 stars 40 forks source link

Overwrite mocks #94

Open RichoDemus opened 8 months ago

RichoDemus commented 8 months ago

I'd like the ability to overwrite a previously defined mock if I define a new one with the same "when" like this:

self.mock_server.mock(|when, then| { when.method(GET) .path("/api/")); then.status(200).json_body(json!({ "msg": "A" })); });

now a call to /api returns msg: A

then I do self.mock_server.mock(|when, then| { when.method(GET) .path("/api/")); then.status(200).json_body(json!({ "msg": "B" })); });

now a call to /api returns msg:B

currently it seems like the only way is to delete the old mock first which is a bit cumbersome imo

alexliesenfeld commented 5 months ago

I see, thanks for your suggestion!