diff options
author | James Lal <james@lightsofapollo.com> | 2012-07-07 08:16:54 -0700 |
---|---|---|
committer | James Lal <james@lightsofapollo.com> | 2012-07-07 08:16:54 -0700 |
commit | 0541668eaa804770d51e85037c21887c045642c7 (patch) | |
tree | 589945289b3ad98dc447d777d4113d9b536d8900 /test | |
parent | e45011f8ffff1fd71ea715739390a8d13dda977b (diff) | |
download | jsCalDAV-0541668eaa804770d51e85037c21887c045642c7.tar.gz |
moved obviously useful mockCallback to testSupport.mock.method
Diffstat (limited to 'test')
-rw-r--r-- | test/caldav/request/calendar_home_test.js | 18 | ||||
-rw-r--r-- | test/helper.js | 39 |
2 files changed, 41 insertions, 16 deletions
diff --git a/test/caldav/request/calendar_home_test.js b/test/caldav/request/calendar_home_test.js index b48c3b2..88eb905 100644 --- a/test/caldav/request/calendar_home_test.js +++ b/test/caldav/request/calendar_home_test.js @@ -131,25 +131,11 @@ suite('caldav/request/propfind', function() { suite('#send', function() { - function mockCallback(obj, method) { - var calledWith = {}; - var calls = 0; - - obj[method] = function() { - if (calls.length > 1) { - throw new Error(method + ' called more then once'); - } - - calledWith.args = arguments; - }; - - return calledWith; - } test('success', function() { var expected = { url: 'foo.com' }; - var principal = mockCallback(subject, '_findPrincipal'); - var home = mockCallback(subject, '_findCalendarHome'); + var principal = testSupport.mock.method(subject, '_findPrincipal'); + var home = testSupport.mock.method(subject, '_findCalendarHome'); subject.send(function() { err = arguments[0]; diff --git a/test/helper.js b/test/helper.js index 6157bdb..306a426 100644 --- a/test/helper.js +++ b/test/helper.js @@ -104,6 +104,45 @@ }); }; + testSupport.mock = { + + /** + * Mocks out a method + * + * var called = testSupport.mock.method(subject, 'myMethod'); + * + * subject.myMethod('foo', 'bar'); + * + * called.args[0] === 'foo'; // true + * called.args[1] === 'bar'; // true + * + * + * @return {Object} reference object. + */ + method: function(obj, method, times) { + var calledWith = {}; + var calls = 0; + + if (typeof(times) === 'undefined') { + times = 1; + } + + obj[method] = function() { + if (calls.length > times) { + throw new Error( + method + ' called more then ' + times + 'time(s)' + ); + } + + calledWith.args = arguments; + calls++; + }; + + return calledWith; + } + + }; + testSupport.lib = function(lib, callback) { testSupport.require('/lib/caldav/' + lib, callback); }; |