diff --git a/lib/sinon/assert.js b/lib/sinon/assert.js index 04ef3b51b..b8760c939 100644 --- a/lib/sinon/assert.js +++ b/lib/sinon/assert.js @@ -79,6 +79,7 @@ function mirrorPropAsAssertion(name, method, message) { var failed = false; verifyIsValidAssertion(name, args); + if (typeof method === "function") { failed = !method(fake); } else { @@ -199,11 +200,11 @@ mirrorPropAsAssertion( mirrorPropAsAssertion("calledWithNew", "expected %n to be called with new"); mirrorPropAsAssertion("alwaysCalledWithNew", "expected %n to always be called with new"); mirrorPropAsAssertion("calledWith", "expected %n to be called with arguments %D"); -mirrorPropAsAssertion("calledWithMatch", "expected %n to be called with match %*%C"); -mirrorPropAsAssertion("alwaysCalledWith", "expected %n to always be called with arguments %*%C"); -mirrorPropAsAssertion("alwaysCalledWithMatch", "expected %n to always be called with match %*%C"); -mirrorPropAsAssertion("calledWithExactly", "expected %n to be called with exact arguments %*%C"); -mirrorPropAsAssertion("alwaysCalledWithExactly", "expected %n to always be called with exact arguments %*%C"); +mirrorPropAsAssertion("calledWithMatch", "expected %n to be called with match %D"); +mirrorPropAsAssertion("alwaysCalledWith", "expected %n to always be called with arguments %D"); +mirrorPropAsAssertion("alwaysCalledWithMatch", "expected %n to always be called with match %D"); +mirrorPropAsAssertion("calledWithExactly", "expected %n to be called with exact arguments %D"); +mirrorPropAsAssertion("alwaysCalledWithExactly", "expected %n to always be called with exact arguments %D"); mirrorPropAsAssertion("neverCalledWith", "expected %n to never be called with arguments %*%C"); mirrorPropAsAssertion("neverCalledWithMatch", "expected %n to never be called with match %*%C"); mirrorPropAsAssertion("threw", "%n did not throw exception%C"); diff --git a/lib/sinon/spy.js b/lib/sinon/spy.js index f96f56b0a..4b2b46d75 100644 --- a/lib/sinon/spy.js +++ b/lib/sinon/spy.js @@ -461,16 +461,16 @@ spyApi.formatters = { if (i > 0) { message += "\n"; } - message += "Call " + i + ":"; + message += "Call " + (i + 1) + ":"; } var calledArgs = spyInstance.getCall(i).args; for (var j = 0; j < calledArgs.length || j < args.length; ++j) { message += "\n"; var calledArgMessage = j < calledArgs.length ? sinonFormat(calledArgs[j]) : ""; - var expectedArgMessage = j < args.length ? sinonFormat(args[j]) : ""; if (sinonMatch.isMatcher(args[j])) { message += colorSinonMatchText(args[j], calledArgs[j], calledArgMessage); } else { + var expectedArgMessage = j < args.length ? sinonFormat(args[j]) : ""; var diff = jsDiff.diffJson(calledArgMessage, expectedArgMessage); message += colorDiffText(diff); } diff --git a/test/assert-test.js b/test/assert-test.js index dc997c1b5..a1603315d 100644 --- a/test/assert-test.js +++ b/test/assert-test.js @@ -1375,11 +1375,11 @@ describe("assert", function () { assert.equals(this.message("calledWith", this.obj.doSomething, 1, 3, "hey").replace(/ at.*/g, ""), "expected doSomething to be called with arguments " + - "Call 0:\n" + + "Call 1:\n" + "4".red + " " + "1".green + " \n" + "3\n" + "hey\n" + - "Call 1:\n" + + "Call 2:\n" + "1\n" + "3\n" + "not".red + " " + "hey".green + " "); @@ -1552,8 +1552,10 @@ describe("assert", function () { this.obj.doSomething(1, 3, "hey"); assert.equals(this.message("calledWithMatch", this.obj.doSomething, 4, 3, "hey").replace(/ at.*/g, ""), - "expected doSomething to be called with match 4, 3, " + - "hey\n doSomething(1, 3, hey)"); + "expected doSomething to be called with match \n" + + "1".red + " " + "4".green + " \n" + + "3\n" + + "hey"); }); it("assert.alwaysCalledWith exception message", function () { @@ -1561,8 +1563,13 @@ describe("assert", function () { this.obj.doSomething(1, "hey"); assert.equals(this.message("alwaysCalledWith", this.obj.doSomething, 1, "hey").replace(/ at.*/g, ""), - "expected doSomething to always be called with arguments 1" + - ", hey\n doSomething(1, 3, hey)\n doSomething(1, hey)"); + "expected doSomething to always be called with arguments Call 1:\n" + + "1\n" + + "3".red + " " + "hey".green + " \n" + + "hey".red + "\n" + + "Call 2:\n" + + "1\n" + + "hey"); }); it("assert.alwaysCalledWithMatch exception message", function () { @@ -1571,17 +1578,23 @@ describe("assert", function () { assert.equals( this.message("alwaysCalledWithMatch", this.obj.doSomething, 1, "hey").replace(/ at.*/g, ""), - "expected doSomething to always be called with match 1" + - ", hey\n doSomething(1, 3, hey)\n doSomething(1, hey)" - ); + "expected doSomething to always be called with match Call 1:\n" + + "1\n" + + "3".red + " " + "hey".green + " \n" + + "hey".red + "\n" + + "Call 2:\n" + + "1\n" + + "hey"); }); it("assert.calledWithExactly exception message", function () { this.obj.doSomething(1, 3, "hey"); assert.equals(this.message("calledWithExactly", this.obj.doSomething, 1, 3).replace(/ at.*/g, ""), - "expected doSomething to be called with exact arguments 1" + - ", 3\n doSomething(1, 3, hey)"); + "expected doSomething to be called with exact arguments \n" + + "1\n" + + "3\n" + + "hey".red); }); it("assert.alwaysCalledWithExactly exception message", function () { @@ -1589,9 +1602,13 @@ describe("assert", function () { this.obj.doSomething(1, 3); assert.equals(this.message("alwaysCalledWithExactly", this.obj.doSomething, 1, 3).replace(/ at.*/g, ""), - "expected doSomething to always be called with exact " + - "arguments 1, 3\n doSomething(1, 3, hey)\n " + - "doSomething(1, 3)"); + "expected doSomething to always be called with exact arguments Call 1:\n" + + "1\n" + + "3\n" + + "hey".red + "\n" + + "Call 2:\n" + + "1\n" + + "3"); }); it("assert.neverCalledWith exception message", function () {