feat(mocktail): show argument diffs on verify mismatch failures - #273
Open
theprantadutta wants to merge 1 commit into
Open
feat(mocktail): show argument diffs on verify mismatch failures#273theprantadutta wants to merge 1 commit into
theprantadutta wants to merge 1 commit into
Conversation
Author
|
Gentle bump @felangel — this is ready for review whenever you have a moment. It adds argument diffs to |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Status
READY
Breaking Changes
NO — the richer message is only appended when a call to the same member (with the same shape) mismatches on a long/multiline string or a larger collection. For small values the failure message is byte-for-byte identical to today's, and the existing mockito-compat test suite passes unchanged.
Description
Implements the string diffs discussed in #208, following @renancaraujo's suggestion to reuse
package:matcher'sdescribeMismatch(I proposed this plan on the issue on May 22).When
verifyfinds no matching call, mocktail now looks for the closest unverified call — same member, same positional arity / named keys / type arguments, fewest mismatched arguments — and appends a per-argument mismatch description produced by the sameMatcherthat failed the comparison (equals(value)for concrete values, the wrapped matcher forany(that: ...)).For the exact scenario from the issue (a long log message that differs only by trailing whitespace), the failure goes from a wall of text you have to eyeball twice, to:
Mid-string differences get
package:matcher's windowed diff with the^marker andDiffer at offset N; collections get the mismatched index/key (was <9> instead of <4> at location [3]).To keep noise down (and existing messages stable), the diff section only triggers when a mismatched value is "large": a string that is multiline or longer than 40 chars, or a collection with more than 5 elements. Small values keep the current short form, since the plain call listing already makes those differences obvious. Both thresholds are constants — happy to tune them or always show the diff if you'd prefer.
Fixes #208
Type of Change