Permalink
Browse files

Merge pull request #1 from pivotal-toadstool/master

Add toBeGreaterThan matcher
  • Loading branch information...
2 parents ff9296b + 77fc097 commit 7d11c3d57c706bf1b74ce8452f2d144359d2c683 @winston committed Sep 25, 2012
Showing with 29 additions and 3 deletions.
  1. +22 −0 spec/javascripts/cactusSpec.js
  2. +7 −3 vendor/assets/javascripts/cactus.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() {
@@ -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; });
};
@@ -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;
@@ -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;

0 comments on commit 7d11c3d

Please sign in to comment.