Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to assert on received request? #152

Open
mawkler opened this issue Nov 11, 2024 · 0 comments
Open

Is it possible to assert on received request? #152

mawkler opened this issue Nov 11, 2024 · 0 comments

Comments

@mawkler
Copy link

mawkler commented Nov 11, 2024

Hi! I would like to assert on the received request body of a mock, but can't figure out how to acheive this.

To illustrate, let's say that I want to verify that a specific mock has received a request body that matches:

{
  "foo": "bar"
}

I tried to do this with Matchers:

let expected_body = json!({ "foo": "bar" });

wiremock::Mock::given(method("POST"))
    .and(wiremock::matchers::path("/foo"))
    .and(body_json(expected_body));

, but it seems that the mock now simply returns 404 if the body doesn't match. This does fail the test, but it fails it in a very subtle way. I would like for my tests to fail more explicitly with a message like "Mock received incorrect body ..." from assert_eq!.

I tried creating my custom Matcher that asserts on the body, but then I realized that since the mock runs in a totally separate process from the tests, this will just crash the mock server, which fails the test in an arguably even more subtle way.

I could check MockServer::received_requests, but this returns all requests for the entire test, which means that I have to somehow figure out which request was received by which mock.

Is there a better way to acheive this that I'm missing?

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

No branches or pull requests

1 participant