Skip to content

Commit

Permalink
Fixed more compatibility issues for should.js. Maybe I should publish…
Browse files Browse the repository at this point in the history
… this. Remind

me to ask TJ.
  • Loading branch information
rauchg committed Jun 21, 2011
1 parent a5b53f0 commit e1e11dd
Showing 1 changed file with 40 additions and 5 deletions.
45 changes: 40 additions & 5 deletions support/should.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@
Assertion.prototype.contain = function (obj) {
this.obj.should().be.an.instance.of(Array);
this.assert(
~this.obj.indexOf(obj)
~indexOf(this.obj, obj)
, 'expected ' + i(this.obj) + ' to contain ' + i(obj)
, 'expected ' + i(this.obj) + ' to not contain ' + i(obj));
return this;
Expand Down Expand Up @@ -426,8 +426,8 @@
, len = keys.length;

// Inclusion
ok = keys.every(function(key){
return ~actual.indexOf(key);
ok = every(keys, function(key){
return ~indexOf(actual, key);
});

// Strict
Expand Down Expand Up @@ -494,6 +494,41 @@

FlaggedAssertion.prototype = new Assertion;

/**
* Array every compatibility
*
* @see bit.ly/5Fq1N2
* @api public
*/

function every (arr, fn, thisObj) {
var scope = thisObj || window;
for (var i = 0, j = arr.length; i < j; ++i) {
if (!fn.call(scope, arr[i], i, arr)) {
return false;
}
}
return true;
};

/**
* Array indexOf compatibility.
*
* @see bit.ly/a5Dxa2
* @api public
*/

function indexOf (arr, o, i) {
if (Array.prototype.indexOf) {
return Array.prototype.indexOf.call(arr, o, i);
}

for (var j = arr.length, i = i < 0 ? i + j < 0 ? 0 : i + j : i || 0
; i < j && arr[i] !== o; i++);

return j <= i ? -1 : i;
};

/**
* Inspects an object.
*
Expand Down Expand Up @@ -612,11 +647,11 @@
}
}
}
if (visible_keys.indexOf(key) < 0) {
if (indexOf(visible_keys, key) < 0) {
name = '[' + key + ']';
}
if (!str) {
if (seen.indexOf(value[key]) < 0) {
if (indexOf(seen, value[key]) < 0) {
if (recurseTimes === null) {
str = format(value[key]);
} else {
Expand Down

0 comments on commit e1e11dd

Please sign in to comment.