Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

- Add skipped results (where tags are not matched on page).

- Refactored code.
- Changed toBeTruthy to toBe(true) and toBeFalsy to toBe(false).
  • Loading branch information...
commit 67661ab239def150c5a177840237f84d6923fb5e 1 parent 85f630a
Winston Teo authored
View
68 spec/javascripts/cactusReportSpec.js
@@ -13,9 +13,10 @@ describe("CactusReport", function() {
CactusReport.render(true, "test 1 passed");
});
- it("hides toggle for failures", function() {
- expect($(".cactus_toggle_pass").is(":visible")).toBeTruthy();
- expect($(".cactus_toggle_fail").is(":visible")).toBeFalsy();
+ it("only shows toggle for passes", function() {
+ expect($(".cactus_toggle_pass").is(":visible")).toBe(true);
+ expect($(".cactus_toggle_fail").is(":visible")).toBe(false);
+ expect($(".cactus_toggle_skip").is(":visible")).toBe(false);
});
});
@@ -24,30 +25,46 @@ describe("CactusReport", function() {
CactusReport.render(false, "test 1 failed");
});
- it("hides toggle for passes", function() {
- expect($(".cactus_toggle_pass").is(":visible")).toBeFalsy();
- expect($(".cactus_toggle_fail").is(":visible")).toBeTruthy();
+ it("only shows toggle for failures", function() {
+ expect($(".cactus_toggle_pass").is(":visible")).toBe(false);
+ expect($(".cactus_toggle_fail").is(":visible")).toBe(true);
+ expect($(".cactus_toggle_skip").is(":visible")).toBe(false);
});
});
- describe("some tests passed, some tests failed", function() {
+ describe("all tests skipped", function() {
beforeEach(function() {
- CactusReport.render(true , "test 1 passed");
- CactusReport.render(false, "test 2 failed");
+ CactusReport.render("skip", "test 1 skipped");
+ });
+
+ it("only shows toggle for skips", function() {
+ expect($(".cactus_toggle_pass").is(":visible")).toBe(false);
+ expect($(".cactus_toggle_fail").is(":visible")).toBe(false);
+ expect($(".cactus_toggle_skip").is(":visible")).toBe(true);
+ });
+ });
+
+ describe("some tests passed, some tests failed, some tests skipped", function() {
+ beforeEach(function() {
+ CactusReport.render(true , "test 1 passed");
+ CactusReport.render(false , "test 2 failed");
+ CactusReport.render("skip", "test 3 skipped");
});
it("displays div#cactus", function() {
- expect($("#cactus").is(":visible")).toBeTruthy();
+ expect($("#cactus").is(":visible")).toBe(true);
});
- it("contains 1 pass and 1 failure", function() {
+ it("contains 1 pass, 1 failure and 1 skip", function() {
expect($("#cactus .cactus_pass").length).toEqual(1);
expect($("#cactus .cactus_fail").length).toEqual(1);
+ expect($("#cactus .cactus_skip").length).toEqual(1);
});
- it("shows toggles for passes and failures", function() {
- expect($(".cactus_toggle_pass").is(":visible")).toBeTruthy();
- expect($(".cactus_toggle_fail").is(":visible")).toBeTruthy();
+ it("shows toggles for passes, failures and skips", function() {
+ expect($(".cactus_toggle_pass").is(":visible")).toBe(true);
+ expect($(".cactus_toggle_fail").is(":visible")).toBe(true);
+ expect($(".cactus_toggle_skip").is(":visible")).toBe(true);
});
});
@@ -57,12 +74,27 @@ describe("CactusReport", function() {
});
it("is hidden", function() {
- expect($("#cactus .cactus_pass").is(":visible")).toBeFalsy();
+ expect($("#cactus .cactus_pass").is(":visible")).toBe(false);
});
it("is shown when clicked on 'Show Passes'", function() {
$(".cactus_toggle_pass").click();
- expect($("#cactus .cactus_pass").is(":visible")).toBeTruthy();
+ expect($("#cactus .cactus_pass").is(":visible")).toBe(true);
+ })
+ });
+
+ describe("skips are hidden by default", function() {
+ beforeEach(function() {
+ CactusReport.render("skip" , "test 1 skipped");
+ });
+
+ it("is hidden", function() {
+ expect($("#cactus .cactus_skip").is(":visible")).toBe(false);
+ });
+
+ it("is shown when clicked on 'Show Skips'", function() {
+ $(".cactus_toggle_skip").click();
+ expect($("#cactus .cactus_skip").is(":visible")).toBe(true);
})
});
@@ -72,12 +104,12 @@ describe("CactusReport", function() {
});
it("is shown", function() {
- expect($("#cactus .cactus_fail").is(":visible")).toBeTruthy();
+ expect($("#cactus .cactus_fail").is(":visible")).toBe(true);
});
it("is shown when clicked on 'Show Passes'", function() {
$(".cactus_toggle_fail").click();
- expect($("#cactus .cactus_fail").is(":visible")).toBeFalsy();
+ expect($("#cactus .cactus_fail").is(":visible")).toBe(false);
})
});
});
View
12 spec/javascripts/cactusSpec.js
@@ -27,7 +27,7 @@ describe("Cactus", function() {
describe("toEqual", function() {
it("returns true when result is true for all matched elements", function() {
var result = Cactus.expect("label", "text-align").toEqual("right");
- expect(result).toBeTruthy();
+ expect(result).toBe(true);
});
it("returns false when result is false for one of the matched elements", function() {
@@ -35,7 +35,7 @@ describe("Cactus", function() {
$("label:first").css("text-align", "left");
var result = Cactus.expect("label", "text-align").toEqual("left");
- expect(result).toBeFalsy();
+ expect(result).toBe(false);
// Reset
$("label:first").css("text-align", "right");
@@ -45,7 +45,7 @@ describe("Cactus", function() {
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();
+ expect(result).toBe(true);
});
it("returns false when result is false for one of the matched elements", function() {
@@ -53,7 +53,7 @@ describe("Cactus", function() {
$("label:first").css("text-align", "left");
var result = Cactus.expect("label", "text-align").toContain("lef");
- expect(result).toBeFalsy();
+ expect(result).toBe(false);
// Reset
$("label:first").css("text-align", "right");
@@ -63,7 +63,7 @@ describe("Cactus", function() {
describe("toHaveColor", function() {
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();
+ expect(result).toBe(true);
});
it("returns false when result is false for one of the matched elements", function() {
@@ -71,7 +71,7 @@ describe("Cactus", function() {
$("label:first").css("color", "#000000");
var result = Cactus.expect("label", "color").toHaveColor("#000000");
- expect(result).toBeFalsy();
+ expect(result).toBe(false);
// Reset
$("label:first").css("color", "#330033");
View
84 vendor/assets/javascripts/cactus.js
@@ -36,7 +36,7 @@ Cactus = (function() {
};
_cactus.toContain = function(expected_style) {
- return compare(styles, expected_style, function(x, y) { return x.match(y); });
+ return compare(styles, expected_style, function(x, y) { return x.match(y) ? true : false; });
};
_cactus.toHaveColor = function(expected_style) {
@@ -97,32 +97,31 @@ CactusReport = (function() {
// Private Variables
var _cactus_report = {};
+ var status_styles =
+ {
+ false : { class: "cactus_fail", css: { "background": "#f6704d" } },
+ true : { class: "cactus_pass", css: { "display": "none", "background": "#93cd67" } },
+ "skip": { class: "cactus_skip", css: { "display": "none", "background": "#f0e68c" } }
+ };
_cactus_report.render = function(status, message) {
var $html, $row;
$html = init_container();
-
$row = $(
"<div />",
{
- html: message,
- css : { "padding": "5px 10px", "border-bottom": "1px solid #d3d3d3" }
+ html : message,
+ class: status_styles[status]["class"],
+ css : $.extend( { "padding": "5px 10px", "border-bottom": "1px solid #d3d3d3" }, status_styles[status]["css"] )
}
);
- if(status) {
- $row.addClass("cactus_pass");
- $row.css( { "display": "none", "background": "#93cd67" } );
- } else {
- $row.addClass("cactus_fail");
- $row.css( { "background": "#f6704d" } );
- }
-
$html.append($row);
// Show toggles
- if ($(".cactus_pass").length > 0) { $(".cactus_toggle_pass").show(); }
- if ($(".cactus_fail").length > 0) { $(".cactus_toggle_fail").show(); }
+ show_toggle("fail");
+ show_toggle("pass");
+ show_toggle("skip");
};
// Private Methods
@@ -132,7 +131,18 @@ CactusReport = (function() {
if ($html.length === 0) {
// Create a new div#cactus
- $html = $("<div id='cactus'><div class='cactus_header'><div class='cactus_banner'>Cactus</div><div class='cactus_option'><a href='#' class='cactus_toggle_pass' style='display: none;'>Show Passes</a> <a href='#' class='cactus_toggle_fail' style='display: none;'>Hide Failures</a></div></div></div>");
+ $html = $(
+ "<div id='cactus'>" +
+ "<div class='cactus_header'>" +
+ "<div class='cactus_banner'>Cactus</div>" +
+ "<div class='cactus_option'>" +
+ "<a href='#' class='cactus_toggle_fail' style='display: none;'>Hide Failures</a> " +
+ "<a href='#' class='cactus_toggle_pass' style='display: none;'>Show Passes</a> " +
+ "<a href='#' class='cactus_toggle_skip' style='display: none;'>Show Skips</a> " +
+ "</div>" +
+ "</div>" +
+ "</div>"
+ );
// Setup CSS stylings
$html.css( { "position": "absolute", "width": "100%", "bottom": 0, "left": 0, "font-size": "12px" } );
@@ -144,37 +154,37 @@ CactusReport = (function() {
$("body").append($html);
// Setup options
- show_and_hide_pass();
- show_and_hide_fail();
+ init_toggle("fail", "Show Failures", "Hide Failures");
+ init_toggle("pass", "Show Passes" , "Hide Passes" );
+ init_toggle("skip", "Show Skips" , "Hide Skips" );
}
return $html;
}
- function show_and_hide_pass() {
- $(".cactus_toggle_pass").toggle(
- function() {
- $(this).html("Hide Passes");
- $(".cactus_pass").show();
- },
+ function init_toggle(type, show_msg, hide_msg) {
+ $(".cactus_toggle_" + type).click(
function() {
- $(this).html("Show Passes");
- $(".cactus_pass").hide();
+ var $selector = $(".cactus_" + type);
+ if ($selector.is(":visible")) {
+ $(this).html(show_msg);
+ $selector.hide();
+ } else {
+ $(this).html(hide_msg);
+ $selector.show();
+ }
}
- );
+ )
}
- function show_and_hide_fail() {
- $(".cactus_toggle_fail").toggle(
- function() {
- $(this).html("Show Failures");
- $(".cactus_fail").hide();
- },
- function() {
- $(this).html("Hide Failures");
- $(".cactus_fail").show();
- }
- );
+ function show_toggle(type) {
+ var $link, $rows;
+ $link = $(".cactus_toggle_" + type);
+ $rows = $(".cactus_" + type);
+
+ if (!$link.is(":visible") && $rows.length > 0) {
+ $link.show();
+ }
}
// Return Accessor
Please sign in to comment.
Something went wrong with that request. Please try again.