From 49f295690a4bba6c99c7c31cfcee6d563997bd26 Mon Sep 17 00:00:00 2001 From: Christian Williams Date: Mon, 1 Mar 2010 23:02:59 -0500 Subject: [PATCH] Old-style custom matchers (those which call this.report()) are not supported with the ".not" matcher negation syntax. --- spec/suites/MatchersSpec.js | 16 ++++++++++++++++ src/Matchers.js | 8 ++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/spec/suites/MatchersSpec.js b/spec/suites/MatchersSpec.js index 67295fb..32b7e5f 100644 --- a/spec/suites/MatchersSpec.js +++ b/spec/suites/MatchersSpec.js @@ -513,6 +513,22 @@ describe("jasmine.Matchers", function() { match(false).not.custom(); expect(lastResult().message).toEqual("Passed."); }); + + it("should make old-style custom matchers blow up, but only when negated", function() { + spec.addMatchers({ + custom: function() { + this.report(); + } + }); + + expect(function() { + match(true).custom(); + }).not.toThrow(); + + expect(function() { + match(true).not.custom(); + }).toThrow(); + }); }); describe("spy matchers >>", function() { diff --git a/src/Matchers.js b/src/Matchers.js index d387d52..4b27692 100644 --- a/src/Matchers.js +++ b/src/Matchers.js @@ -18,8 +18,12 @@ jasmine.Matchers.pp = function(str) { /** @deprecated */ jasmine.Matchers.prototype.report = function(result, failing_message, details) { -// todo first: report deprecation warning [xw] -// todo later: throw new Error("As of jasmine 0.xx, custom matchers must be implemented differently -- please see jasmine docs"); + // todo: report a deprecation warning [xw] + + if (this.isNot) { + throw new Error("As of jasmine 0.11, custom matchers must be implemented differently -- please see jasmine docs"); + } + this.reportWasCalled_ = true; var expectationResult = new jasmine.ExpectationResult({ passed: result,