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

Mock: Add diff to output when no exact match found #335

Merged
merged 1 commit into from
Sep 24, 2016

Conversation

dominicbarnes
Copy link
Contributor

I use this library a lot, but even still I find the output generated when the expected arguments don't match to be incredibly difficult to use when you are dealing with non-trivial values like structs.

This PR adds one more section to the output, it will find the first argument that has any differences and print a diff. (logic lifted directly from the assert package) This goes a long way in making it easier to quickly identify differences and iterate.

@ernesto-jimenez
Copy link
Member

Hey @dominicbarnes, sorry it took me so long to get to your PR. I've been crazy busy this summer.

Can you post the output before and after the changes?

@dominicbarnes
Copy link
Contributor Author

Here's a really simple example, so it probably doesn't show off the usefulness as well as a more complicated struct. (but I think it demonstrates the change pretty clearly)

Before:

mock: Unexpected Method Call
-----------------------------

Test_Mock_AssertExpectations_With_Repeatability(map[string]string)
        0: map[string]string{"b":"B"}

The closest call I have is: 

Test_Mock_AssertExpectations_With_Repeatability(map[string]string)
        0: map[string]string{"a":"A"}

After:

mock: Unexpected Method Call
-----------------------------

Test_Mock_AssertExpectations_With_Repeatability(map[string]string)
        0: map[string]string{"b":"B"}

The closest call I have is: 

Test_Mock_AssertExpectations_With_Repeatability(map[string]string)
        0: map[string]string{"a":"A"}

Difference found in argument 0:

--- Expected
+++ Actual
@@ -1,3 +1,3 @@
 (map[string]string) (len=1) {
- (string) (len=1) "b": (string) (len=1) "B"
+ (string) (len=1) "a": (string) (len=1) "A"
 }

@ernesto-jimenez ernesto-jimenez merged commit dfaf6b8 into stretchr:master Sep 24, 2016
jonnyreeves pushed a commit to jonnyreeves/testify that referenced this pull request Jan 5, 2017
Mock: Add diff to output when no exact match found
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

Successfully merging this pull request may close these issues.

2 participants