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

Start checking arity on arg comparisons #34

Merged
merged 3 commits into from
Oct 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions lib/args-match.coffee
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
_ = require('lodash')

module.exports = (expectedArgs, actualArgs) ->
return true if _.eq(expectedArgs, actualArgs)
return false if expectedArgs.length != actualArgs.length
satisfiesEqualityPlusAnyArgumentMatchers(expectedArgs, actualArgs)

satisfiesEqualityPlusAnyArgumentMatchers = (expectedArgs, actualArgs) ->
_.eq expectedArgs, actualArgs, (expected, actual) ->
return true if _.eq(expectedArgs, actualArgs)
_.all expectedArgs, (expectedArg, i) ->
return true if _.eq(expectedArg, actualArgs[i])
if _.isFunction(expectedArg?.__matches)
expectedArg.__matches(actualArgs[i])
else
false
argumentMatchesExpectation(expectedArg, actualArgs[i])

argumentMatchesExpectation = (expectedArg, actualArg) ->
if _.eq(expectedArg, actualArg)
true
else if matcher = matcherHidingInExpectedArgument(expectedArg)
matcher(actualArg)
else
false

# This is literally all that's needed to implement argument matchers & captors
matcherHidingInExpectedArgument = (expectedArg) ->
if _.isFunction(expectedArg?.__matches)
expectedArg.__matches
12 changes: 12 additions & 0 deletions test/lib/verify-test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ describe '.verify', ->
- called with `("the wrong WOAH")`.
"""

context 'unsatisfied verify - wrong arg count', ->
When -> @testDouble("good", "bad")
Then -> shouldThrow (=> @verify(@testDouble("good"))), """
Unsatisfied verification on test double.

Wanted:
- called with `("good")`.

But was actually called:
- called with `("good", "bad")`.
"""

context 'with a named double', ->
Given -> @testDouble = @create("#footime")
When -> @result = (shouldThrow => @verify(@testDouble()))
Expand Down