diff --git a/spec/core/CustomMatchersSpec.js b/spec/core/CustomMatchersSpec.js index 9f449aa2..8ac71d31 100644 --- a/spec/core/CustomMatchersSpec.js +++ b/spec/core/CustomMatchersSpec.js @@ -10,10 +10,8 @@ describe("Custom Matchers (Integration)", function() { env.it('spec defining a custom matcher', function() { env.addMatchers({ matcherForSpec: function() { - return { - compare: function(actual, expected) { - return { pass: false, message: "matcherForSpec: actual: " + actual + "; expected: " + expected }; - } + return function(actual, expected) { + return { pass: false, message: "matcherForSpec: actual: " + actual + "; expected: " + expected }; } } }); @@ -40,7 +38,7 @@ describe("Custom Matchers (Integration)", function() { it("passes the spec if the custom matcher passes", function(done) { env.addMatchers({ toBeReal: function() { - return { compare: function() { return { pass: true }; } }; + return function() { return { pass: true }; }; } }); @@ -59,10 +57,8 @@ describe("Custom Matchers (Integration)", function() { it("generates messages with the same rules as built in matchers absent a custom message", function(done) { env.addMatchers({ toBeReal: function() { - return { - compare: function() { - return { pass: false }; - } + return function() { + return { pass: false }; } } }); @@ -83,7 +79,7 @@ describe("Custom Matchers (Integration)", function() { var argumentSpy = jasmine.createSpy("argument spy").and.returnValue({ pass: true }); env.addMatchers({ toBeReal: function() { - return { compare: argumentSpy }; + return argumentSpy; } }); @@ -104,7 +100,7 @@ describe("Custom Matchers (Integration)", function() { }); it("passes the jasmine utility and current equality matchers to the expectation factory", function(done) { - var matcherFactory = function() { return { compare: function() { return {pass: true}; }}; }, + var matcherFactory = function() { return function() { return { pass: true }; }; }, argumentSpy = jasmine.createSpy("argument spy").and.returnValue(matcherFactory), customEqualityFn = function() { return true; }; diff --git a/spec/core/ExpectationSpec.js b/spec/core/ExpectationSpec.js index a86c4f66..b9755dba 100644 --- a/spec/core/ExpectationSpec.js +++ b/spec/core/ExpectationSpec.js @@ -56,7 +56,7 @@ describe("Expectation", function() { it("wraps matchers's compare functions, passing in matcher dependencies", function() { var fakeCompare = function() { return { pass: true }; }, - matcherFactory = jasmine.createSpy("matcher").and.returnValue({ compare: fakeCompare }), + matcherFactory = jasmine.createSpy("matcher").and.returnValue(fakeCompare), matchers = { toFoo: matcherFactory }, @@ -83,9 +83,7 @@ describe("Expectation", function() { var fakeCompare = jasmine.createSpy('fake-compare').and.returnValue({pass: true}), matchers = { toFoo: function() { - return { - compare: fakeCompare - }; + return fakeCompare; } }, util = { @@ -110,9 +108,7 @@ describe("Expectation", function() { it("reports a passing result to the spec when the comparison passes", function() { var matchers = { toFoo: function() { - return { - compare: function() { return { pass: true }; } - }; + return function() { return { pass: true }; }; } }, util = { @@ -144,9 +140,7 @@ describe("Expectation", function() { it("reports a failing result to the spec when the comparison fails", function() { var matchers = { toFoo: function() { - return { - compare: function() { return { pass: false }; } - }; + return function() { return { pass: false }; }; } }, util = { @@ -178,13 +172,11 @@ describe("Expectation", function() { it("reports a failing result and a custom fail message to the spec when the comparison fails", function() { var matchers = { toFoo: function() { - return { - compare: function() { - return { - pass: false, - message: "I am a custom message" - }; - } + return function() { + return { + pass: false, + message: "I am a custom message" + }; }; } }, @@ -213,9 +205,7 @@ describe("Expectation", function() { it("reports a passing result to the spec when the comparison fails for a negative expectation", function() { var matchers = { toFoo: function() { - return { - compare: function() { return { pass: false }; } - }; + return function() { return { pass: false }; }; } }, util = { @@ -248,9 +238,7 @@ describe("Expectation", function() { it("reports a failing result to the spec when the comparison passes for a negative expectation", function() { var matchers = { toFoo: function() { - return { - compare: function() { return { pass: true }; } - }; + return function() { return { pass: true }; }; } }, util = { @@ -284,13 +272,11 @@ describe("Expectation", function() { it("reports a failing result and a custom fail message to the spec when the comparison passes for a negative expectation", function() { var matchers = { toFoo: function() { - return { - compare: function() { - return { - pass: true, - message: "I am a custom message" - }; - } + return function() { + return { + pass: true, + message: "I am a custom message" + }; }; } }, @@ -317,4 +303,4 @@ describe("Expectation", function() { message: "I am a custom message" }); }); -}); \ No newline at end of file +}); diff --git a/spec/core/matchers/toBeCloseToSpec.js b/spec/core/matchers/toBeCloseToSpec.js index c7975bd0..b45fb949 100644 --- a/spec/core/matchers/toBeCloseToSpec.js +++ b/spec/core/matchers/toBeCloseToSpec.js @@ -1,51 +1,51 @@ describe("toBeCloseTo", function() { it("passes when within two decimal places by default", function() { - var matcher = j$.matchers.toBeCloseTo(), + var matcherComparator = j$.matchers.toBeCloseTo(), result; - result = matcher.compare(0, 0); + result = matcherComparator(0, 0); expect(result.pass).toBe(true); - result = matcher.compare(0, 0.001); + result = matcherComparator(0, 0.001); expect(result.pass).toBe(true); }); it("fails when not within two decimal places by default", function() { - var matcher = j$.matchers.toBeCloseTo(), + var matcherComparator = j$.matchers.toBeCloseTo(), result; - result = matcher.compare(0, 0.01); + result = matcherComparator(0, 0.01); expect(result.pass).toBe(false); }); it("accepts an optional precision argument", function() { - var matcher = j$.matchers.toBeCloseTo(), + var matcherComparator = j$.matchers.toBeCloseTo(), result; - result = matcher.compare(0, 0.1, 0); + result = matcherComparator(0, 0.1, 0); expect(result.pass).toBe(true); - result = matcher.compare(0, 0.0001, 3); + result = matcherComparator(0, 0.0001, 3); expect(result.pass).toBe(true); }); it("rounds expected values", function() { - var matcher = j$.matchers.toBeCloseTo(), + var matcherComparator = j$.matchers.toBeCloseTo(), result; - result = matcher.compare(1.23, 1.229); + result = matcherComparator(1.23, 1.229); expect(result.pass).toBe(true); - result = matcher.compare(1.23, 1.226); + result = matcherComparator(1.23, 1.226); expect(result.pass).toBe(true); - result = matcher.compare(1.23, 1.225); + result = matcherComparator(1.23, 1.225); expect(result.pass).toBe(true); - result = matcher.compare(1.23, 1.2249999); + result = matcherComparator(1.23, 1.2249999); expect(result.pass).toBe(false); - result = matcher.compare(1.23, 1.234); + result = matcherComparator(1.23, 1.234); expect(result.pass).toBe(true); }); }); diff --git a/spec/core/matchers/toBeDefinedSpec.js b/spec/core/matchers/toBeDefinedSpec.js index 7e6626a6..8499f491 100644 --- a/spec/core/matchers/toBeDefinedSpec.js +++ b/spec/core/matchers/toBeDefinedSpec.js @@ -1,18 +1,18 @@ describe("toBeDefined", function() { it("matches for defined values", function() { - var matcher = j$.matchers.toBeDefined(), + var matcherComparator = j$.matchers.toBeDefined(), result; - result = matcher.compare('foo'); + result = matcherComparator('foo'); expect(result.pass).toBe(true); }); it("fails when matching undefined values", function() { - var matcher = j$.matchers.toBeDefined(), + var matcherComparator = j$.matchers.toBeDefined(), result; - result = matcher.compare(void 0); + result = matcherComparator(void 0); expect(result.pass).toBe(false); }) }); diff --git a/spec/core/matchers/toBeFalsySpec.js b/spec/core/matchers/toBeFalsySpec.js index aa612838..6527f90b 100644 --- a/spec/core/matchers/toBeFalsySpec.js +++ b/spec/core/matchers/toBeFalsySpec.js @@ -1,38 +1,38 @@ describe("toBeFalsy", function() { it("passes for 'falsy' values", function() { - var matcher = j$.matchers.toBeFalsy(), + var matcherComparator = j$.matchers.toBeFalsy(), result; - result = matcher.compare(false); + result = matcherComparator(false); expect(result.pass).toBe(true); - result = matcher.compare(0); + result = matcherComparator(0); expect(result.pass).toBe(true); - result = matcher.compare(''); + result = matcherComparator(''); expect(result.pass).toBe(true); - result = matcher.compare(null); + result = matcherComparator(null); expect(result.pass).toBe(true); - result = matcher.compare(void 0); + result = matcherComparator(void 0); expect(result.pass).toBe(true); }); it("fails for 'truthy' values", function() { - var matcher = j$.matchers.toBeFalsy(), + var matcherComparator = j$.matchers.toBeFalsy(), result; - result = matcher.compare(true); + result = matcherComparator(true); expect(result.pass).toBe(false); - result = matcher.compare(1); + result = matcherComparator(1); expect(result.pass).toBe(false); - result = matcher.compare("foo"); + result = matcherComparator("foo"); expect(result.pass).toBe(false); - result = matcher.compare({}); + result = matcherComparator({}); expect(result.pass).toBe(false); }); }); diff --git a/spec/core/matchers/toBeGreaterThanSpec.js b/spec/core/matchers/toBeGreaterThanSpec.js index 397c0e55..407ea197 100644 --- a/spec/core/matchers/toBeGreaterThanSpec.js +++ b/spec/core/matchers/toBeGreaterThanSpec.js @@ -1,19 +1,19 @@ describe("toBeGreaterThan", function() { it("passes when actual > expected", function() { - var matcher = j$.matchers.toBeGreaterThan(), + var matcherComparator = j$.matchers.toBeGreaterThan(), result; - result = matcher.compare(2, 1); + result = matcherComparator(2, 1); expect(result.pass).toBe(true); }); it("fails when actual <= expected", function() { - var matcher = j$.matchers.toBeGreaterThan(); + var matcherComparator = j$.matchers.toBeGreaterThan(); - result = matcher.compare(1, 1); + result = matcherComparator(1, 1); expect(result.pass).toBe(false); - result = matcher.compare(1, 2); + result = matcherComparator(1, 2); expect(result.pass).toBe(false); }); }); diff --git a/spec/core/matchers/toBeLessThanSpec.js b/spec/core/matchers/toBeLessThanSpec.js index 53938d2c..3496748e 100644 --- a/spec/core/matchers/toBeLessThanSpec.js +++ b/spec/core/matchers/toBeLessThanSpec.js @@ -1,20 +1,20 @@ describe("toBeLessThan", function() { it("passes when actual < expected", function() { - var matcher = j$.matchers.toBeLessThan(), + var matcherComparator = j$.matchers.toBeLessThan(), result; - result = matcher.compare(1, 2); + result = matcherComparator(1, 2); expect(result.pass).toBe(true); }); it("fails when actual <= expected", function() { - var matcher = j$.matchers.toBeLessThan(), + var matcherComparator = j$.matchers.toBeLessThan(), result; - result = matcher.compare(1, 1); + result = matcherComparator(1, 1); expect(result.pass).toBe(false); - result = matcher.compare(2, 1); + result = matcherComparator(2, 1); expect(result.pass).toBe(false); }); }); diff --git a/spec/core/matchers/toBeNaNSpec.js b/spec/core/matchers/toBeNaNSpec.js index d4a00b4d..f576008f 100644 --- a/spec/core/matchers/toBeNaNSpec.js +++ b/spec/core/matchers/toBeNaNSpec.js @@ -1,35 +1,35 @@ describe("toBeNaN", function() { it("passes for NaN with a custom .not fail", function() { - var matcher = j$.matchers.toBeNaN(), + var matcherComparator = j$.matchers.toBeNaN(), result; - result = matcher.compare(Number.NaN); + result = matcherComparator(Number.NaN); expect(result.pass).toBe(true); expect(result.message).toEqual("Expected actual not to be NaN."); }); it("fails for anything not a NaN", function() { - var matcher = j$.matchers.toBeNaN(); + var matcherComparator = j$.matchers.toBeNaN(); - result = matcher.compare(1); + result = matcherComparator(1); expect(result.pass).toBe(false); - result = matcher.compare(null); + result = matcherComparator(null); expect(result.pass).toBe(false); - result = matcher.compare(void 0); + result = matcherComparator(void 0); expect(result.pass).toBe(false); - result = matcher.compare(''); + result = matcherComparator(''); expect(result.pass).toBe(false); - result = matcher.compare(Number.POSITIVE_INFINITY); + result = matcherComparator(Number.POSITIVE_INFINITY); expect(result.pass).toBe(false); }); it("has a custom message on failure", function() { - var matcher = j$.matchers.toBeNaN(), - result = matcher.compare(0); + var matcherComparator = j$.matchers.toBeNaN(), + result = matcherComparator(0); expect(result.message).toEqual("Expected 0 to be NaN."); }); diff --git a/spec/core/matchers/toBeNullSpec.js b/spec/core/matchers/toBeNullSpec.js index 8a178d5c..63b42a8a 100644 --- a/spec/core/matchers/toBeNullSpec.js +++ b/spec/core/matchers/toBeNullSpec.js @@ -1,17 +1,17 @@ describe("toBeNull", function() { it("passes for null", function() { - var matcher = j$.matchers.toBeNull(), + var matcherComparator = j$.matchers.toBeNull(), result; - result = matcher.compare(null); + result = matcherComparator(null); expect(result.pass).toBe(true); }); it("fails for non-null", function() { - var matcher = j$.matchers.toBeNull(), + var matcherComparator = j$.matchers.toBeNull(), result; - result = matcher.compare('foo'); + result = matcherComparator('foo'); expect(result.pass).toBe(false); }); }); diff --git a/spec/core/matchers/toBeSpec.js b/spec/core/matchers/toBeSpec.js index 908c2978..45dc679e 100644 --- a/spec/core/matchers/toBeSpec.js +++ b/spec/core/matchers/toBeSpec.js @@ -1,17 +1,17 @@ describe("toBe", function() { it("passes when actual === expected", function() { - var matcher = j$.matchers.toBe(), + var matcherComparator = j$.matchers.toBe(), result; - result = matcher.compare(1, 1); + result = matcherComparator(1, 1); expect(result.pass).toBe(true); }); it("fails when actual !== expected", function() { - var matcher = j$.matchers.toBe(), + var matcherComparator = j$.matchers.toBe(), result; - result = matcher.compare(1, 2); + result = matcherComparator(1, 2); expect(result.pass).toBe(false); }); }); diff --git a/spec/core/matchers/toBeTruthySpec.js b/spec/core/matchers/toBeTruthySpec.js index 3acb1ffe..01df676d 100644 --- a/spec/core/matchers/toBeTruthySpec.js +++ b/spec/core/matchers/toBeTruthySpec.js @@ -1,38 +1,38 @@ describe("toBeTruthy", function() { it("passes for 'truthy' values", function() { - var matcher = j$.matchers.toBeTruthy(), + var matcherComparator = j$.matchers.toBeTruthy(), result; - result = matcher.compare(true); + result = matcherComparator(true); expect(result.pass).toBe(true); - result = matcher.compare(1); + result = matcherComparator(1); expect(result.pass).toBe(true); - result = matcher.compare("foo"); + result = matcherComparator("foo"); expect(result.pass).toBe(true); - result = matcher.compare({}); + result = matcherComparator({}); expect(result.pass).toBe(true); }); it("fails for 'falsy' values", function() { - var matcher = j$.matchers.toBeTruthy(), + var matcherComparator = j$.matchers.toBeTruthy(), result; - result = matcher.compare(false); + result = matcherComparator(false); expect(result.pass).toBe(false); - result = matcher.compare(0); + result = matcherComparator(0); expect(result.pass).toBe(false); - result = matcher.compare(''); + result = matcherComparator(''); expect(result.pass).toBe(false); - result = matcher.compare(null); + result = matcherComparator(null); expect(result.pass).toBe(false); - result = matcher.compare(void 0); + result = matcherComparator(void 0); expect(result.pass).toBe(false); }); }); diff --git a/spec/core/matchers/toBeUndefinedSpec.js b/spec/core/matchers/toBeUndefinedSpec.js index 9d166276..5cce6f6c 100644 --- a/spec/core/matchers/toBeUndefinedSpec.js +++ b/spec/core/matchers/toBeUndefinedSpec.js @@ -1,17 +1,17 @@ describe("toBeUndefined", function() { it("passes for undefined values", function() { - var matcher = j$.matchers.toBeUndefined(), + var matcherComparator = j$.matchers.toBeUndefined(), result; - result = matcher.compare(void 0); + result = matcherComparator(void 0); expect(result.pass).toBe(true); }); it("fails when matching defined values", function() { - var matcher = j$.matchers.toBeUndefined(); + var matcherComparator = j$.matchers.toBeUndefined(); - result = matcher.compare('foo'); + result = matcherComparator('foo'); expect(result.pass).toBe(false); }) }); diff --git a/spec/core/matchers/toContainSpec.js b/spec/core/matchers/toContainSpec.js index 848a73dc..f4f7b26a 100644 --- a/spec/core/matchers/toContainSpec.js +++ b/spec/core/matchers/toContainSpec.js @@ -3,9 +3,9 @@ describe("toContain", function() { var util = { contains: jasmine.createSpy('delegated-contains').and.returnValue(true) }, - matcher = j$.matchers.toContain(util); + matcherComparator = j$.matchers.toContain(util); - result = matcher.compare("ABC", "B"); + result = matcherComparator("ABC", "B"); expect(util.contains).toHaveBeenCalledWith("ABC", "B", []); expect(result.pass).toBe(true); }); @@ -15,9 +15,9 @@ describe("toContain", function() { contains: jasmine.createSpy('delegated-contains').and.returnValue(true) }, customEqualityTesters = ['a', 'b'], - matcher = j$.matchers.toContain(util, customEqualityTesters); + matcherComparator = j$.matchers.toContain(util, customEqualityTesters); - result = matcher.compare("ABC", "B"); + result = matcherComparator("ABC", "B"); expect(util.contains).toHaveBeenCalledWith("ABC", "B", ['a', 'b']); expect(result.pass).toBe(true); }); diff --git a/spec/core/matchers/toEqualSpec.js b/spec/core/matchers/toEqualSpec.js index 55bfee12..aa6d4f91 100644 --- a/spec/core/matchers/toEqualSpec.js +++ b/spec/core/matchers/toEqualSpec.js @@ -3,10 +3,10 @@ describe("toEqual", function() { var util = { equals: jasmine.createSpy('delegated-equals').and.returnValue(true) }, - matcher = j$.matchers.toEqual(util), + matcherComparator = j$.matchers.toEqual(util), result; - result = matcher.compare(1, 1); + result = matcherComparator(1, 1); expect(util.equals).toHaveBeenCalledWith(1, 1, []); expect(result.pass).toBe(true); @@ -17,10 +17,10 @@ describe("toEqual", function() { equals: jasmine.createSpy('delegated-equals').and.returnValue(true) }, customEqualityTesters = ['a', 'b'], - matcher = j$.matchers.toEqual(util, customEqualityTesters), + matcherComparator = j$.matchers.toEqual(util, customEqualityTesters), result; - result = matcher.compare(1, 1); + result = matcherComparator(1, 1); expect(util.equals).toHaveBeenCalledWith(1, 1, ['a', 'b']); expect(result.pass).toBe(true); diff --git a/spec/core/matchers/toHaveBeenCalledSpec.js b/spec/core/matchers/toHaveBeenCalledSpec.js index 88c8d4a7..d2799e61 100644 --- a/spec/core/matchers/toHaveBeenCalledSpec.js +++ b/spec/core/matchers/toHaveBeenCalledSpec.js @@ -1,44 +1,44 @@ describe("toHaveBeenCalled", function() { it("passes when the actual was called, with a custom .not fail message", function() { - var matcher = j$.matchers.toHaveBeenCalled(), + var matcherComparator = j$.matchers.toHaveBeenCalled(), calledSpy = j$.createSpy('called-spy'), result; calledSpy(); - result = matcher.compare(calledSpy); + result = matcherComparator(calledSpy); expect(result.pass).toBe(true); expect(result.message).toEqual("Expected spy called-spy not to have been called."); }); it("fails when the actual was not called", function() { - var matcher = j$.matchers.toHaveBeenCalled(), + var matcherComparator = j$.matchers.toHaveBeenCalled(), uncalledSpy = j$.createSpy('uncalled spy'); - result = matcher.compare(uncalledSpy); + result = matcherComparator(uncalledSpy); expect(result.pass).toBe(false); }); it("throws an exception when the actual is not a spy", function() { - var matcher = j$.matchers.toHaveBeenCalled(), + var matcherComparator = j$.matchers.toHaveBeenCalled(), fn = function() {}; - expect(function() { matcher.compare(fn) }).toThrow(new Error("Expected a spy, but got Function.")); + expect(function() { matcherComparator(fn) }).toThrow(new Error("Expected a spy, but got Function.")); }); it("throws an exception when invoked with any arguments", function() { - var matcher = j$.matchers.toHaveBeenCalled(), + var matcherComparator = j$.matchers.toHaveBeenCalled(), spy = j$.createSpy('sample spy'); - expect(function() { matcher.compare(spy, 'foo') }).toThrow(new Error("toHaveBeenCalled does not take arguments, use toHaveBeenCalledWith")); + expect(function() { matcherComparator(spy, 'foo') }).toThrow(new Error("toHaveBeenCalled does not take arguments, use toHaveBeenCalledWith")); }); it("has a custom message on failure", function() { - var matcher = j$.matchers.toHaveBeenCalled(), + var matcherComparator = j$.matchers.toHaveBeenCalled(), spy = j$.createSpy('sample-spy'), result; - result = matcher.compare(spy); + result = matcherComparator(spy); expect(result.message).toEqual("Expected spy sample-spy to have been called."); }); diff --git a/spec/core/matchers/toHaveBeenCalledWithSpec.js b/spec/core/matchers/toHaveBeenCalledWithSpec.js index 466682cd..fe72cec8 100644 --- a/spec/core/matchers/toHaveBeenCalledWithSpec.js +++ b/spec/core/matchers/toHaveBeenCalledWithSpec.js @@ -3,12 +3,12 @@ describe("toHaveBeenCalledWith", function() { var util = { contains: jasmine.createSpy('delegated-contains').and.returnValue(true) }, - matcher = j$.matchers.toHaveBeenCalledWith(util), + matcherComparator = j$.matchers.toHaveBeenCalledWith(util), calledSpy = j$.createSpy('called-spy'), result; calledSpy('a', 'b'); - result = matcher.compare(calledSpy, 'a', 'b'); + result = matcherComparator(calledSpy, 'a', 'b'); expect(result.pass).toBe(true); expect(result.message).toEqual("Expected spy called-spy not to have been called with [ 'a', 'b' ] but it was."); @@ -18,11 +18,11 @@ describe("toHaveBeenCalledWith", function() { var util = { contains: jasmine.createSpy('delegated-contains').and.returnValue(false) }, - matcher = j$.matchers.toHaveBeenCalledWith(util), + matcherComparator = j$.matchers.toHaveBeenCalledWith(util), uncalledSpy = j$.createSpy('uncalled spy'), result; - result = matcher.compare(uncalledSpy); + result = matcherComparator(uncalledSpy); expect(result.pass).toBe(false); expect(result.message).toEqual("Expected spy uncalled spy to have been called with [ ] but it was never called."); }); @@ -31,22 +31,22 @@ describe("toHaveBeenCalledWith", function() { var util = { contains: jasmine.createSpy('delegated-contains').and.returnValue(false) }, - matcher = j$.matchers.toHaveBeenCalledWith(util), + matcherComparator = j$.matchers.toHaveBeenCalledWith(util), calledSpy = j$.createSpy('called spy'), result; calledSpy('a'); calledSpy('c', 'd'); - result = matcher.compare(calledSpy, 'a', 'b'); + result = matcherComparator(calledSpy, 'a', 'b'); expect(result.pass).toBe(false); expect(result.message).toEqual("Expected spy called spy to have been called with [ 'a', 'b' ] but actual calls were [ 'a' ], [ 'c', 'd' ]."); }); it("throws an exception when the actual is not a spy", function() { - var matcher = j$.matchers.toHaveBeenCalledWith(), + var matcherComparator = j$.matchers.toHaveBeenCalledWith(), fn = function() {}; - expect(function() { matcher.compare(fn) }).toThrow(new Error("Expected a spy, but got Function.")); + expect(function() { matcherComparator(fn) }).toThrow(new Error("Expected a spy, but got Function.")); }); }); diff --git a/spec/core/matchers/toMatchSpec.js b/spec/core/matchers/toMatchSpec.js index ae4c2e8e..ae3e0662 100644 --- a/spec/core/matchers/toMatchSpec.js +++ b/spec/core/matchers/toMatchSpec.js @@ -1,33 +1,33 @@ describe("toMatch", function() { it("passes when RegExps are equivalent", function() { - var matcher = j$.matchers.toMatch(), + var matcherComparator = j$.matchers.toMatch(), result; - result = matcher.compare(/foo/, /foo/); + result = matcherComparator(/foo/, /foo/); expect(result.pass).toBe(true); }); it("fails when RegExps are not equivalent", function() { - var matcher = j$.matchers.toMatch(), + var matcherComparator = j$.matchers.toMatch(), result; - result = matcher.compare(/bar/, /foo/); + result = matcherComparator(/bar/, /foo/); expect(result.pass).toBe(false); }); it("passes when the actual matches the expected string as a pattern", function() { - var matcher = j$.matchers.toMatch(), + var matcherComparator = j$.matchers.toMatch(), result; - result = matcher.compare('foosball', 'foo'); + result = matcherComparator('foosball', 'foo'); expect(result.pass).toBe(true); }); it("fails when the actual matches the expected string as a pattern", function() { - var matcher = j$.matchers.toMatch(), + var matcherComparator = j$.matchers.toMatch(), result; - result = matcher.compare('bar', 'foo'); + result = matcherComparator('bar', 'foo'); expect(result.pass).toBe(false); }); }); diff --git a/spec/core/matchers/toThrowErrorSpec.js b/spec/core/matchers/toThrowErrorSpec.js index a6391f0a..a218a385 100644 --- a/spec/core/matchers/toThrowErrorSpec.js +++ b/spec/core/matchers/toThrowErrorSpec.js @@ -1,142 +1,142 @@ describe("toThrowError", function() { it("throws an error when the actual is not a function", function() { - var matcher = j$.matchers.toThrowError(); + var matcherComparator = j$.matchers.toThrowError(); expect(function() { - matcher.compare({}); + matcherComparator({}); }).toThrow(new Error("Actual is not a Function")); // TODO: this needs to change for self-test }); it("throws an error when the expected is not an Error, string, or RegExp", function() { - var matcher = j$.matchers.toThrowError(), + var matcherComparator = j$.matchers.toThrowError(), fn = function() { throw new Error("foo"); }; expect(function() { - matcher.compare(fn, 1); + matcherComparator(fn, 1); }).toThrow(new Error("Expected is not an Error, string, or RegExp.")); // TODO: this needs to change for self-test }); it("throws an error when the expected error type is not an Error", function() { - var matcher = j$.matchers.toThrowError(), + var matcherComparator = j$.matchers.toThrowError(), fn = function() { throw new Error("foo"); }; expect(function() { - matcher.compare(fn, void 0, "foo"); + matcherComparator(fn, void 0, "foo"); }).toThrow(new Error("Expected error type is not an Error.")); // TODO: this needs to change for self-test }); it("throws an error when the expected error message is not a string or RegExp", function() { - var matcher = j$.matchers.toThrowError(), + var matcherComparator = j$.matchers.toThrowError(), fn = function() { throw new Error("foo"); }; expect(function() { - matcher.compare(fn, Error, 1); + matcherComparator(fn, Error, 1); }).toThrow(new Error("Expected error message is not a string or RegExp.")); // TODO: this needs to change for self-test }); it("fails if actual does not throw at all", function() { - var matcher = j$.matchers.toThrowError(), + var matcherComparator = j$.matchers.toThrowError(), fn = function() { return true; }, result; - result = matcher.compare(fn); + result = matcherComparator(fn); expect(result.pass).toBe(false); expect(result.message).toEqual("Expected function to throw an Error."); }); it("fails if thrown is not an instanceof Error", function() { - var matcher = j$.matchers.toThrowError(), + var matcherComparator = j$.matchers.toThrowError(), fn = function() { throw 4; }, result; - result = matcher.compare(fn); + result = matcherComparator(fn); expect(result.pass).toBe(false); expect(result.message).toEqual("Expected function to throw an Error, but it threw 4."); }); it("fails with the correct message if thrown is a falsy value", function() { - var matcher = j$.matchers.toThrowError(), + var matcherComparator = j$.matchers.toThrowError(), fn = function() { throw undefined; }, result; - result = matcher.compare(fn); + result = matcherComparator(fn); expect(result.pass).toBe(false); expect(result.message).toEqual("Expected function to throw an Error, but it threw undefined."); }); it("passes if thrown is a type of Error, but there is no expected error", function() { - var matcher = j$.matchers.toThrowError(), + var matcherComparator = j$.matchers.toThrowError(), fn = function() { throw new TypeError(); }, result; - result = matcher.compare(fn); + result = matcherComparator(fn); expect(result.pass).toBe(true); expect(result.message).toEqual("Expected function not to throw an Error, but it threw TypeError."); }); it("passes if thrown is an Error and the expected is the same message", function() { - var matcher = j$.matchers.toThrowError(), + var matcherComparator = j$.matchers.toThrowError(), fn = function() { throw new Error("foo"); }, result; - result = matcher.compare(fn, "foo"); + result = matcherComparator(fn, "foo"); expect(result.pass).toBe(true); expect(result.message).toEqual("Expected function not to throw an exception with message 'foo'."); }); it("fails if thrown is an Error and the expected is not the same message", function() { - var matcher = j$.matchers.toThrowError(), + var matcherComparator = j$.matchers.toThrowError(), fn = function() { throw new Error("foo"); }, result; - result = matcher.compare(fn, "bar"); + result = matcherComparator(fn, "bar"); expect(result.pass).toBe(false); expect(result.message).toEqual("Expected function to throw an exception with message 'bar', but it threw an exception with message 'foo'."); }); it("passes if thrown is an Error and the expected is a RegExp that matches the message", function() { - var matcher = j$.matchers.toThrowError(), + var matcherComparator = j$.matchers.toThrowError(), fn = function() { throw new Error("a long message"); }, result; - result = matcher.compare(fn, /long/); + result = matcherComparator(fn, /long/); expect(result.pass).toBe(true); expect(result.message).toEqual("Expected function not to throw an exception with a message matching /long/."); }); it("fails if thrown is an Error and the expected is a RegExp that does not match the message", function() { - var matcher = j$.matchers.toThrowError(), + var matcherComparator = j$.matchers.toThrowError(), fn = function() { throw new Error("a long message"); }, result; - result = matcher.compare(fn, /foo/); + result = matcherComparator(fn, /foo/); expect(result.pass).toBe(false); expect(result.message).toEqual("Expected function to throw an exception with a message matching /foo/, but it threw an exception with message 'a long message'."); @@ -146,13 +146,13 @@ describe("toThrowError", function() { var util = { equals: jasmine.createSpy('delegated-equal').and.returnValue(true) }, - matcher = j$.matchers.toThrowError(util), + matcherComparator = j$.matchers.toThrowError(util), fn = function() { throw new Error(); }, result; - result = matcher.compare(fn, Error); + result = matcherComparator(fn, Error); expect(result.pass).toBe(true); expect(result.message).toEqual("Expected function not to throw Error."); @@ -162,7 +162,7 @@ describe("toThrowError", function() { var util = { equals: jasmine.createSpy('delegated-equal').and.returnValue(true) }, - matcher = j$.matchers.toThrowError(util), + matcherComparator = j$.matchers.toThrowError(util), CustomError = function CustomError(arg) { arg.x }, fn = function() { throw new CustomError({ x: 1 }); @@ -172,7 +172,7 @@ describe("toThrowError", function() { CustomError.prototype = new Error(); CustomError.prototype.constructor = CustomError; - result = matcher.compare(fn, CustomError); + result = matcherComparator(fn, CustomError); expect(result.pass).toBe(true); expect(result.message).toEqual("Expected function not to throw CustomError."); @@ -182,13 +182,13 @@ describe("toThrowError", function() { var util = { equals: jasmine.createSpy('delegated-equal').and.returnValue(false) }, - matcher = j$.matchers.toThrowError(util), + matcherComparator = j$.matchers.toThrowError(util), fn = function() { throw new Error(); }, result; - result = matcher.compare(fn, TypeError); + result = matcherComparator(fn, TypeError); expect(result.pass).toBe(false); expect(result.message).toEqual("Expected function to throw TypeError, but it threw Error."); @@ -198,13 +198,13 @@ describe("toThrowError", function() { var util = { equals: jasmine.createSpy('delegated-equal').and.returnValue(true) }, - matcher = j$.matchers.toThrowError(util), + matcherComparator = j$.matchers.toThrowError(util), fn = function() { throw new TypeError("foo"); }, result; - result = matcher.compare(fn, TypeError, "foo"); + result = matcherComparator(fn, TypeError, "foo"); expect(result.pass).toBe(true); expect(result.message).toEqual("Expected function not to throw TypeError with message \"foo\"."); @@ -214,7 +214,7 @@ describe("toThrowError", function() { var util = { equals: jasmine.createSpy('delegated-equal').and.returnValue(true) }, - matcher = j$.matchers.toThrowError(util), + matcherComparator = j$.matchers.toThrowError(util), CustomError = function CustomError(arg) { this.message = arg.message }, fn = function() { throw new CustomError({message: "foo"}); @@ -224,7 +224,7 @@ describe("toThrowError", function() { CustomError.prototype = new Error(); CustomError.prototype.constructor = CustomError; - result = matcher.compare(fn, CustomError, "foo"); + result = matcherComparator(fn, CustomError, "foo"); expect(result.pass).toBe(true); expect(result.message).toEqual("Expected function not to throw CustomError with message \"foo\"."); @@ -234,13 +234,13 @@ describe("toThrowError", function() { var util = { equals: jasmine.createSpy('delegated-equal').and.returnValue(false) }, - matcher = j$.matchers.toThrowError(util), + matcherComparator = j$.matchers.toThrowError(util), fn = function() { throw new TypeError("foo"); }, result; - result = matcher.compare(fn, TypeError, "bar"); + result = matcherComparator(fn, TypeError, "bar"); expect(result.pass).toBe(false); expect(result.message).toEqual("Expected function to throw TypeError with message \"bar\", but it threw TypeError with message \"foo\"."); @@ -250,13 +250,13 @@ describe("toThrowError", function() { var util = { equals: jasmine.createSpy('delegated-equal').and.returnValue(true) }, - matcher = j$.matchers.toThrowError(util), + matcherComparator = j$.matchers.toThrowError(util), fn = function() { throw new TypeError("foo"); }, result; - result = matcher.compare(fn, TypeError, /foo/); + result = matcherComparator(fn, TypeError, /foo/); expect(result.pass).toBe(true); expect(result.message).toEqual("Expected function not to throw TypeError with message matching /foo/."); @@ -266,13 +266,13 @@ describe("toThrowError", function() { var util = { equals: jasmine.createSpy('delegated-equal').and.returnValue(false) }, - matcher = j$.matchers.toThrowError(util), + matcherComparator = j$.matchers.toThrowError(util), fn = function() { throw new TypeError("foo"); }, result; - result = matcher.compare(fn, TypeError, /bar/); + result = matcherComparator(fn, TypeError, /bar/); expect(result.pass).toBe(false); expect(result.message).toEqual("Expected function to throw TypeError with message matching /bar/, but it threw TypeError with message \"foo\"."); diff --git a/spec/core/matchers/toThrowSpec.js b/spec/core/matchers/toThrowSpec.js index 0f16673a..2c5b4b99 100644 --- a/spec/core/matchers/toThrowSpec.js +++ b/spec/core/matchers/toThrowSpec.js @@ -1,20 +1,20 @@ describe("toThrow", function() { it("throws an error when the actual is not a function", function() { - var matcher = j$.matchers.toThrow(); + var matcherComparator = j$.matchers.toThrow(); expect(function() { - matcher.compare({}); + matcherComparator({}); }).toThrow(new Error("Actual is not a Function")); // TODO: this needs to change for self-test }); it("fails if actual does not throw", function() { - var matcher = j$.matchers.toThrow(), + var matcherComparator = j$.matchers.toThrow(), fn = function() { return true; }, result; - result = matcher.compare(fn); + result = matcherComparator(fn); expect(result.pass).toBe(false); expect(result.message).toEqual("Expected function to throw an exception."); @@ -24,26 +24,26 @@ describe("toThrow", function() { var util = { equals: jasmine.createSpy('delegated-equal').and.returnValue(true) }, - matcher = j$.matchers.toThrow(util), + matcherComparator = j$.matchers.toThrow(util), fn = function() { throw 5; }, result; - result = matcher.compare(fn); + result = matcherComparator(fn); expect(result.pass).toBe(true); expect(result.message).toEqual("Expected function not to throw, but it threw 5."); }); it("passes even if what is thrown is falsy", function() { - var matcher = j$.matchers.toThrow(), + var matcherComparator = j$.matchers.toThrow(), fn = function() { throw undefined; }, result; - result = matcher.compare(fn); + result = matcherComparator(fn); expect(result.pass).toBe(true); expect(result.message).toEqual("Expected function not to throw, but it threw undefined."); }); @@ -52,13 +52,13 @@ describe("toThrow", function() { var util = { equals: jasmine.createSpy('delegated-equal').and.returnValue(true) }, - matcher = j$.matchers.toThrow(util), + matcherComparator = j$.matchers.toThrow(util), fn = function() { throw 5; }, result; - result = matcher.compare(fn, 5); + result = matcherComparator(fn, 5); expect(result.pass).toBe(true); expect(result.message).toEqual("Expected function not to throw 5."); @@ -68,13 +68,13 @@ describe("toThrow", function() { var util = { equals: jasmine.createSpy('delegated-equal').and.returnValue(false) }, - matcher = j$.matchers.toThrow(util), + matcherComparator = j$.matchers.toThrow(util), fn = function() { throw 5; }, result; - result = matcher.compare(fn, "foo"); + result = matcherComparator(fn, "foo"); expect(result.pass).toBe(false); expect(result.message).toEqual("Expected function to throw 'foo', but it threw 5."); @@ -84,15 +84,15 @@ describe("toThrow", function() { var util = { equals: jasmine.createSpy('delegated-equal').and.returnValue(false) }, - matcher = j$.matchers.toThrow(util), + matcherComparator = j$.matchers.toThrow(util), fn = function() { throw 5; }, result; - result = matcher.compare(fn, void 0); + result = matcherComparator(fn, void 0); expect(result.pass).toBe(false); expect(result.message).toEqual("Expected function to throw undefined, but it threw 5."); }); -}); \ No newline at end of file +}); diff --git a/src/core/Expectation.js b/src/core/Expectation.js index e8205eb9..ea6b630a 100644 --- a/src/core/Expectation.js +++ b/src/core/Expectation.js @@ -22,7 +22,8 @@ getJasmineRequireObj().Expectation = function() { args.unshift(this.actual); - var result = matcherFactory(this.util, this.customEqualityTesters).compare.apply(null, args); + var matcherComparator = matcherFactory(this.util, this.customEqualityTesters), + result = matcherComparator.apply(null, args); if (this.isNot) { result.pass = !result.pass; diff --git a/src/core/matchers/toBe.js b/src/core/matchers/toBe.js index f0bf88f6..e64c272d 100644 --- a/src/core/matchers/toBe.js +++ b/src/core/matchers/toBe.js @@ -1,11 +1,9 @@ getJasmineRequireObj().toBe = function() { function toBe() { - return { - compare: function(actual, expected) { - return { - pass: actual === expected - }; - } + return function(actual, expected) { + return { + pass: actual === expected + }; }; } diff --git a/src/core/matchers/toBeCloseTo.js b/src/core/matchers/toBeCloseTo.js index 52e63121..0e23c1f0 100644 --- a/src/core/matchers/toBeCloseTo.js +++ b/src/core/matchers/toBeCloseTo.js @@ -1,16 +1,14 @@ getJasmineRequireObj().toBeCloseTo = function() { function toBeCloseTo() { - return { - compare: function(actual, expected, precision) { - if (precision !== 0) { - precision = precision || 2; - } - - return { - pass: Math.abs(expected - actual) < (Math.pow(10, -precision) / 2) - }; + return function(actual, expected, precision) { + if (precision !== 0) { + precision = precision || 2; } + + return { + pass: Math.abs(expected - actual) < (Math.pow(10, -precision) / 2) + }; }; } diff --git a/src/core/matchers/toBeDefined.js b/src/core/matchers/toBeDefined.js index 68bca653..cb67b019 100644 --- a/src/core/matchers/toBeDefined.js +++ b/src/core/matchers/toBeDefined.js @@ -1,11 +1,9 @@ getJasmineRequireObj().toBeDefined = function() { function toBeDefined() { - return { - compare: function(actual) { - return { - pass: (void 0 !== actual) - }; - } + return function(actual) { + return { + pass: (void 0 !== actual) + }; }; } diff --git a/src/core/matchers/toBeFalsy.js b/src/core/matchers/toBeFalsy.js index 663c84e8..4a283631 100644 --- a/src/core/matchers/toBeFalsy.js +++ b/src/core/matchers/toBeFalsy.js @@ -1,11 +1,9 @@ getJasmineRequireObj().toBeFalsy = function() { function toBeFalsy() { - return { - compare: function(actual) { - return { - pass: !!!actual - }; - } + return function(actual) { + return { + pass: !!!actual + }; }; } diff --git a/src/core/matchers/toBeGreaterThan.js b/src/core/matchers/toBeGreaterThan.js index 61961591..b38536c1 100644 --- a/src/core/matchers/toBeGreaterThan.js +++ b/src/core/matchers/toBeGreaterThan.js @@ -1,12 +1,10 @@ getJasmineRequireObj().toBeGreaterThan = function() { function toBeGreaterThan() { - return { - compare: function(actual, expected) { - return { - pass: actual > expected - }; - } + return function(actual, expected) { + return { + pass: actual > expected + }; }; } diff --git a/src/core/matchers/toBeLessThan.js b/src/core/matchers/toBeLessThan.js index 2c29be35..3b3685f4 100644 --- a/src/core/matchers/toBeLessThan.js +++ b/src/core/matchers/toBeLessThan.js @@ -1,14 +1,11 @@ getJasmineRequireObj().toBeLessThan = function() { function toBeLessThan() { - return { - - compare: function(actual, expected) { - return { - pass: actual < expected - }; - } + return function(actual, expected) { + return { + pass: actual < expected + }; }; } return toBeLessThan; -}; \ No newline at end of file +}; diff --git a/src/core/matchers/toBeNaN.js b/src/core/matchers/toBeNaN.js index a8b0c270..c0bce5f2 100644 --- a/src/core/matchers/toBeNaN.js +++ b/src/core/matchers/toBeNaN.js @@ -1,20 +1,18 @@ getJasmineRequireObj().toBeNaN = function(j$) { function toBeNaN() { - return { - compare: function(actual) { - var result = { - pass: (actual !== actual) - }; + return function(actual) { + var result = { + pass: (actual !== actual) + }; - if (result.pass) { - result.message = "Expected actual not to be NaN."; - } else { - result.message = "Expected " + j$.pp(actual) + " to be NaN."; - } - - return result; + if (result.pass) { + result.message = "Expected actual not to be NaN."; + } else { + result.message = "Expected " + j$.pp(actual) + " to be NaN."; } + + return result; }; } diff --git a/src/core/matchers/toBeNull.js b/src/core/matchers/toBeNull.js index 47ba8ea5..0c084ec6 100644 --- a/src/core/matchers/toBeNull.js +++ b/src/core/matchers/toBeNull.js @@ -1,12 +1,10 @@ getJasmineRequireObj().toBeNull = function() { function toBeNull() { - return { - compare: function(actual) { - return { - pass: actual === null - }; - } + return function(actual) { + return { + pass: actual === null + }; }; } diff --git a/src/core/matchers/toBeTruthy.js b/src/core/matchers/toBeTruthy.js index 5ab044b5..75fbecc3 100644 --- a/src/core/matchers/toBeTruthy.js +++ b/src/core/matchers/toBeTruthy.js @@ -1,12 +1,10 @@ getJasmineRequireObj().toBeTruthy = function() { function toBeTruthy() { - return { - compare: function(actual) { - return { - pass: !!actual - }; - } + return function(actual) { + return { + pass: !!actual + }; }; } diff --git a/src/core/matchers/toBeUndefined.js b/src/core/matchers/toBeUndefined.js index dfae8f41..2f928176 100644 --- a/src/core/matchers/toBeUndefined.js +++ b/src/core/matchers/toBeUndefined.js @@ -1,12 +1,10 @@ getJasmineRequireObj().toBeUndefined = function() { function toBeUndefined() { - return { - compare: function(actual) { - return { - pass: void 0 === actual - }; - } + return function(actual) { + return { + pass: void 0 === actual + }; }; } diff --git a/src/core/matchers/toContain.js b/src/core/matchers/toContain.js index ac05cd24..9731d0fa 100644 --- a/src/core/matchers/toContain.js +++ b/src/core/matchers/toContain.js @@ -2,13 +2,10 @@ getJasmineRequireObj().toContain = function() { function toContain(util, customEqualityTesters) { customEqualityTesters = customEqualityTesters || []; - return { - compare: function(actual, expected) { - - return { - pass: util.contains(actual, expected, customEqualityTesters) - }; - } + return function(actual, expected) { + return { + pass: util.contains(actual, expected, customEqualityTesters) + }; }; } diff --git a/src/core/matchers/toEqual.js b/src/core/matchers/toEqual.js index 653541bc..cac225a5 100644 --- a/src/core/matchers/toEqual.js +++ b/src/core/matchers/toEqual.js @@ -3,16 +3,10 @@ getJasmineRequireObj().toEqual = function() { function toEqual(util, customEqualityTesters) { customEqualityTesters = customEqualityTesters || []; - return { - compare: function(actual, expected) { - var result = { - pass: false - }; - - result.pass = util.equals(actual, expected, customEqualityTesters); - - return result; - } + return function(actual, expected) { + return { + pass: util.equals(actual, expected, customEqualityTesters) + }; }; } diff --git a/src/core/matchers/toHaveBeenCalled.js b/src/core/matchers/toHaveBeenCalled.js index a1b647f1..1ab81295 100644 --- a/src/core/matchers/toHaveBeenCalled.js +++ b/src/core/matchers/toHaveBeenCalled.js @@ -1,26 +1,24 @@ getJasmineRequireObj().toHaveBeenCalled = function(j$) { function toHaveBeenCalled() { - return { - compare: function(actual) { - var result = {}; + return function(actual) { + var result = {}; - if (!j$.isSpy(actual)) { - throw new Error('Expected a spy, but got ' + j$.pp(actual) + '.'); - } - - if (arguments.length > 1) { - throw new Error('toHaveBeenCalled does not take arguments, use toHaveBeenCalledWith'); - } - - result.pass = actual.calls.any(); - - result.message = result.pass ? - "Expected spy " + actual.and.identity() + " not to have been called." : - "Expected spy " + actual.and.identity() + " to have been called."; - - return result; + if (!j$.isSpy(actual)) { + throw new Error('Expected a spy, but got ' + j$.pp(actual) + '.'); } + + if (arguments.length > 1) { + throw new Error('toHaveBeenCalled does not take arguments, use toHaveBeenCalledWith'); + } + + result.pass = actual.calls.any(); + + result.message = result.pass ? + "Expected spy " + actual.and.identity() + " not to have been called." : + "Expected spy " + actual.and.identity() + " to have been called."; + + return result; }; } diff --git a/src/core/matchers/toHaveBeenCalledWith.js b/src/core/matchers/toHaveBeenCalledWith.js index da9ccf37..4ccaf0bb 100644 --- a/src/core/matchers/toHaveBeenCalledWith.js +++ b/src/core/matchers/toHaveBeenCalledWith.js @@ -1,31 +1,29 @@ getJasmineRequireObj().toHaveBeenCalledWith = function(j$) { function toHaveBeenCalledWith(util) { - return { - compare: function() { - var args = Array.prototype.slice.call(arguments, 0), - actual = args[0], - expectedArgs = args.slice(1), - result = { pass: false }; + return function() { + var args = Array.prototype.slice.call(arguments, 0), + actual = args[0], + expectedArgs = args.slice(1), + result = { pass: false }; - if (!j$.isSpy(actual)) { - throw new Error('Expected a spy, but got ' + j$.pp(actual) + '.'); - } - - if (!actual.calls.any()) { - result.message = "Expected spy " + actual.and.identity() + " to have been called with " + j$.pp(expectedArgs) + " but it was never called."; - return result; - } - - if (util.contains(actual.calls.allArgs(), expectedArgs)) { - result.pass = true; - result.message = "Expected spy " + actual.and.identity() + " not to have been called with " + j$.pp(expectedArgs) + " but it was."; - } else { - result.message = "Expected spy " + actual.and.identity() + " to have been called with " + j$.pp(expectedArgs) + " but actual calls were " + j$.pp(actual.calls.allArgs()).replace(/^\[ | \]$/g, '') + "."; - } + if (!j$.isSpy(actual)) { + throw new Error('Expected a spy, but got ' + j$.pp(actual) + '.'); + } + if (!actual.calls.any()) { + result.message = "Expected spy " + actual.and.identity() + " to have been called with " + j$.pp(expectedArgs) + " but it was never called."; return result; } + + if (util.contains(actual.calls.allArgs(), expectedArgs)) { + result.pass = true; + result.message = "Expected spy " + actual.and.identity() + " not to have been called with " + j$.pp(expectedArgs) + " but it was."; + } else { + result.message = "Expected spy " + actual.and.identity() + " to have been called with " + j$.pp(expectedArgs) + " but actual calls were " + j$.pp(actual.calls.allArgs()).replace(/^\[ | \]$/g, '') + "."; + } + + return result; }; } diff --git a/src/core/matchers/toMatch.js b/src/core/matchers/toMatch.js index 38309fd0..1479f321 100644 --- a/src/core/matchers/toMatch.js +++ b/src/core/matchers/toMatch.js @@ -1,14 +1,12 @@ getJasmineRequireObj().toMatch = function() { function toMatch() { - return { - compare: function(actual, expected) { - var regexp = new RegExp(expected); + return function(actual, expected) { + var regexp = new RegExp(expected); - return { - pass: regexp.test(actual) - }; - } + return { + pass: regexp.test(actual) + }; }; } diff --git a/src/core/matchers/toThrow.js b/src/core/matchers/toThrow.js index 4a2fa1dd..fa2291dd 100644 --- a/src/core/matchers/toThrow.js +++ b/src/core/matchers/toThrow.js @@ -1,44 +1,42 @@ getJasmineRequireObj().toThrow = function(j$) { function toThrow(util) { - return { - compare: function(actual, expected) { - var result = { pass: false }, - threw = false, - thrown; + return function(actual, expected) { + var result = { pass: false }, + threw = false, + thrown; - if (typeof actual != "function") { - throw new Error("Actual is not a Function"); - } + if (typeof actual != "function") { + throw new Error("Actual is not a Function"); + } - try { - actual(); - } catch (e) { - threw = true; - thrown = e; - } + try { + actual(); + } catch (e) { + threw = true; + thrown = e; + } - if (!threw) { - result.message = "Expected function to throw an exception."; - return result; - } + if (!threw) { + result.message = "Expected function to throw an exception."; + return result; + } - if (arguments.length == 1) { - result.pass = true; - result.message = "Expected function not to throw, but it threw " + j$.pp(thrown) + "."; - - return result; - } - - if (util.equals(thrown, expected)) { - result.pass = true; - result.message = "Expected function not to throw " + j$.pp(expected) + "."; - } else { - result.message = "Expected function to throw " + j$.pp(expected) + ", but it threw " + j$.pp(thrown) + "."; - } + if (arguments.length == 1) { + result.pass = true; + result.message = "Expected function not to throw, but it threw " + j$.pp(thrown) + "."; return result; } + + if (util.equals(thrown, expected)) { + result.pass = true; + result.message = "Expected function not to throw " + j$.pp(expected) + "."; + } else { + result.message = "Expected function to throw " + j$.pp(expected) + ", but it threw " + j$.pp(thrown) + "."; + } + + return result; }; } diff --git a/src/core/matchers/toThrowError.js b/src/core/matchers/toThrowError.js index ca5a7df0..e09dd041 100644 --- a/src/core/matchers/toThrowError.js +++ b/src/core/matchers/toThrowError.js @@ -1,152 +1,150 @@ getJasmineRequireObj().toThrowError = function(j$) { function toThrowError (util) { - return { - compare: function(actual) { - var threw = false, - thrown, - errorType, - message, - regexp, - name, - constructorName; + return function(actual) { + var threw = false, + thrown, + errorType, + message, + regexp, + name, + constructorName; - if (typeof actual != "function") { - throw new Error("Actual is not a Function"); + if (typeof actual != "function") { + throw new Error("Actual is not a Function"); + } + + extractExpectedParams.apply(null, arguments); + + try { + actual(); + } catch (e) { + threw = true; + thrown = e; + } + + if (!threw) { + return fail("Expected function to throw an Error."); + } + + if (!(thrown instanceof Error)) { + return fail("Expected function to throw an Error, but it threw " + thrown + "."); + } + + if (arguments.length == 1) { + return pass("Expected function not to throw an Error, but it threw " + fnNameFor(thrown) + "."); + } + + if (errorType) { + name = fnNameFor(errorType); + constructorName = fnNameFor(thrown.constructor); + } + + if (errorType && message) { + if (thrown.constructor == errorType && util.equals(thrown.message, message)) { + return pass("Expected function not to throw " + name + " with message \"" + message + "\"."); + } else { + return fail("Expected function to throw " + name + " with message \"" + message + + "\", but it threw " + constructorName + " with message \"" + thrown.message + "\"."); } + } - extractExpectedParams.apply(null, arguments); - - try { - actual(); - } catch (e) { - threw = true; - thrown = e; + if (errorType && regexp) { + if (thrown.constructor == errorType && regexp.test(thrown.message)) { + return pass("Expected function not to throw " + name + " with message matching " + regexp + "."); + } else { + return fail("Expected function to throw " + name + " with message matching " + regexp + + ", but it threw " + constructorName + " with message \"" + thrown.message + "\"."); } + } - if (!threw) { - return fail("Expected function to throw an Error."); + if (errorType) { + if (thrown.constructor == errorType) { + return pass("Expected function not to throw " + name + "."); + } else { + return fail("Expected function to throw " + name + ", but it threw " + constructorName + "."); } + } - if (!(thrown instanceof Error)) { - return fail("Expected function to throw an Error, but it threw " + thrown + "."); + if (message) { + if (thrown.message == message) { + return pass("Expected function not to throw an exception with message " + j$.pp(message) + "."); + } else { + return fail("Expected function to throw an exception with message " + j$.pp(message) + + ", but it threw an exception with message " + j$.pp(thrown.message) + "."); } + } + if (regexp) { + if (regexp.test(thrown.message)) { + return pass("Expected function not to throw an exception with a message matching " + j$.pp(regexp) + "."); + } else { + return fail("Expected function to throw an exception with a message matching " + j$.pp(regexp) + + ", but it threw an exception with message " + j$.pp(thrown.message) + "."); + } + } + + function fnNameFor(func) { + return func.name || func.toString().match(/^\s*function\s*(\w*)\s*\(/)[1]; + } + + function pass(notMessage) { + return { + pass: true, + message: notMessage + }; + } + + function fail(message) { + return { + pass: false, + message: message + }; + } + + function extractExpectedParams() { if (arguments.length == 1) { - return pass("Expected function not to throw an Error, but it threw " + fnNameFor(thrown) + "."); + return; } - if (errorType) { - name = fnNameFor(errorType); - constructorName = fnNameFor(thrown.constructor); - } + if (arguments.length == 2) { + var expected = arguments[1]; - if (errorType && message) { - if (thrown.constructor == errorType && util.equals(thrown.message, message)) { - return pass("Expected function not to throw " + name + " with message \"" + message + "\"."); + if (expected instanceof RegExp) { + regexp = expected; + } else if (typeof expected == "string") { + message = expected; + } else if (checkForAnErrorType(expected)) { + errorType = expected; + } + + if (!(errorType || message || regexp)) { + throw new Error("Expected is not an Error, string, or RegExp."); + } + } else { + if (checkForAnErrorType(arguments[1])) { + errorType = arguments[1]; } else { - return fail("Expected function to throw " + name + " with message \"" + message + - "\", but it threw " + constructorName + " with message \"" + thrown.message + "\"."); + throw new Error("Expected error type is not an Error."); } - } - if (errorType && regexp) { - if (thrown.constructor == errorType && regexp.test(thrown.message)) { - return pass("Expected function not to throw " + name + " with message matching " + regexp + "."); + if (arguments[2] instanceof RegExp) { + regexp = arguments[2]; + } else if (typeof arguments[2] == "string") { + message = arguments[2]; } else { - return fail("Expected function to throw " + name + " with message matching " + regexp + - ", but it threw " + constructorName + " with message \"" + thrown.message + "\"."); + throw new Error("Expected error message is not a string or RegExp."); } } + } - if (errorType) { - if (thrown.constructor == errorType) { - return pass("Expected function not to throw " + name + "."); - } else { - return fail("Expected function to throw " + name + ", but it threw " + constructorName + "."); - } + function checkForAnErrorType(type) { + if (typeof type !== "function") { + return false; } - if (message) { - if (thrown.message == message) { - return pass("Expected function not to throw an exception with message " + j$.pp(message) + "."); - } else { - return fail("Expected function to throw an exception with message " + j$.pp(message) + - ", but it threw an exception with message " + j$.pp(thrown.message) + "."); - } - } - - if (regexp) { - if (regexp.test(thrown.message)) { - return pass("Expected function not to throw an exception with a message matching " + j$.pp(regexp) + "."); - } else { - return fail("Expected function to throw an exception with a message matching " + j$.pp(regexp) + - ", but it threw an exception with message " + j$.pp(thrown.message) + "."); - } - } - - function fnNameFor(func) { - return func.name || func.toString().match(/^\s*function\s*(\w*)\s*\(/)[1]; - } - - function pass(notMessage) { - return { - pass: true, - message: notMessage - }; - } - - function fail(message) { - return { - pass: false, - message: message - }; - } - - function extractExpectedParams() { - if (arguments.length == 1) { - return; - } - - if (arguments.length == 2) { - var expected = arguments[1]; - - if (expected instanceof RegExp) { - regexp = expected; - } else if (typeof expected == "string") { - message = expected; - } else if (checkForAnErrorType(expected)) { - errorType = expected; - } - - if (!(errorType || message || regexp)) { - throw new Error("Expected is not an Error, string, or RegExp."); - } - } else { - if (checkForAnErrorType(arguments[1])) { - errorType = arguments[1]; - } else { - throw new Error("Expected error type is not an Error."); - } - - if (arguments[2] instanceof RegExp) { - regexp = arguments[2]; - } else if (typeof arguments[2] == "string") { - message = arguments[2]; - } else { - throw new Error("Expected error message is not a string or RegExp."); - } - } - } - - function checkForAnErrorType(type) { - if (typeof type !== "function") { - return false; - } - - var Surrogate = function() {}; - Surrogate.prototype = type.prototype; - return (new Surrogate()) instanceof Error; - } + var Surrogate = function() {}; + Surrogate.prototype = type.prototype; + return (new Surrogate()) instanceof Error; } }; }