Permalink
Browse files

Result is "skip" when tag is not found.

  • Loading branch information...
1 parent 9ff20b7 commit 85f630a4c691f112d6b5e5baa7d09765a031a8b8 Winston Teo committed Mar 19, 2012
Showing with 44 additions and 18 deletions.
  1. +22 −12 spec/javascripts/cactusSpec.js
  2. +22 −6 vendor/assets/javascripts/cactus.js
@@ -25,53 +25,63 @@ describe("Cactus", function() {
});
describe("toEqual", function() {
- afterEach(function() {
- $("label:first").css("text-align", "right");
- });
-
it("returns true when result is true for all matched elements", function() {
var result = Cactus.expect("label", "text-align").toEqual("right");
expect(result).toBeTruthy();
});
it("returns false when result is false for one of the matched elements", function() {
+ // Setup
$("label:first").css("text-align", "left");
+
var result = Cactus.expect("label", "text-align").toEqual("left");
expect(result).toBeFalsy();
- });
- });
- describe("toContain", function() {
- afterEach(function() {
+ // Reset
$("label:first").css("text-align", "right");
});
+ });
+ describe("toContain", function() {
it("returns true when result is true for all matched elements", function() {
var result = Cactus.expect("label", "text-align").toContain("righ");
expect(result).toBeTruthy();
});
it("returns false when result is false for one of the matched elements", function() {
+ // Setup
$("label:first").css("text-align", "left");
+
var result = Cactus.expect("label", "text-align").toContain("lef");
expect(result).toBeFalsy();
+
+ // Reset
+ $("label:first").css("text-align", "right");
});
});
describe("toHaveColor", function() {
- afterEach(function() {
- $("label:first").css("color", "#330033");
- });
-
it("returns true when result is true for all matched elements (case insensitive)", function() {
var result = Cactus.expect("label", "color").toHaveColor("#330033");
expect(result).toBeTruthy();
});
it("returns false when result is false for one of the matched elements", function() {
+ // Setup
$("label:first").css("color", "#000000");
+
var result = Cactus.expect("label", "color").toHaveColor("#000000");
expect(result).toBeFalsy();
+
+ // Reset
+ $("label:first").css("color", "#330033");
+ });
+ });
+
+ describe("skip", function() {
+ it("returns 'skip' when tag is not found", function() {
+ var result = Cactus.expect("#not_found", "display").toEqual("block");
+ expect(result).toEqual("skip");
});
});
});
@@ -54,18 +54,34 @@ Cactus = (function() {
// Private Methods
+ function selector(index) {
+ var str = "$('" + tag_name + "')";
+ if (index >=0) { str += "[" + index + "]"; }
+ return str;
+ }
+
function compare(computed, expected, comparator) {
- var result = true;
+ 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 + ".";
- $.each(computed, function(index, style) {
- var status = comparator(style, expected);
- var message = "Expected" + " $('" + tag_name + "')" + "[" + index + "] " + property + " to equal " + expected + ". Got " + style + ".";
+ result = result && status;
- result = result && status;
+ // Print result on page
+ CactusReport.render(status, message);
+ });
+ } else {
+ status = "skip";
+ message = "Expected " + selector() + " " + property + " to equal " + expected + ".";
+
+ result = "skip";
// Print result on page
CactusReport.render(status, message);
- });
+ }
return result;
}

0 comments on commit 85f630a

Please sign in to comment.