Skip to content

Commit

Permalink
Use special matcher for imageDiffEqual (in jasmine spec).
Browse files Browse the repository at this point in the history
  • Loading branch information
cesutherland committed Feb 14, 2012
1 parent 4803de2 commit 7f5812f
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions spec/ImageDiffSpec.js
Expand Up @@ -22,6 +22,34 @@ describe('ImageUtils', function() {
return window ? new Image() : new Canvas.Image();
}

function toImageDiffEqual (expected) {

var
expectedData = expected.data,
actualData = this.actual.data;

this.message = function () {
var
length = Math.min(expectedData.length, actualData.length),
examples = '',
count = 0,
i;

for (i = 0; i < length; i++) {
if (expectedData[i] !== actualData[i]) {
count++;
if (count < 10) {
examples += (examples ? ', ' : '') + 'Expected '+expectedData[i]+' to equal '+actualData[i]+' at '+i;
}
}
}

return 'Differed in ' + count + ' places. ' + examples;
}

return imagediff.equal(this.actual, expected);
}

// Creation Testing
describe('Creation', function () {

Expand Down Expand Up @@ -99,9 +127,7 @@ describe('ImageUtils', function() {
toBeImageData : function () {
return imagediff.isImageData(this.actual);
},
toImageDiffEqual : function (expected) {
return imagediff.equal(this.actual, expected);
}
toImageDiffEqual : toImageDiffEqual
});
});

Expand Down Expand Up @@ -228,9 +254,7 @@ describe('ImageUtils', function() {

beforeEach(function () {
this.addMatchers({
toImageDiffEqual : function (expected) {
return imagediff.equal(this.actual, expected);
}
toImageDiffEqual : toImageDiffEqual
});
});

Expand Down

0 comments on commit 7f5812f

Please sign in to comment.