A spyOn implementation for whiskey. (in progress) #35

Merged
merged 5 commits into from May 11, 2012

2 participants

@btipling

No description provided.

@Kami Kami and 1 other commented on an outdated diff May 11, 2012
lib/common.js
@@ -544,3 +545,73 @@ exports.TestFile = TestFile;
exports.getTestFilePathAndPattern = getTestFilePathAndPattern;
exports.registerCustomAssertionFunctions = registerCustomAssertionFunctions;
+
+/**
+ * @constructor
+ */
+function SpyOn (){
+ /**
+ * This tracks the number of times a function has been fired.
+ * @param {Object.<number>}
+ * @private
+ */
+ this.callCount_ = {};
@Kami
Cloudkick member
Kami added a note May 11, 2012

Minor style issue - we prefix 'private' attributes with _ (_callCount) instead of suffix them.

Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Kami Kami and 1 other commented on an outdated diff May 11, 2012
lib/common.js
+ this.reset(funcName);
+ var wrapper = (function () {
+ this.callCount_[funcName] += 1;
+ return func.apply(context, arguments);
+ }).bind(this);
+ context[funcName] = wrapper;
+ this.funcMap_[funcName] = func;
+ return this;
+};
+
+/**
+ * @param {string} funcName The key to clear.
+ * @param {Object} context The context in which the function should execute.
+ * @param {Function} opt_func The optional function to reapply to the context.
+ */
+SpyOn.prototype.clear = function (funcName, context, opt_func) {
@Kami
Cloudkick member
Kami added a note May 11, 2012

Another minor style issue: opt_func -> optFunc.

Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Kami Kami merged commit 0a801c3 into master May 11, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment