-
Notifications
You must be signed in to change notification settings - Fork 29
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
Integrate with sinon match #48
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a few questions and suggestions. I also didn't see the value in a few of the changes.
return obj1 === obj2; | ||
} | ||
return obj1.test(obj2); | ||
return obj2.test(obj1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were any changes in this file necessary? It seems like you just switched variable names, but I'm not seeing the why.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. It's easier to see if you review each commit individually. I had to introduce this check on top of the previous one to make these new test cases pass:
samsam/lib/sinon-match-integration.test.js
Lines 50 to 62 in 2760e75
context("samsam.deepEqual", function() { | |
it("returns true if matching boolean", function() { | |
assert.isTrue(samsam.deepEqual(false, match.bool)); | |
}); | |
it("returns true when matching nested matcher", function() { | |
assert.isTrue(samsam.deepEqual({ x: 1 }, { x: match.number })); | |
}); | |
it("returns false when not matching nested matcher", function() { | |
assert.isFalse(samsam.deepEqual({ x: 1 }, { x: match.string })); | |
}); | |
}); |
It then occurred to me, that we can have the same simple solution as before with the tests still passing if we swapped the variable names.
@@ -54,7 +54,7 @@ function isMatcher(object) { | |||
return isPrototypeOf(matcher, object); | |||
} | |||
|
|||
function matchObject(expectation, actual) { | |||
function matchObject(actual, expectation) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this change made? Was it necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it wasn't strictly necessary, but I had to change the order of actual
/ expected
in other places and I thought it should be consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sinonMatch
was created as stepping stone to get us to where we needed to go. This PR tidies up everything nicely, but still leaves that behind. Would you mind renaming the file to something that no longer references sinon
?
6d840c8
to
dcc0e30
Compare
I renamed |
If we're happy, we can either just squash the whole PR, or I can rebase to clean it up a little – if you think some refactoring history makes it easier to follow. |
Kind of important question: The behavior of |
* Integrate sinon.match with samsam.match * Integrate samsam.match with samsam.deepEqual * Simplify deepEqualCyclic by swapping actual and expected * Order exported functions alphabetically * More consistent formatting in test case * Group positive and negative tests * Rename sinon-match.js to matcher.js
I thought changing the order of the params was a breaking change, no? |
@fearphage Yes. It became very obvious when I tried to integrate with Sinon :) (see here) |
@mantoni Does switching the order of the params here provide some value that I'm not seeing? It seems to make more work and provide zero additional value from my external point of view. Please feel free to correct me though. |
@fearphage The only value that I can see myself is consistency with I agreed with Morgan that we'll be releasing these changes as a major anyway, regardless of the parameter ordering. Otherwise we might run into issues when integrating this with Sinon. Also, the matcher awareness of All of this work was merged into |
Ok, that makes sense. |
Pull Request Test Coverage Report for Build 192
💛 - Coveralls |
* Integrate sinon.match with samsam.match * Integrate samsam.match with samsam.deepEqual * Simplify deepEqualCyclic by swapping actual and expected * Order exported functions alphabetically * More consistent formatting in test case * Group positive and negative tests * Rename sinon-match.js to matcher.js
This is a solution for sinonjs/referee#29, merging
samsam.match
withsinon.match
and integrating the whole thing withsamsam.deepEqual
. This is based on the work done in #36.I was dancing around this for a few days now trying a few approaches that lead to huge changes. It turns out to be quite straight forward to integrate everything without even breaking any existing behavior (look ma, no test cases changed).
How this works:
sinon.match
is not a matching function likesamsam.match
, it's a matcher factory function. It is therefore now exported as a new APIsamsam.createMatcher
.samsam.createMatcher
still exposes allsinon.match.*
APIs, so this can be imported by Sinon and shouldn't require any further changes.samsam.match
is kept as is and allsinon.match.*
functions are assigned to it. This means thatsinon.match.string
andsamsam.match.string
will be the same function.samsam.deepEqual
is integrated withsamsam.match
through thedeepEqual.use(...)
API. For the sinon matchers to work, a small code change was needed to check if the second argument is a matcher.I believeThis can be simplified by changingdeepEqual
calls insinon-match
by swapping the arguments (deepEqual(actual, expectation)
instead ofdeepEqual(expectation, actual)
).The last point is actually optional. We could decide that calling libraries like
referee
could integratedeepEqual
andmatch
. Opinions anyone?How to verify - mandatory
npm install
npm t
Checklist for author
npm run lint
passes