dennisdoomen / dennisdoomen/mockly

Report which criterion failed (and a body diff) in the closest-matching-mock message

Open
#182 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
C#
Stars
40
Forks
9
Avg merge
2d 1h
Merged PRs (30d)
13

Description

## Motivation

The "closest matching mock" report (added via #55 / #71) is already one of Mockly's best features. It tells you *which* mock came closest, but not *why* it failed. With several near-identical mocks — same method and path, differing only in a header or a body field — you still have to eyeball two long URLs and a JSON blob to spot the difference.

## Proposed improvement

Report the outcome per matching criterion, and diff the body:

```
Unexpected request to:
POST https://api.example.com/api/users

Closest matching mock:
POST https://*/api/users
method ✓ POST
scheme/host ✓ api.example.com
path ✓ /api/users
query ✓ (none)
header ✗ expected "X-Tenant: acme" but the request had no such header
body ✗ expected { "role": "Admin" } but found { "role": "User" }
```

Plus a way to dump the whole conversation on failure, for the cases where the mismatch is not on a single request:

```csharp
output.WriteLine(mock.GetTrafficReport());
```

## Notes

- The scoring logic to find the closest mock already exists; this is mostly about recording *why* each criterion failed while scoring, instead of only the score.
- The body diff should reuse whatever `WithBodyEquivalentTo` already produces (#54), so the wording stays consistent.
- `GetTrafficReport()` is a small public API addition; the improved message is not.

Contributor guide

Open the contributing guide

Research direction

Start by tracing the existing closest-mock scoring logic and the WithBodyEquivalentTo body comparison, which the issue identifies as the source for consistent diff wording. Map how the score becomes the closest-mock message, then define coverage for per-criterion failures, body diffs, and the public GetTrafficReport() output. Done means the report explains mismatches and the conversation can be dumped on failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api, testing-qa
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.