Skip to content

Commit

Permalink
Merge pull request #1 from pivotal-toadstool/master
Browse files Browse the repository at this point in the history
Add toBeGreaterThan matcher
  • Loading branch information
winston committed Sep 25, 2012
2 parents ff9296b + 77fc097 commit 7d11c3d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
22 changes: 22 additions & 0 deletions spec/javascripts/cactusSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,28 @@ describe("Cactus", function() {
// Reset
$("label:first").css("text-align", "right");
});

describe("toBeGreaterThan", function() {
beforeEach(function() {
$("label").css("font-size", "12px");
});

it("returns true when result is true for all matched elements", function() {
var result = Cactus.expect("label", "font-size").toBeGreaterThan("10px");
expect(result).toBe(true);
});

it("returns false when result is false for one of the matched elements", function() {
// Setup
$("label:first").css("font-size", "9px");

var result = Cactus.expect("label", "font-size").toBeGreaterThan("10px");
expect(result).toBe(false);

// Reset
$("label").css("font-size", "12px");
});
});
});

describe("toContain", function() {
Expand Down
10 changes: 7 additions & 3 deletions vendor/assets/javascripts/cactus.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ Cactus = (function() {
return compare(styles, expected_style, function(x, y) { return x === y; });
};

_cactus.toBeGreaterThan = function(expected_style) {
return compare(styles, expected_style, function(x, y) { return parseInt(x) > parseInt(y); }, "exceed");
};

_cactus.toContain = function(expected_style) {
return compare(styles, expected_style, function(x, y) { return x.match(y) ? true : false; });
};
Expand Down Expand Up @@ -86,13 +90,13 @@ Cactus = (function() {
return str;
}

function compare(computed, expected, comparator) {
function compare(computed, expected, comparator, operation) {
var result = true, status, message;

if ($(tag_name).is("*")) {
$.each(computed, function(index, style) {
status = comparator(style, expected);
message = "Expected " + selector(index) + " " + property + " to equal " + expected + ". Got " + style + ".";
message = "Expected " + selector(index) + " " + property + " to " + (operation ? operation : "equal") + " " + expected + ". Got " + style + ".";

result = result && status;

Expand All @@ -101,7 +105,7 @@ Cactus = (function() {
});
} else {
status = "skip";
message = "Expected " + selector() + " " + property + " to equal " + expected + ".";
message = "Expected " + selector() + " " + property + " to " + (operation ? operation : "equal") + " " + expected + ".";

result = status;

Expand Down

0 comments on commit 7d11c3d

Please sign in to comment.