vendor/assets/javascripts/support/sinon-chai.js in teaspoon-0.7.9 vs vendor/assets/javascripts/support/sinon-chai.js in teaspoon-0.8.0

- old
+ new

@@ -24,10 +24,17 @@ return typeof putativeSpy === "function" && typeof putativeSpy.getCall === "function" && typeof putativeSpy.calledWithExactly === "function"; } + function timesInWords(count) { + return count === 1 ? "once" : + count === 2 ? "twice" : + count === 3 ? "thrice" : + (count || 0) + " times"; + } + function isCall(putativeCall) { return putativeCall && isSpy(putativeCall.proxy); } function assertCanWorkWith(assertion) { @@ -60,10 +67,19 @@ var messages = getMessages(this._obj, action, nonNegatedSuffix, false); this.assert(this._obj[name], messages.affirmative, messages.negative); }); } + function sinonPropertyAsBooleanMethod(name, action, nonNegatedSuffix) { + utils.addMethod(chai.Assertion.prototype, name, function (arg) { + assertCanWorkWith(this); + + var messages = getMessages(this._obj, action, nonNegatedSuffix, false, [timesInWords(arg)]); + this.assert(this._obj[name] === arg, messages.affirmative, messages.negative); + }); + } + function createSinonMethodHandler(sinonName, action, nonNegatedSuffix) { return function () { assertCanWorkWith(this); var alwaysSinonMethod = "always" + sinonName[0].toUpperCase() + sinonName.substring(1); @@ -92,9 +108,10 @@ utils.addProperty(chai.Assertion.prototype, "always", function () { utils.flag(this, "always", true); }); sinonProperty("called", "been called", " at least once, but it was never called"); + sinonPropertyAsBooleanMethod("callCount", "been called exactly %1", ", but it was called %c%C"); sinonProperty("calledOnce", "been called exactly once", ", but it was called %c%C"); sinonProperty("calledTwice", "been called exactly twice", ", but it was called %c%C"); sinonProperty("calledThrice", "been called exactly thrice", ", but it was called %c%C"); sinonMethodAsProperty("calledWithNew", "been called with new"); sinonMethod("calledBefore", "been called before %1");