Skip to content

Commit

Permalink
Made unexpected mock calls print better errors when available.
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobsa committed Jun 28, 2013
1 parent 03a18ce commit 56d307f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions gjstest/internal/integration_tests/mocks.golden.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ mocks_test.js:74: Call to bar matches no expectation.
mocks_test.js:85: Call matches no expectation.
Arg 0: 0

Tried expectation at mocks_test.js:81, but arg 0 didn't match:
Tried expectation at mocks_test.js:81, but arg 0 (which is not an Array) didn't match:
Arg 0: recursively equals [ 17, 23 ]

mocks_test.js:88: Call to bar matches no expectation.
Arg 0: 0

Tried expectation at mocks_test.js:82, but arg 0 didn't match:
Tried expectation at mocks_test.js:82, but arg 0 (which is not an Array) didn't match:
Arg 0: recursively equals [ 17, 23 ]

[ FAILED ] MocksTest.UnexpectedFunctionCall_RecursivelyEquals (1 ms)
Expand Down
4 changes: 2 additions & 2 deletions gjstest/internal/integration_tests/mocks.golden.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ mocks_test.js:74: Call to bar matches no expectation.
<failure><![CDATA[mocks_test.js:85: Call matches no expectation.
Arg 0: 0
Tried expectation at mocks_test.js:81, but arg 0 didn't match:
Tried expectation at mocks_test.js:81, but arg 0 (which is not an Array) didn't match:
Arg 0: recursively equals [ 17, 23 ]
mocks_test.js:88: Call to bar matches no expectation.
Arg 0: 0
Tried expectation at mocks_test.js:82, but arg 0 didn't match:
Tried expectation at mocks_test.js:82, but arg 0 (which is not an Array) didn't match:
Arg 0: recursively equals [ 17, 23 ]]]></failure>
</testcase>
<testcase name="MocksTest.UnexpectedMethodCall" time="0.01">
Expand Down
4 changes: 3 additions & 1 deletion gjstest/internal/js/call_expectation.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,10 @@ gjstest.internal.checkArgsAgainstExpectation = function(args, expectation) {

// Check the argument (or missing argument sentinel) against the matcher.
var predicateResult = matcher.predicate(arg);
if (predicateResult === false || typeof(predicateResult) === 'string') {
if (predicateResult === false) {
return "arg " + i + " didn't match";
} else if (typeof(predicateResult) === 'string') {
return "arg " + i + " (" + predicateResult + ") didn't match";
}
}

Expand Down
6 changes: 4 additions & 2 deletions gjstest/internal/js/call_expectation_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,11 @@ CheckArgsTest.prototype.MatcherReturnsString = function() {
.willOnce(returnWith(true));

expectCall(this.predicateB_)(_)
.willOnce(returnWith('error'));
.willOnce(returnWith('which is foo'));

expectEq("arg 1 didn't match", this.checkArgs_('taco', 'burrito'));
expectEq(
"arg 1 (which is foo) didn't match",
this.checkArgs_('taco', 'burrito'));
};

CheckArgsTest.prototype.AllMatchersSayOkay = function() {
Expand Down

0 comments on commit 56d307f

Please sign in to comment.