Revert removal of compare nesting

Since we want the user to be able to pass a negative comparison function, the extra layer of wrapping is now needed
This commit is contained in:
Kyriacos Souroullas and Sheel Choksi
2013-10-28 13:49:54 -07:00
parent dd8a455f91
commit e346e7dcc1
37 changed files with 493 additions and 435 deletions

View File

@@ -10,10 +10,12 @@ describe("Custom Matchers (Integration)", function() {
env.it('spec defining a custom matcher', function() { env.it('spec defining a custom matcher', function() {
env.addMatchers({ env.addMatchers({
matcherForSpec: function() { matcherForSpec: function() {
return function(actual, expected) { return {
compare: function(actual, expected) {
return { pass: false, message: "matcherForSpec: actual: " + actual + "; expected: " + expected }; return { pass: false, message: "matcherForSpec: actual: " + actual + "; expected: " + expected };
} }
} }
}
}); });
env.expect("zzz").matcherForSpec("yyy"); env.expect("zzz").matcherForSpec("yyy");
@@ -38,7 +40,7 @@ describe("Custom Matchers (Integration)", function() {
it("passes the spec if the custom matcher passes", function(done) { it("passes the spec if the custom matcher passes", function(done) {
env.addMatchers({ env.addMatchers({
toBeReal: function() { toBeReal: function() {
return function() { return { pass: true }; }; return { compare: function() { return { pass: true }; } };
} }
}); });
@@ -57,10 +59,12 @@ describe("Custom Matchers (Integration)", function() {
it("generates messages with the same rules as built in matchers absent a custom message", function(done) { it("generates messages with the same rules as built in matchers absent a custom message", function(done) {
env.addMatchers({ env.addMatchers({
toBeReal: function() { toBeReal: function() {
return function() { return {
compare: function() {
return { pass: false }; return { pass: false };
} }
} }
}
}); });
env.it('spec with an expectation', function() { env.it('spec with an expectation', function() {
@@ -79,7 +83,7 @@ describe("Custom Matchers (Integration)", function() {
var argumentSpy = jasmine.createSpy("argument spy").and.returnValue({ pass: true }); var argumentSpy = jasmine.createSpy("argument spy").and.returnValue({ pass: true });
env.addMatchers({ env.addMatchers({
toBeReal: function() { toBeReal: function() {
return argumentSpy; return { compare: argumentSpy };
} }
}); });
@@ -100,7 +104,7 @@ describe("Custom Matchers (Integration)", function() {
}); });
it("passes the jasmine utility and current equality matchers to the expectation factory", function(done) { it("passes the jasmine utility and current equality matchers to the expectation factory", function(done) {
var matcherFactory = function() { return function() { return { pass: true }; }; }, var matcherFactory = function() { return { compare: function() { return {pass: true}; }}; },
argumentSpy = jasmine.createSpy("argument spy").and.returnValue(matcherFactory), argumentSpy = jasmine.createSpy("argument spy").and.returnValue(matcherFactory),
customEqualityFn = function() { return true; }; customEqualityFn = function() { return true; };

View File

@@ -56,7 +56,7 @@ describe("Expectation", function() {
it("wraps matchers's compare functions, passing in matcher dependencies", function() { it("wraps matchers's compare functions, passing in matcher dependencies", function() {
var fakeCompare = function() { return { pass: true }; }, var fakeCompare = function() { return { pass: true }; },
matcherFactory = jasmine.createSpy("matcher").and.returnValue(fakeCompare), matcherFactory = jasmine.createSpy("matcher").and.returnValue({ compare: fakeCompare }),
matchers = { matchers = {
toFoo: matcherFactory toFoo: matcherFactory
}, },
@@ -83,7 +83,9 @@ describe("Expectation", function() {
var fakeCompare = jasmine.createSpy('fake-compare').and.returnValue({pass: true}), var fakeCompare = jasmine.createSpy('fake-compare').and.returnValue({pass: true}),
matchers = { matchers = {
toFoo: function() { toFoo: function() {
return fakeCompare; return {
compare: fakeCompare
};
} }
}, },
util = { util = {
@@ -108,7 +110,9 @@ describe("Expectation", function() {
it("reports a passing result to the spec when the comparison passes", function() { it("reports a passing result to the spec when the comparison passes", function() {
var matchers = { var matchers = {
toFoo: function() { toFoo: function() {
return function() { return { pass: true }; }; return {
compare: function() { return { pass: true }; }
};
} }
}, },
util = { util = {
@@ -140,7 +144,9 @@ describe("Expectation", function() {
it("reports a failing result to the spec when the comparison fails", function() { it("reports a failing result to the spec when the comparison fails", function() {
var matchers = { var matchers = {
toFoo: function() { toFoo: function() {
return function() { return { pass: false }; }; return {
compare: function() { return { pass: false }; }
};
} }
}, },
util = { util = {
@@ -172,11 +178,13 @@ describe("Expectation", function() {
it("reports a failing result and a custom fail message to the spec when the comparison fails", function() { it("reports a failing result and a custom fail message to the spec when the comparison fails", function() {
var matchers = { var matchers = {
toFoo: function() { toFoo: function() {
return function() { return {
compare: function() {
return { return {
pass: false, pass: false,
message: "I am a custom message" message: "I am a custom message"
}; };
}
}; };
} }
}, },
@@ -205,7 +213,9 @@ describe("Expectation", function() {
it("reports a passing result to the spec when the comparison fails for a negative expectation", function() { it("reports a passing result to the spec when the comparison fails for a negative expectation", function() {
var matchers = { var matchers = {
toFoo: function() { toFoo: function() {
return function() { return { pass: false }; }; return {
compare: function() { return { pass: false }; }
};
} }
}, },
util = { util = {
@@ -238,7 +248,9 @@ describe("Expectation", function() {
it("reports a failing result to the spec when the comparison passes for a negative expectation", function() { it("reports a failing result to the spec when the comparison passes for a negative expectation", function() {
var matchers = { var matchers = {
toFoo: function() { toFoo: function() {
return function() { return { pass: true }; }; return {
compare: function() { return { pass: true }; }
};
} }
}, },
util = { util = {
@@ -272,11 +284,13 @@ 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() { it("reports a failing result and a custom fail message to the spec when the comparison passes for a negative expectation", function() {
var matchers = { var matchers = {
toFoo: function() { toFoo: function() {
return function() { return {
compare: function() {
return { return {
pass: true, pass: true,
message: "I am a custom message" message: "I am a custom message"
}; };
}
}; };
} }
}, },

View File

@@ -1,51 +1,51 @@
describe("toBeCloseTo", function() { describe("toBeCloseTo", function() {
it("passes when within two decimal places by default", function() { it("passes when within two decimal places by default", function() {
var matcherComparator = j$.matchers.toBeCloseTo(), var matcher = j$.matchers.toBeCloseTo(),
result; result;
result = matcherComparator(0, 0); result = matcher.compare(0, 0);
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
result = matcherComparator(0, 0.001); result = matcher.compare(0, 0.001);
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
}); });
it("fails when not within two decimal places by default", function() { it("fails when not within two decimal places by default", function() {
var matcherComparator = j$.matchers.toBeCloseTo(), var matcher = j$.matchers.toBeCloseTo(),
result; result;
result = matcherComparator(0, 0.01); result = matcher.compare(0, 0.01);
expect(result.pass).toBe(false); expect(result.pass).toBe(false);
}); });
it("accepts an optional precision argument", function() { it("accepts an optional precision argument", function() {
var matcherComparator = j$.matchers.toBeCloseTo(), var matcher = j$.matchers.toBeCloseTo(),
result; result;
result = matcherComparator(0, 0.1, 0); result = matcher.compare(0, 0.1, 0);
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
result = matcherComparator(0, 0.0001, 3); result = matcher.compare(0, 0.0001, 3);
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
}); });
it("rounds expected values", function() { it("rounds expected values", function() {
var matcherComparator = j$.matchers.toBeCloseTo(), var matcher = j$.matchers.toBeCloseTo(),
result; result;
result = matcherComparator(1.23, 1.229); result = matcher.compare(1.23, 1.229);
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
result = matcherComparator(1.23, 1.226); result = matcher.compare(1.23, 1.226);
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
result = matcherComparator(1.23, 1.225); result = matcher.compare(1.23, 1.225);
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
result = matcherComparator(1.23, 1.2249999); result = matcher.compare(1.23, 1.2249999);
expect(result.pass).toBe(false); expect(result.pass).toBe(false);
result = matcherComparator(1.23, 1.234); result = matcher.compare(1.23, 1.234);
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
}); });
}); });

View File

@@ -1,18 +1,18 @@
describe("toBeDefined", function() { describe("toBeDefined", function() {
it("matches for defined values", function() { it("matches for defined values", function() {
var matcherComparator = j$.matchers.toBeDefined(), var matcher = j$.matchers.toBeDefined(),
result; result;
result = matcherComparator('foo'); result = matcher.compare('foo');
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
}); });
it("fails when matching undefined values", function() { it("fails when matching undefined values", function() {
var matcherComparator = j$.matchers.toBeDefined(), var matcher = j$.matchers.toBeDefined(),
result; result;
result = matcherComparator(void 0); result = matcher.compare(void 0);
expect(result.pass).toBe(false); expect(result.pass).toBe(false);
}) })
}); });

View File

@@ -1,38 +1,38 @@
describe("toBeFalsy", function() { describe("toBeFalsy", function() {
it("passes for 'falsy' values", function() { it("passes for 'falsy' values", function() {
var matcherComparator = j$.matchers.toBeFalsy(), var matcher = j$.matchers.toBeFalsy(),
result; result;
result = matcherComparator(false); result = matcher.compare(false);
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
result = matcherComparator(0); result = matcher.compare(0);
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
result = matcherComparator(''); result = matcher.compare('');
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
result = matcherComparator(null); result = matcher.compare(null);
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
result = matcherComparator(void 0); result = matcher.compare(void 0);
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
}); });
it("fails for 'truthy' values", function() { it("fails for 'truthy' values", function() {
var matcherComparator = j$.matchers.toBeFalsy(), var matcher = j$.matchers.toBeFalsy(),
result; result;
result = matcherComparator(true); result = matcher.compare(true);
expect(result.pass).toBe(false); expect(result.pass).toBe(false);
result = matcherComparator(1); result = matcher.compare(1);
expect(result.pass).toBe(false); expect(result.pass).toBe(false);
result = matcherComparator("foo"); result = matcher.compare("foo");
expect(result.pass).toBe(false); expect(result.pass).toBe(false);
result = matcherComparator({}); result = matcher.compare({});
expect(result.pass).toBe(false); expect(result.pass).toBe(false);
}); });
}); });

View File

@@ -1,19 +1,19 @@
describe("toBeGreaterThan", function() { describe("toBeGreaterThan", function() {
it("passes when actual > expected", function() { it("passes when actual > expected", function() {
var matcherComparator = j$.matchers.toBeGreaterThan(), var matcher = j$.matchers.toBeGreaterThan(),
result; result;
result = matcherComparator(2, 1); result = matcher.compare(2, 1);
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
}); });
it("fails when actual <= expected", function() { it("fails when actual <= expected", function() {
var matcherComparator = j$.matchers.toBeGreaterThan(); var matcher = j$.matchers.toBeGreaterThan();
result = matcherComparator(1, 1); result = matcher.compare(1, 1);
expect(result.pass).toBe(false); expect(result.pass).toBe(false);
result = matcherComparator(1, 2); result = matcher.compare(1, 2);
expect(result.pass).toBe(false); expect(result.pass).toBe(false);
}); });
}); });

View File

@@ -1,20 +1,20 @@
describe("toBeLessThan", function() { describe("toBeLessThan", function() {
it("passes when actual < expected", function() { it("passes when actual < expected", function() {
var matcherComparator = j$.matchers.toBeLessThan(), var matcher = j$.matchers.toBeLessThan(),
result; result;
result = matcherComparator(1, 2); result = matcher.compare(1, 2);
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
}); });
it("fails when actual <= expected", function() { it("fails when actual <= expected", function() {
var matcherComparator = j$.matchers.toBeLessThan(), var matcher = j$.matchers.toBeLessThan(),
result; result;
result = matcherComparator(1, 1); result = matcher.compare(1, 1);
expect(result.pass).toBe(false); expect(result.pass).toBe(false);
result = matcherComparator(2, 1); result = matcher.compare(2, 1);
expect(result.pass).toBe(false); expect(result.pass).toBe(false);
}); });
}); });

View File

@@ -1,35 +1,35 @@
describe("toBeNaN", function() { describe("toBeNaN", function() {
it("passes for NaN with a custom .not fail", function() { it("passes for NaN with a custom .not fail", function() {
var matcherComparator = j$.matchers.toBeNaN(), var matcher = j$.matchers.toBeNaN(),
result; result;
result = matcherComparator(Number.NaN); result = matcher.compare(Number.NaN);
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
expect(result.message).toEqual("Expected actual not to be NaN."); expect(result.message).toEqual("Expected actual not to be NaN.");
}); });
it("fails for anything not a NaN", function() { it("fails for anything not a NaN", function() {
var matcherComparator = j$.matchers.toBeNaN(); var matcher = j$.matchers.toBeNaN();
result = matcherComparator(1); result = matcher.compare(1);
expect(result.pass).toBe(false); expect(result.pass).toBe(false);
result = matcherComparator(null); result = matcher.compare(null);
expect(result.pass).toBe(false); expect(result.pass).toBe(false);
result = matcherComparator(void 0); result = matcher.compare(void 0);
expect(result.pass).toBe(false); expect(result.pass).toBe(false);
result = matcherComparator(''); result = matcher.compare('');
expect(result.pass).toBe(false); expect(result.pass).toBe(false);
result = matcherComparator(Number.POSITIVE_INFINITY); result = matcher.compare(Number.POSITIVE_INFINITY);
expect(result.pass).toBe(false); expect(result.pass).toBe(false);
}); });
it("has a custom message on failure", function() { it("has a custom message on failure", function() {
var matcherComparator = j$.matchers.toBeNaN(), var matcher = j$.matchers.toBeNaN(),
result = matcherComparator(0); result = matcher.compare(0);
expect(result.message).toEqual("Expected 0 to be NaN."); expect(result.message).toEqual("Expected 0 to be NaN.");
}); });

View File

@@ -1,17 +1,17 @@
describe("toBeNull", function() { describe("toBeNull", function() {
it("passes for null", function() { it("passes for null", function() {
var matcherComparator = j$.matchers.toBeNull(), var matcher = j$.matchers.toBeNull(),
result; result;
result = matcherComparator(null); result = matcher.compare(null);
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
}); });
it("fails for non-null", function() { it("fails for non-null", function() {
var matcherComparator = j$.matchers.toBeNull(), var matcher = j$.matchers.toBeNull(),
result; result;
result = matcherComparator('foo'); result = matcher.compare('foo');
expect(result.pass).toBe(false); expect(result.pass).toBe(false);
}); });
}); });

View File

@@ -1,17 +1,17 @@
describe("toBe", function() { describe("toBe", function() {
it("passes when actual === expected", function() { it("passes when actual === expected", function() {
var matcherComparator = j$.matchers.toBe(), var matcher = j$.matchers.toBe(),
result; result;
result = matcherComparator(1, 1); result = matcher.compare(1, 1);
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
}); });
it("fails when actual !== expected", function() { it("fails when actual !== expected", function() {
var matcherComparator = j$.matchers.toBe(), var matcher = j$.matchers.toBe(),
result; result;
result = matcherComparator(1, 2); result = matcher.compare(1, 2);
expect(result.pass).toBe(false); expect(result.pass).toBe(false);
}); });
}); });

View File

@@ -1,38 +1,38 @@
describe("toBeTruthy", function() { describe("toBeTruthy", function() {
it("passes for 'truthy' values", function() { it("passes for 'truthy' values", function() {
var matcherComparator = j$.matchers.toBeTruthy(), var matcher = j$.matchers.toBeTruthy(),
result; result;
result = matcherComparator(true); result = matcher.compare(true);
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
result = matcherComparator(1); result = matcher.compare(1);
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
result = matcherComparator("foo"); result = matcher.compare("foo");
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
result = matcherComparator({}); result = matcher.compare({});
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
}); });
it("fails for 'falsy' values", function() { it("fails for 'falsy' values", function() {
var matcherComparator = j$.matchers.toBeTruthy(), var matcher = j$.matchers.toBeTruthy(),
result; result;
result = matcherComparator(false); result = matcher.compare(false);
expect(result.pass).toBe(false); expect(result.pass).toBe(false);
result = matcherComparator(0); result = matcher.compare(0);
expect(result.pass).toBe(false); expect(result.pass).toBe(false);
result = matcherComparator(''); result = matcher.compare('');
expect(result.pass).toBe(false); expect(result.pass).toBe(false);
result = matcherComparator(null); result = matcher.compare(null);
expect(result.pass).toBe(false); expect(result.pass).toBe(false);
result = matcherComparator(void 0); result = matcher.compare(void 0);
expect(result.pass).toBe(false); expect(result.pass).toBe(false);
}); });
}); });

View File

@@ -1,17 +1,17 @@
describe("toBeUndefined", function() { describe("toBeUndefined", function() {
it("passes for undefined values", function() { it("passes for undefined values", function() {
var matcherComparator = j$.matchers.toBeUndefined(), var matcher = j$.matchers.toBeUndefined(),
result; result;
result = matcherComparator(void 0); result = matcher.compare(void 0);
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
}); });
it("fails when matching defined values", function() { it("fails when matching defined values", function() {
var matcherComparator = j$.matchers.toBeUndefined(); var matcher = j$.matchers.toBeUndefined();
result = matcherComparator('foo'); result = matcher.compare('foo');
expect(result.pass).toBe(false); expect(result.pass).toBe(false);
}) })
}); });

View File

@@ -3,9 +3,9 @@ describe("toContain", function() {
var util = { var util = {
contains: jasmine.createSpy('delegated-contains').and.returnValue(true) contains: jasmine.createSpy('delegated-contains').and.returnValue(true)
}, },
matcherComparator = j$.matchers.toContain(util); matcher = j$.matchers.toContain(util);
result = matcherComparator("ABC", "B"); result = matcher.compare("ABC", "B");
expect(util.contains).toHaveBeenCalledWith("ABC", "B", []); expect(util.contains).toHaveBeenCalledWith("ABC", "B", []);
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
}); });
@@ -15,9 +15,9 @@ describe("toContain", function() {
contains: jasmine.createSpy('delegated-contains').and.returnValue(true) contains: jasmine.createSpy('delegated-contains').and.returnValue(true)
}, },
customEqualityTesters = ['a', 'b'], customEqualityTesters = ['a', 'b'],
matcherComparator = j$.matchers.toContain(util, customEqualityTesters); matcher = j$.matchers.toContain(util, customEqualityTesters);
result = matcherComparator("ABC", "B"); result = matcher.compare("ABC", "B");
expect(util.contains).toHaveBeenCalledWith("ABC", "B", ['a', 'b']); expect(util.contains).toHaveBeenCalledWith("ABC", "B", ['a', 'b']);
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
}); });

View File

@@ -3,10 +3,10 @@ describe("toEqual", function() {
var util = { var util = {
equals: jasmine.createSpy('delegated-equals').and.returnValue(true) equals: jasmine.createSpy('delegated-equals').and.returnValue(true)
}, },
matcherComparator = j$.matchers.toEqual(util), matcher = j$.matchers.toEqual(util),
result; result;
result = matcherComparator(1, 1); result = matcher.compare(1, 1);
expect(util.equals).toHaveBeenCalledWith(1, 1, []); expect(util.equals).toHaveBeenCalledWith(1, 1, []);
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
@@ -17,10 +17,10 @@ describe("toEqual", function() {
equals: jasmine.createSpy('delegated-equals').and.returnValue(true) equals: jasmine.createSpy('delegated-equals').and.returnValue(true)
}, },
customEqualityTesters = ['a', 'b'], customEqualityTesters = ['a', 'b'],
matcherComparator = j$.matchers.toEqual(util, customEqualityTesters), matcher = j$.matchers.toEqual(util, customEqualityTesters),
result; result;
result = matcherComparator(1, 1); result = matcher.compare(1, 1);
expect(util.equals).toHaveBeenCalledWith(1, 1, ['a', 'b']); expect(util.equals).toHaveBeenCalledWith(1, 1, ['a', 'b']);
expect(result.pass).toBe(true); expect(result.pass).toBe(true);

View File

@@ -1,44 +1,44 @@
describe("toHaveBeenCalled", function() { describe("toHaveBeenCalled", function() {
it("passes when the actual was called, with a custom .not fail message", function() { it("passes when the actual was called, with a custom .not fail message", function() {
var matcherComparator = j$.matchers.toHaveBeenCalled(), var matcher = j$.matchers.toHaveBeenCalled(),
calledSpy = j$.createSpy('called-spy'), calledSpy = j$.createSpy('called-spy'),
result; result;
calledSpy(); calledSpy();
result = matcherComparator(calledSpy); result = matcher.compare(calledSpy);
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
expect(result.message).toEqual("Expected spy called-spy not to have been called."); expect(result.message).toEqual("Expected spy called-spy not to have been called.");
}); });
it("fails when the actual was not called", function() { it("fails when the actual was not called", function() {
var matcherComparator = j$.matchers.toHaveBeenCalled(), var matcher = j$.matchers.toHaveBeenCalled(),
uncalledSpy = j$.createSpy('uncalled spy'); uncalledSpy = j$.createSpy('uncalled spy');
result = matcherComparator(uncalledSpy); result = matcher.compare(uncalledSpy);
expect(result.pass).toBe(false); expect(result.pass).toBe(false);
}); });
it("throws an exception when the actual is not a spy", function() { it("throws an exception when the actual is not a spy", function() {
var matcherComparator = j$.matchers.toHaveBeenCalled(), var matcher = j$.matchers.toHaveBeenCalled(),
fn = function() {}; fn = function() {};
expect(function() { matcherComparator(fn) }).toThrow(new Error("Expected a spy, but got Function.")); expect(function() { matcher.compare(fn) }).toThrow(new Error("Expected a spy, but got Function."));
}); });
it("throws an exception when invoked with any arguments", function() { it("throws an exception when invoked with any arguments", function() {
var matcherComparator = j$.matchers.toHaveBeenCalled(), var matcher = j$.matchers.toHaveBeenCalled(),
spy = j$.createSpy('sample spy'); spy = j$.createSpy('sample spy');
expect(function() { matcherComparator(spy, 'foo') }).toThrow(new Error("toHaveBeenCalled does not take arguments, use toHaveBeenCalledWith")); expect(function() { matcher.compare(spy, 'foo') }).toThrow(new Error("toHaveBeenCalled does not take arguments, use toHaveBeenCalledWith"));
}); });
it("has a custom message on failure", function() { it("has a custom message on failure", function() {
var matcherComparator = j$.matchers.toHaveBeenCalled(), var matcher = j$.matchers.toHaveBeenCalled(),
spy = j$.createSpy('sample-spy'), spy = j$.createSpy('sample-spy'),
result; result;
result = matcherComparator(spy); result = matcher.compare(spy);
expect(result.message).toEqual("Expected spy sample-spy to have been called."); expect(result.message).toEqual("Expected spy sample-spy to have been called.");
}); });

View File

@@ -3,12 +3,12 @@ describe("toHaveBeenCalledWith", function() {
var util = { var util = {
contains: jasmine.createSpy('delegated-contains').and.returnValue(true) contains: jasmine.createSpy('delegated-contains').and.returnValue(true)
}, },
matcherComparator = j$.matchers.toHaveBeenCalledWith(util), matcher = j$.matchers.toHaveBeenCalledWith(util),
calledSpy = j$.createSpy('called-spy'), calledSpy = j$.createSpy('called-spy'),
result; result;
calledSpy('a', 'b'); calledSpy('a', 'b');
result = matcherComparator(calledSpy, 'a', 'b'); result = matcher.compare(calledSpy, 'a', 'b');
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
expect(result.message).toEqual("Expected spy called-spy not to have been called with [ 'a', 'b' ] but it was."); 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 = { var util = {
contains: jasmine.createSpy('delegated-contains').and.returnValue(false) contains: jasmine.createSpy('delegated-contains').and.returnValue(false)
}, },
matcherComparator = j$.matchers.toHaveBeenCalledWith(util), matcher = j$.matchers.toHaveBeenCalledWith(util),
uncalledSpy = j$.createSpy('uncalled spy'), uncalledSpy = j$.createSpy('uncalled spy'),
result; result;
result = matcherComparator(uncalledSpy); result = matcher.compare(uncalledSpy);
expect(result.pass).toBe(false); expect(result.pass).toBe(false);
expect(result.message).toEqual("Expected spy uncalled spy to have been called with [ ] but it was never called."); 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 = { var util = {
contains: jasmine.createSpy('delegated-contains').and.returnValue(false) contains: jasmine.createSpy('delegated-contains').and.returnValue(false)
}, },
matcherComparator = j$.matchers.toHaveBeenCalledWith(util), matcher = j$.matchers.toHaveBeenCalledWith(util),
calledSpy = j$.createSpy('called spy'), calledSpy = j$.createSpy('called spy'),
result; result;
calledSpy('a'); calledSpy('a');
calledSpy('c', 'd'); calledSpy('c', 'd');
result = matcherComparator(calledSpy, 'a', 'b'); result = matcher.compare(calledSpy, 'a', 'b');
expect(result.pass).toBe(false); 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' ]."); 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() { it("throws an exception when the actual is not a spy", function() {
var matcherComparator = j$.matchers.toHaveBeenCalledWith(), var matcher = j$.matchers.toHaveBeenCalledWith(),
fn = function() {}; fn = function() {};
expect(function() { matcherComparator(fn) }).toThrow(new Error("Expected a spy, but got Function.")); expect(function() { matcher.compare(fn) }).toThrow(new Error("Expected a spy, but got Function."));
}); });
}); });

View File

@@ -1,33 +1,33 @@
describe("toMatch", function() { describe("toMatch", function() {
it("passes when RegExps are equivalent", function() { it("passes when RegExps are equivalent", function() {
var matcherComparator = j$.matchers.toMatch(), var matcher = j$.matchers.toMatch(),
result; result;
result = matcherComparator(/foo/, /foo/); result = matcher.compare(/foo/, /foo/);
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
}); });
it("fails when RegExps are not equivalent", function() { it("fails when RegExps are not equivalent", function() {
var matcherComparator = j$.matchers.toMatch(), var matcher = j$.matchers.toMatch(),
result; result;
result = matcherComparator(/bar/, /foo/); result = matcher.compare(/bar/, /foo/);
expect(result.pass).toBe(false); expect(result.pass).toBe(false);
}); });
it("passes when the actual matches the expected string as a pattern", function() { it("passes when the actual matches the expected string as a pattern", function() {
var matcherComparator = j$.matchers.toMatch(), var matcher = j$.matchers.toMatch(),
result; result;
result = matcherComparator('foosball', 'foo'); result = matcher.compare('foosball', 'foo');
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
}); });
it("fails when the actual matches the expected string as a pattern", function() { it("fails when the actual matches the expected string as a pattern", function() {
var matcherComparator = j$.matchers.toMatch(), var matcher = j$.matchers.toMatch(),
result; result;
result = matcherComparator('bar', 'foo'); result = matcher.compare('bar', 'foo');
expect(result.pass).toBe(false); expect(result.pass).toBe(false);
}); });
}); });

View File

@@ -1,142 +1,142 @@
describe("toThrowError", function() { describe("toThrowError", function() {
it("throws an error when the actual is not a function", function() { it("throws an error when the actual is not a function", function() {
var matcherComparator = j$.matchers.toThrowError(); var matcher = j$.matchers.toThrowError();
expect(function() { expect(function() {
matcherComparator({}); matcher.compare({});
}).toThrowError("Actual is not a Function"); }).toThrowError("Actual is not a Function");
}); });
it("throws an error when the expected is not an Error, string, or RegExp", function() { it("throws an error when the expected is not an Error, string, or RegExp", function() {
var matcherComparator = j$.matchers.toThrowError(), var matcher = j$.matchers.toThrowError(),
fn = function() { fn = function() {
throw new Error("foo"); throw new Error("foo");
}; };
expect(function() { expect(function() {
matcherComparator(fn, 1); matcher.compare(fn, 1);
}).toThrowError("Expected is not an Error, string, or RegExp."); }).toThrowError("Expected is not an Error, string, or RegExp.");
}); });
it("throws an error when the expected error type is not an Error", function() { it("throws an error when the expected error type is not an Error", function() {
var matcherComparator = j$.matchers.toThrowError(), var matcher = j$.matchers.toThrowError(),
fn = function() { fn = function() {
throw new Error("foo"); throw new Error("foo");
}; };
expect(function() { expect(function() {
matcherComparator(fn, void 0, "foo"); matcher.compare(fn, void 0, "foo");
}).toThrowError("Expected error type is not an Error."); }).toThrowError("Expected error type is not an Error.");
}); });
it("throws an error when the expected error message is not a string or RegExp", function() { it("throws an error when the expected error message is not a string or RegExp", function() {
var matcherComparator = j$.matchers.toThrowError(), var matcher = j$.matchers.toThrowError(),
fn = function() { fn = function() {
throw new Error("foo"); throw new Error("foo");
}; };
expect(function() { expect(function() {
matcherComparator(fn, Error, 1); matcher.compare(fn, Error, 1);
}).toThrowError("Expected error message is not a string or RegExp."); }).toThrowError("Expected error message is not a string or RegExp.");
}); });
it("fails if actual does not throw at all", function() { it("fails if actual does not throw at all", function() {
var matcherComparator = j$.matchers.toThrowError(), var matcher = j$.matchers.toThrowError(),
fn = function() { fn = function() {
return true; return true;
}, },
result; result;
result = matcherComparator(fn); result = matcher.compare(fn);
expect(result.pass).toBe(false); expect(result.pass).toBe(false);
expect(result.message).toEqual("Expected function to throw an Error."); expect(result.message).toEqual("Expected function to throw an Error.");
}); });
it("fails if thrown is not an instanceof Error", function() { it("fails if thrown is not an instanceof Error", function() {
var matcherComparator = j$.matchers.toThrowError(), var matcher = j$.matchers.toThrowError(),
fn = function() { fn = function() {
throw 4; throw 4;
}, },
result; result;
result = matcherComparator(fn); result = matcher.compare(fn);
expect(result.pass).toBe(false); expect(result.pass).toBe(false);
expect(result.message).toEqual("Expected function to throw an Error, but it threw 4."); 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() { it("fails with the correct message if thrown is a falsy value", function() {
var matcherComparator = j$.matchers.toThrowError(), var matcher = j$.matchers.toThrowError(),
fn = function() { fn = function() {
throw undefined; throw undefined;
}, },
result; result;
result = matcherComparator(fn); result = matcher.compare(fn);
expect(result.pass).toBe(false); expect(result.pass).toBe(false);
expect(result.message).toEqual("Expected function to throw an Error, but it threw undefined."); 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() { it("passes if thrown is a type of Error, but there is no expected error", function() {
var matcherComparator = j$.matchers.toThrowError(), var matcher = j$.matchers.toThrowError(),
fn = function() { fn = function() {
throw new TypeError(); throw new TypeError();
}, },
result; result;
result = matcherComparator(fn); result = matcher.compare(fn);
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
expect(result.message).toEqual("Expected function not to throw an Error, but it threw TypeError."); 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() { it("passes if thrown is an Error and the expected is the same message", function() {
var matcherComparator = j$.matchers.toThrowError(), var matcher = j$.matchers.toThrowError(),
fn = function() { fn = function() {
throw new Error("foo"); throw new Error("foo");
}, },
result; result;
result = matcherComparator(fn, "foo"); result = matcher.compare(fn, "foo");
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
expect(result.message).toEqual("Expected function not to throw an exception with message 'foo'."); 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() { it("fails if thrown is an Error and the expected is not the same message", function() {
var matcherComparator = j$.matchers.toThrowError(), var matcher = j$.matchers.toThrowError(),
fn = function() { fn = function() {
throw new Error("foo"); throw new Error("foo");
}, },
result; result;
result = matcherComparator(fn, "bar"); result = matcher.compare(fn, "bar");
expect(result.pass).toBe(false); 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'."); 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() { it("passes if thrown is an Error and the expected is a RegExp that matches the message", function() {
var matcherComparator = j$.matchers.toThrowError(), var matcher = j$.matchers.toThrowError(),
fn = function() { fn = function() {
throw new Error("a long message"); throw new Error("a long message");
}, },
result; result;
result = matcherComparator(fn, /long/); result = matcher.compare(fn, /long/);
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
expect(result.message).toEqual("Expected function not to throw an exception with a message matching /long/."); 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() { it("fails if thrown is an Error and the expected is a RegExp that does not match the message", function() {
var matcherComparator = j$.matchers.toThrowError(), var matcher = j$.matchers.toThrowError(),
fn = function() { fn = function() {
throw new Error("a long message"); throw new Error("a long message");
}, },
result; result;
result = matcherComparator(fn, /foo/); result = matcher.compare(fn, /foo/);
expect(result.pass).toBe(false); 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'."); 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 = { var util = {
equals: jasmine.createSpy('delegated-equal').and.returnValue(true) equals: jasmine.createSpy('delegated-equal').and.returnValue(true)
}, },
matcherComparator = j$.matchers.toThrowError(util), matcher = j$.matchers.toThrowError(util),
fn = function() { fn = function() {
throw new Error(); throw new Error();
}, },
result; result;
result = matcherComparator(fn, Error); result = matcher.compare(fn, Error);
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
expect(result.message).toEqual("Expected function not to throw Error."); expect(result.message).toEqual("Expected function not to throw Error.");
@@ -162,7 +162,7 @@ describe("toThrowError", function() {
var util = { var util = {
equals: jasmine.createSpy('delegated-equal').and.returnValue(true) equals: jasmine.createSpy('delegated-equal').and.returnValue(true)
}, },
matcherComparator = j$.matchers.toThrowError(util), matcher = j$.matchers.toThrowError(util),
CustomError = function CustomError(arg) { arg.x }, CustomError = function CustomError(arg) { arg.x },
fn = function() { fn = function() {
throw new CustomError({ x: 1 }); throw new CustomError({ x: 1 });
@@ -172,7 +172,7 @@ describe("toThrowError", function() {
CustomError.prototype = new Error(); CustomError.prototype = new Error();
CustomError.prototype.constructor = CustomError; CustomError.prototype.constructor = CustomError;
result = matcherComparator(fn, CustomError); result = matcher.compare(fn, CustomError);
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
expect(result.message).toEqual("Expected function not to throw CustomError."); expect(result.message).toEqual("Expected function not to throw CustomError.");
@@ -182,13 +182,13 @@ describe("toThrowError", function() {
var util = { var util = {
equals: jasmine.createSpy('delegated-equal').and.returnValue(false) equals: jasmine.createSpy('delegated-equal').and.returnValue(false)
}, },
matcherComparator = j$.matchers.toThrowError(util), matcher = j$.matchers.toThrowError(util),
fn = function() { fn = function() {
throw new Error(); throw new Error();
}, },
result; result;
result = matcherComparator(fn, TypeError); result = matcher.compare(fn, TypeError);
expect(result.pass).toBe(false); expect(result.pass).toBe(false);
expect(result.message).toEqual("Expected function to throw TypeError, but it threw Error."); expect(result.message).toEqual("Expected function to throw TypeError, but it threw Error.");
@@ -198,13 +198,13 @@ describe("toThrowError", function() {
var util = { var util = {
equals: jasmine.createSpy('delegated-equal').and.returnValue(true) equals: jasmine.createSpy('delegated-equal').and.returnValue(true)
}, },
matcherComparator = j$.matchers.toThrowError(util), matcher = j$.matchers.toThrowError(util),
fn = function() { fn = function() {
throw new TypeError("foo"); throw new TypeError("foo");
}, },
result; result;
result = matcherComparator(fn, TypeError, "foo"); result = matcher.compare(fn, TypeError, "foo");
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
expect(result.message).toEqual("Expected function not to throw TypeError with message \"foo\"."); expect(result.message).toEqual("Expected function not to throw TypeError with message \"foo\".");
@@ -214,7 +214,7 @@ describe("toThrowError", function() {
var util = { var util = {
equals: jasmine.createSpy('delegated-equal').and.returnValue(true) equals: jasmine.createSpy('delegated-equal').and.returnValue(true)
}, },
matcherComparator = j$.matchers.toThrowError(util), matcher = j$.matchers.toThrowError(util),
CustomError = function CustomError(arg) { this.message = arg.message }, CustomError = function CustomError(arg) { this.message = arg.message },
fn = function() { fn = function() {
throw new CustomError({message: "foo"}); throw new CustomError({message: "foo"});
@@ -224,7 +224,7 @@ describe("toThrowError", function() {
CustomError.prototype = new Error(); CustomError.prototype = new Error();
CustomError.prototype.constructor = CustomError; CustomError.prototype.constructor = CustomError;
result = matcherComparator(fn, CustomError, "foo"); result = matcher.compare(fn, CustomError, "foo");
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
expect(result.message).toEqual("Expected function not to throw CustomError with message \"foo\"."); expect(result.message).toEqual("Expected function not to throw CustomError with message \"foo\".");
@@ -234,13 +234,13 @@ describe("toThrowError", function() {
var util = { var util = {
equals: jasmine.createSpy('delegated-equal').and.returnValue(false) equals: jasmine.createSpy('delegated-equal').and.returnValue(false)
}, },
matcherComparator = j$.matchers.toThrowError(util), matcher = j$.matchers.toThrowError(util),
fn = function() { fn = function() {
throw new TypeError("foo"); throw new TypeError("foo");
}, },
result; result;
result = matcherComparator(fn, TypeError, "bar"); result = matcher.compare(fn, TypeError, "bar");
expect(result.pass).toBe(false); expect(result.pass).toBe(false);
expect(result.message).toEqual("Expected function to throw TypeError with message \"bar\", but it threw TypeError with message \"foo\"."); 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 = { var util = {
equals: jasmine.createSpy('delegated-equal').and.returnValue(true) equals: jasmine.createSpy('delegated-equal').and.returnValue(true)
}, },
matcherComparator = j$.matchers.toThrowError(util), matcher = j$.matchers.toThrowError(util),
fn = function() { fn = function() {
throw new TypeError("foo"); throw new TypeError("foo");
}, },
result; result;
result = matcherComparator(fn, TypeError, /foo/); result = matcher.compare(fn, TypeError, /foo/);
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
expect(result.message).toEqual("Expected function not to throw TypeError with message matching /foo/."); expect(result.message).toEqual("Expected function not to throw TypeError with message matching /foo/.");
@@ -266,13 +266,13 @@ describe("toThrowError", function() {
var util = { var util = {
equals: jasmine.createSpy('delegated-equal').and.returnValue(false) equals: jasmine.createSpy('delegated-equal').and.returnValue(false)
}, },
matcherComparator = j$.matchers.toThrowError(util), matcher = j$.matchers.toThrowError(util),
fn = function() { fn = function() {
throw new TypeError("foo"); throw new TypeError("foo");
}, },
result; result;
result = matcherComparator(fn, TypeError, /bar/); result = matcher.compare(fn, TypeError, /bar/);
expect(result.pass).toBe(false); 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\"."); expect(result.message).toEqual("Expected function to throw TypeError with message matching /bar/, but it threw TypeError with message \"foo\".");

View File

@@ -1,20 +1,21 @@
describe("toThrow", function() { describe("toThrow", function() {
it("throws an error when the actual is not a function", function() { it("throws an error when the actual is not a function", function() {
var matcherComparator = j$.matchers.toThrow(); var matcher = j$.matchers.toThrow();
expect(function() { expect(function() {
matcher.compare({});
matcherComparator({}); matcherComparator({});
}).toThrowError("Actual is not a Function"); }).toThrowError("Actual is not a Function");
}); });
it("fails if actual does not throw", function() { it("fails if actual does not throw", function() {
var matcherComparator = j$.matchers.toThrow(), var matcher = j$.matchers.toThrow(),
fn = function() { fn = function() {
return true; return true;
}, },
result; result;
result = matcherComparator(fn); result = matcher.compare(fn);
expect(result.pass).toBe(false); expect(result.pass).toBe(false);
expect(result.message).toEqual("Expected function to throw an exception."); expect(result.message).toEqual("Expected function to throw an exception.");
@@ -24,26 +25,26 @@ describe("toThrow", function() {
var util = { var util = {
equals: jasmine.createSpy('delegated-equal').and.returnValue(true) equals: jasmine.createSpy('delegated-equal').and.returnValue(true)
}, },
matcherComparator = j$.matchers.toThrow(util), matcher = j$.matchers.toThrow(util),
fn = function() { fn = function() {
throw 5; throw 5;
}, },
result; result;
result = matcherComparator(fn); result = matcher.compare(fn);
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
expect(result.message).toEqual("Expected function not to throw, but it threw 5."); expect(result.message).toEqual("Expected function not to throw, but it threw 5.");
}); });
it("passes even if what is thrown is falsy", function() { it("passes even if what is thrown is falsy", function() {
var matcherComparator = j$.matchers.toThrow(), var matcher = j$.matchers.toThrow(),
fn = function() { fn = function() {
throw undefined; throw undefined;
}, },
result; result;
result = matcherComparator(fn); result = matcher.compare(fn);
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
expect(result.message).toEqual("Expected function not to throw, but it threw undefined."); expect(result.message).toEqual("Expected function not to throw, but it threw undefined.");
}); });
@@ -52,13 +53,13 @@ describe("toThrow", function() {
var util = { var util = {
equals: jasmine.createSpy('delegated-equal').and.returnValue(true) equals: jasmine.createSpy('delegated-equal').and.returnValue(true)
}, },
matcherComparator = j$.matchers.toThrow(util), matcher = j$.matchers.toThrow(util),
fn = function() { fn = function() {
throw 5; throw 5;
}, },
result; result;
result = matcherComparator(fn, 5); result = matcher.compare(fn, 5);
expect(result.pass).toBe(true); expect(result.pass).toBe(true);
expect(result.message).toEqual("Expected function not to throw 5."); expect(result.message).toEqual("Expected function not to throw 5.");
@@ -68,13 +69,13 @@ describe("toThrow", function() {
var util = { var util = {
equals: jasmine.createSpy('delegated-equal').and.returnValue(false) equals: jasmine.createSpy('delegated-equal').and.returnValue(false)
}, },
matcherComparator = j$.matchers.toThrow(util), matcher = j$.matchers.toThrow(util),
fn = function() { fn = function() {
throw 5; throw 5;
}, },
result; result;
result = matcherComparator(fn, "foo"); result = matcher.compare(fn, "foo");
expect(result.pass).toBe(false); expect(result.pass).toBe(false);
expect(result.message).toEqual("Expected function to throw 'foo', but it threw 5."); expect(result.message).toEqual("Expected function to throw 'foo', but it threw 5.");
@@ -84,13 +85,13 @@ describe("toThrow", function() {
var util = { var util = {
equals: jasmine.createSpy('delegated-equal').and.returnValue(false) equals: jasmine.createSpy('delegated-equal').and.returnValue(false)
}, },
matcherComparator = j$.matchers.toThrow(util), matcher = j$.matchers.toThrow(util),
fn = function() { fn = function() {
throw 5; throw 5;
}, },
result; result;
result = matcherComparator(fn, void 0); result = matcher.compare(fn, void 0);
expect(result.pass).toBe(false); expect(result.pass).toBe(false);
expect(result.message).toEqual("Expected function to throw undefined, but it threw 5."); expect(result.message).toEqual("Expected function to throw undefined, but it threw 5.");

View File

@@ -22,8 +22,7 @@ getJasmineRequireObj().Expectation = function() {
args.unshift(this.actual); args.unshift(this.actual);
var matcherComparator = matcherFactory(this.util, this.customEqualityTesters), var result = matcherFactory(this.util, this.customEqualityTesters).compare.apply(null, args);
result = matcherComparator.apply(null, args);
if (this.isNot) { if (this.isNot) {
result.pass = !result.pass; result.pass = !result.pass;

View File

@@ -1,9 +1,11 @@
getJasmineRequireObj().toBe = function() { getJasmineRequireObj().toBe = function() {
function toBe() { function toBe() {
return function(actual, expected) { return {
compare: function(actual, expected) {
return { return {
pass: actual === expected pass: actual === expected
}; };
}
}; };
} }

View File

@@ -1,7 +1,8 @@
getJasmineRequireObj().toBeCloseTo = function() { getJasmineRequireObj().toBeCloseTo = function() {
function toBeCloseTo() { function toBeCloseTo() {
return function(actual, expected, precision) { return {
compare: function(actual, expected, precision) {
if (precision !== 0) { if (precision !== 0) {
precision = precision || 2; precision = precision || 2;
} }
@@ -9,6 +10,7 @@ getJasmineRequireObj().toBeCloseTo = function() {
return { return {
pass: Math.abs(expected - actual) < (Math.pow(10, -precision) / 2) pass: Math.abs(expected - actual) < (Math.pow(10, -precision) / 2)
}; };
}
}; };
} }

View File

@@ -1,9 +1,11 @@
getJasmineRequireObj().toBeDefined = function() { getJasmineRequireObj().toBeDefined = function() {
function toBeDefined() { function toBeDefined() {
return function(actual) { return {
compare: function(actual) {
return { return {
pass: (void 0 !== actual) pass: (void 0 !== actual)
}; };
}
}; };
} }

View File

@@ -1,9 +1,11 @@
getJasmineRequireObj().toBeFalsy = function() { getJasmineRequireObj().toBeFalsy = function() {
function toBeFalsy() { function toBeFalsy() {
return function(actual) { return {
compare: function(actual) {
return { return {
pass: !!!actual pass: !!!actual
}; };
}
}; };
} }

View File

@@ -1,10 +1,12 @@
getJasmineRequireObj().toBeGreaterThan = function() { getJasmineRequireObj().toBeGreaterThan = function() {
function toBeGreaterThan() { function toBeGreaterThan() {
return function(actual, expected) { return {
compare: function(actual, expected) {
return { return {
pass: actual > expected pass: actual > expected
}; };
}
}; };
} }

View File

@@ -1,9 +1,12 @@
getJasmineRequireObj().toBeLessThan = function() { getJasmineRequireObj().toBeLessThan = function() {
function toBeLessThan() { function toBeLessThan() {
return function(actual, expected) { return {
compare: function(actual, expected) {
return { return {
pass: actual < expected pass: actual < expected
}; };
}
}; };
} }

View File

@@ -1,7 +1,8 @@
getJasmineRequireObj().toBeNaN = function(j$) { getJasmineRequireObj().toBeNaN = function(j$) {
function toBeNaN() { function toBeNaN() {
return function(actual) { return {
compare: function(actual) {
var result = { var result = {
pass: (actual !== actual) pass: (actual !== actual)
}; };
@@ -13,6 +14,7 @@ getJasmineRequireObj().toBeNaN = function(j$) {
} }
return result; return result;
}
}; };
} }

View File

@@ -1,10 +1,12 @@
getJasmineRequireObj().toBeNull = function() { getJasmineRequireObj().toBeNull = function() {
function toBeNull() { function toBeNull() {
return function(actual) { return {
compare: function(actual) {
return { return {
pass: actual === null pass: actual === null
}; };
}
}; };
} }

View File

@@ -1,10 +1,12 @@
getJasmineRequireObj().toBeTruthy = function() { getJasmineRequireObj().toBeTruthy = function() {
function toBeTruthy() { function toBeTruthy() {
return function(actual) { return {
compare: function(actual) {
return { return {
pass: !!actual pass: !!actual
}; };
}
}; };
} }

View File

@@ -1,10 +1,12 @@
getJasmineRequireObj().toBeUndefined = function() { getJasmineRequireObj().toBeUndefined = function() {
function toBeUndefined() { function toBeUndefined() {
return function(actual) { return {
compare: function(actual) {
return { return {
pass: void 0 === actual pass: void 0 === actual
}; };
}
}; };
} }

View File

@@ -2,10 +2,13 @@ getJasmineRequireObj().toContain = function() {
function toContain(util, customEqualityTesters) { function toContain(util, customEqualityTesters) {
customEqualityTesters = customEqualityTesters || []; customEqualityTesters = customEqualityTesters || [];
return function(actual, expected) { return {
compare: function(actual, expected) {
return { return {
pass: util.contains(actual, expected, customEqualityTesters) pass: util.contains(actual, expected, customEqualityTesters)
}; };
}
}; };
} }

View File

@@ -3,10 +3,16 @@ getJasmineRequireObj().toEqual = function() {
function toEqual(util, customEqualityTesters) { function toEqual(util, customEqualityTesters) {
customEqualityTesters = customEqualityTesters || []; customEqualityTesters = customEqualityTesters || [];
return function(actual, expected) {
return { return {
pass: util.equals(actual, expected, customEqualityTesters) compare: function(actual, expected) {
var result = {
pass: false
}; };
result.pass = util.equals(actual, expected, customEqualityTesters);
return result;
}
}; };
} }

View File

@@ -1,7 +1,8 @@
getJasmineRequireObj().toHaveBeenCalled = function(j$) { getJasmineRequireObj().toHaveBeenCalled = function(j$) {
function toHaveBeenCalled() { function toHaveBeenCalled() {
return function(actual) { return {
compare: function(actual) {
var result = {}; var result = {};
if (!j$.isSpy(actual)) { if (!j$.isSpy(actual)) {
@@ -19,6 +20,7 @@ getJasmineRequireObj().toHaveBeenCalled = function(j$) {
"Expected spy " + actual.and.identity() + " to have been called."; "Expected spy " + actual.and.identity() + " to have been called.";
return result; return result;
}
}; };
} }

View File

@@ -1,7 +1,8 @@
getJasmineRequireObj().toHaveBeenCalledWith = function(j$) { getJasmineRequireObj().toHaveBeenCalledWith = function(j$) {
function toHaveBeenCalledWith(util) { function toHaveBeenCalledWith(util) {
return function() { return {
compare: function() {
var args = Array.prototype.slice.call(arguments, 0), var args = Array.prototype.slice.call(arguments, 0),
actual = args[0], actual = args[0],
expectedArgs = args.slice(1), expectedArgs = args.slice(1),
@@ -24,6 +25,7 @@ getJasmineRequireObj().toHaveBeenCalledWith = function(j$) {
} }
return result; return result;
}
}; };
} }

View File

@@ -1,12 +1,14 @@
getJasmineRequireObj().toMatch = function() { getJasmineRequireObj().toMatch = function() {
function toMatch() { function toMatch() {
return function(actual, expected) { return {
compare: function(actual, expected) {
var regexp = new RegExp(expected); var regexp = new RegExp(expected);
return { return {
pass: regexp.test(actual) pass: regexp.test(actual)
}; };
}
}; };
} }

View File

@@ -1,7 +1,8 @@
getJasmineRequireObj().toThrow = function(j$) { getJasmineRequireObj().toThrow = function(j$) {
function toThrow(util) { function toThrow(util) {
return function(actual, expected) { return {
compare: function(actual, expected) {
var result = { pass: false }, var result = { pass: false },
threw = false, threw = false,
thrown; thrown;
@@ -37,6 +38,7 @@ getJasmineRequireObj().toThrow = function(j$) {
} }
return result; return result;
}
}; };
} }

View File

@@ -1,6 +1,7 @@
getJasmineRequireObj().toThrowError = function(j$) { getJasmineRequireObj().toThrowError = function(j$) {
function toThrowError (util) { function toThrowError (util) {
return function(actual) { return {
compare: function(actual) {
var threw = false, var threw = false,
thrown, thrown,
errorType, errorType,
@@ -146,6 +147,7 @@ getJasmineRequireObj().toThrowError = function(j$) {
Surrogate.prototype = type.prototype; Surrogate.prototype = type.prototype;
return (new Surrogate()) instanceof Error; return (new Surrogate()) instanceof Error;
} }
}
}; };
} }