LukeMathWalker / LukeMathWalker/wiremock-rs

Named mocks

Open
#92 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
799
Forks
91
PR merge metrics
No merged PRs in 30d

Description

Hello,

Can you evaluate the following proposal?

If you agree, I can provide a PR.

## Proposal

This issue aims to propose a named mock.

## use case

Currently, mock expectations are verified once the wiremock server goes out of scope.

However, there are situations where we need to verify if side effects have happened before a wiremock server has the chance to go out of scope.

One (but not the only one) example is when a domain driven design test model is being used. For example, cucumber style tests need to verify if something has happened before the test ends, in a then function.

There are also situations where one wiremock server is used to support several tests running sequentially.

To support these use cases, we propose the creation of named mocks.

### Named mock

A named mock shares several characteristics of the classical mock. It however:

* has a unique name
* expectations are not checked on wiremock server drop.
* can be retrieved at any moment from the named mocks repository, maintained by the wiremock server.
* holds a copy of the matched (s) request (s).
* provides a get_matches_count() method bringing the amount of matched requests.
* provides a get_matched_requests() method which returns a read only vector of references of the matched requests.
* is deleted from the wiremock server repository of named mocks when reset() is called on the wiremock server.

## side effects

This addition will not break usage for those who are already using this project, while enabling other use cases.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the proposal and the existing mock and Wiremock server APIs, which are not identified in the issue. Define how named mocks are created, retrieved, matched, counted, and reset, while preserving existing behavior. Done means the design is agreed and the named-mock use cases are covered by appropriate tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.