Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added real trunk dir and file

git-svn-id: file:///Users/jyurek/Backups/repositories/jocha/trunk@3 5317845c-832e-0410-b2c0-db6c5bc7c761
  • Loading branch information...
commit 9d335cb0eb80811abd133e5b1d0451a31e69b146 0 parents
tfwright authored
Showing with 58 additions and 0 deletions.
  1. +58 −0 jocha.js
58 jocha.js
@@ -0,0 +1,58 @@
+ // Thanks http://www.svendtofte.com/code/usefull_prototypes/
+ Array.prototype.isEqual = function(arr) {
+ if (this.length != arr.length) return false;
+ for (var i = 0; i < arr.length; i++) {
+ if (this[i].isEqual) { //likely nested array
+ if (!this[i].isEqual(arr[i])) return false;
+ else continue;
+ }
+ if (this[i] != arr[i]) return false;
+ }
+ return true;
+ }
+
+ Mock = Class.create();
+ Mock.prototype = {
+ initialize : function() {
+ this.expectations = new Array();
+ }
+ }
+ Expectation = Class.create();
+ Expectation.prototype = {
+ initialize : function(functionName) {
+ this.functionName = functionName;
+ this.params = [];
+ this.invoked = false;
+ },
+ withParams : function() {
+ this.params = $A(arguments);
+ return this;
+ },
+ andReturns : function(return_val) {
+ this.return_val = return_val;
+ }
+ }
+
+ Object.extend(Object.prototype, {
+ expects : function(functionName) {
+ this[functionName] = function() {
+ this.methodMocked(functionName, arguments);
+ };
+ if (!this.mock)
+ this.mock = new Mock();
+ expectation = new Expectation(functionName);
+ this.mock.expectations.push(expectation);
+ return expectation;
+ },
+ verify : function() {
+ if (!this.mock.expectations.all(function(e){return e.invoked}))
+ return false;
+ else
+ return true;
+ },
+ methodMocked : function(functionName, args) {
+ expectation = this.mock.expectations.find(function(e){return e.functionName == functionName && e.params.isEqual($A(args))});
+ expectation.invoked = true;
+ return expectation.return_val;
+ }
+ });
Please sign in to comment.
Something went wrong with that request. Please try again.