Permalink
Browse files

Add toBeGreaterThan matcher

  • Loading branch information...
1 parent ff9296b commit 701c95737dc11dd03a30a248bdd3688d592736c0 James Somers & Steve Ellis committed Sep 24, 2012
Showing with 26 additions and 0 deletions.
  1. +22 −0 spec/javascripts/cactusSpec.js
  2. +4 −0 vendor/assets/javascripts/cactus.js
View
22 spec/javascripts/cactusSpec.js
@@ -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() {
View
4 vendor/assets/javascripts/cactus.js
@@ -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; });
};

0 comments on commit 701c957

Please sign in to comment.