Skip to content

Commit

Permalink
Fixed a bug in Array.isEqual
Browse files Browse the repository at this point in the history
git-svn-id: file:///Users/jyurek/Backups/repositories/jocha/trunk@21 5317845c-832e-0410-b2c0-db6c5bc7c761
  • Loading branch information
jyurek committed Apr 25, 2007
1 parent e050696 commit 26cd50b
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions jocha.js
Expand Up @@ -39,8 +39,10 @@ Jocha.Expectation.prototype = {

Jocha.FailedExpectation = Class.create();
Jocha.FailedExpectation.prototype = {
initialize: function(message) {
initialize: function(message, stack) {
this.message = message;
this.stackTrace = stack || null;
this.assertion = true;
}
}

Expand All @@ -64,12 +66,26 @@ Object.extend(Object.prototype, {
return false;
},
methodMocked : function(functionName, args) {
var expectation = this.mock.expectations.find(function(e){
return e.functionName == functionName && e.params.isEqual($A(args))
});
var expectation = null;
for(var i=0; i < this.mock.expectations.length; i++)
{
var e = this.mock.expectations[i];
if(e.functionName == functionName && e.params.isEqual($A(args)))
{
expectation = e;
break;
}
}
if (expectation) {
expectation.invoked = true;
return expectation.returnVal;
} else {
var st = null;

if(stackTrace){ st = stackTrace(); }
else{ try{ throw new Error() } catch(e) { st = e.stack } }

throw new Jocha.FailedExpectation(functionName + " was called with the wrong arguments.", st);
}
}
});
Expand Down Expand Up @@ -101,9 +117,9 @@ Object.prototype.isEqual = function(other) {

Object.equal = function(one, two){
if(typeof(one) == "object" && one != null && one.isEqual){
if(!one.isEqual(two)) return false;
return( one.isEqual(two) );
} else {
if(one != two) return false;
return( one != two );
}
}

Expand Down

0 comments on commit 26cd50b

Please sign in to comment.