diff options
author | James Lal <james@lightsofapollo.com> | 2012-07-06 21:24:22 -0700 |
---|---|---|
committer | James Lal <james@lightsofapollo.com> | 2012-07-06 21:24:22 -0700 |
commit | d67f226d11b84f39c2bda7b9a6ef95ea7dafa337 (patch) | |
tree | 39028d73304f54b05d879f3adbcea3680f1a3316 /test/support | |
parent | 619241a08ec736303324211e36ea7dafc4f46c51 (diff) | |
download | jsCalDAV-d67f226d11b84f39c2bda7b9a6ef95ea7dafa337.tar.gz |
Initial mocking support for mock requests
Diffstat (limited to 'test/support')
-rw-r--r-- | test/support/mock_request.js | 72 | ||||
-rw-r--r-- | test/support/propfind.js | 0 |
2 files changed, 72 insertions, 0 deletions
diff --git a/test/support/mock_request.js b/test/support/mock_request.js new file mode 100644 index 0000000..2141b3c --- /dev/null +++ b/test/support/mock_request.js @@ -0,0 +1,72 @@ +(function(module, ns) { + + function MockRequest(connection, options) { + this.connection = connection; + this.options = options; + + var parent = this.constructor; + + if (!parent.instances) { + parent.instances = []; + } + + parent.instances.push(this); + } + + + MockRequest.prototype = { + send: function(callback) { + this.__sendCallback = callback; + }, + + respond: function() { + this.__sendCallback.apply(this, arguments); + } + + }; + + MockRequest.reset = function() { + if (!this.instances) { + this.instances = []; + } + this.instances.length = 0; + } + + MockRequest.create = function(methods) { + var self = this; + + if (typeof(methods) === 'undefined') { + methods = []; + } + + var child = function() { + self.apply(this, arguments); + }; + + child.prototype = Object.create(self.prototype); + child.prototype.constructor = child; + + methods.forEach(function(method) { + child.prototype[method] = function() { + var savedName = method + 'Calls'; + if (!(savedName in this)) { + this[savedName] = []; + } + this[savedName].push(arguments); + } + }); + + child.create = self.create; + child.reset = self.reset; + + return child; + }; + + module.exports = MockRequest; + +}.apply( + this, + (this.Caldav) ? + [Caldav('support/mock_request'), Caldav] : + [module, require('../../lib/caldav/caldav')] +)); diff --git a/test/support/propfind.js b/test/support/propfind.js deleted file mode 100644 index e69de29..0000000 --- a/test/support/propfind.js +++ /dev/null |