This commit is contained in:
Steve Conover 2011-02-28 17:58:29 -08:00
parent ac00d765d2
commit a1f58f8be4
2 changed files with 46 additions and 44 deletions

View File

@ -38,17 +38,16 @@ describe("TrivialNodeReporter", function() {
} }
beforeEach(function() { beforeEach(function() {
this.fakeSys = (function(){ this.out = (function(){
var output = ""; var output = "";
return { return {
puts:function(str) {output += str + "\n";},
print:function(str) {output += str;}, print:function(str) {output += str;},
getOutput:function(){return output;}, getOutput:function(){return output;},
clear: function(){output = "";} clear: function(){output = "";}
}; };
})(); })();
this.reporter = new jasmine.TrivialNodeReporter(this.fakeSys); this.reporter = new jasmine.TrivialNodeReporter(this.out.print);
}); });
@ -69,7 +68,7 @@ describe("TrivialNodeReporter", function() {
1000, 1000,
1777); 1777);
expect(this.fakeSys.getOutput()).toEqual( expect(this.out.getOutput()).toEqual(
[ [
"Started", "Started",
green(".") + green(".") + green("."), green(".") + green(".") + green("."),
@ -97,9 +96,11 @@ describe("TrivialNodeReporter", function() {
1000, 1000,
1777); 1777);
expect(this.fakeSys.getOutput()).toEqual( expect(this.out.getOutput()).toEqual(
[ [
"Started", "Started",
green(".") + green(".") + green(".") + green(".") + green(".") + //50 green dots
green(".") + green(".") + green(".") + green(".") + green(".") + green(".") + green(".") + green(".") + green(".") + green(".") +
green(".") + green(".") + green(".") + green(".") + green(".") + green(".") + green(".") + green(".") + green(".") + green(".") +
green(".") + green(".") + green(".") + green(".") + green(".") + green(".") + green(".") + green(".") + green(".") + green(".") +
@ -108,10 +109,11 @@ describe("TrivialNodeReporter", function() {
green(".") + green(".") + green(".") + green(".") + green(".") + green(".") + green(".") + green(".") + green(".") + green(".") +
green(".") + green(".") + green(".") + green(".") + green(".") + green(".") + green(".") + green(".") + green(".") + green(".") +
green(".") + green(".") + green(".") + green(".") + green(".") + green(".") + green(".") + green(".") + green(".") + green(".") +
green(".") + green(".") + green(".") + green(".") + green(".") + green(".") + green(".") + green(".") + green(".") + green(".") + newline +
green(".") + green(".") + green(".") + green(".") + green(".") + "\n" +
green(".") + green(".") + green(".") + green(".") + green(".") + green(".") + green(".") + green(".") + green(".") + green(".") + //7 green dots
green(".") + green("."), green(".") + green("."),
"", "",
"Finished in 0.777 seconds", "Finished in 0.777 seconds",
green("3 specs, 7 assertions, 0 failures"), green("3 specs, 7 assertions, 0 failures"),
@ -127,7 +129,7 @@ describe("TrivialNodeReporter", function() {
it("prints Started", function(){ it("prints Started", function(){
this.reporter.reportRunnerStarting(); this.reporter.reportRunnerStarting();
expect(this.fakeSys.getOutput()).toEqual( expect(this.out.getOutput()).toEqual(
"Started" + newline "Started" + newline
); );
}); });
@ -137,7 +139,7 @@ describe("TrivialNodeReporter", function() {
it("prints a green dot if the spec passes", function(){ it("prints a green dot if the spec passes", function(){
this.reporter.reportSpecResults(passingSpec); this.reporter.reportSpecResults(passingSpec);
expect(this.fakeSys.getOutput()).toEqual( expect(this.out.getOutput()).toEqual(
green(".") green(".")
); );
}); });
@ -145,7 +147,7 @@ describe("TrivialNodeReporter", function() {
it("prints a red dot if the spec fails", function(){ it("prints a red dot if the spec fails", function(){
this.reporter.reportSpecResults(failingSpec); this.reporter.reportSpecResults(failingSpec);
expect(this.fakeSys.getOutput()).toEqual( expect(this.out.getOutput()).toEqual(
red("F") red("F")
); );
}); });
@ -153,7 +155,7 @@ describe("TrivialNodeReporter", function() {
it("prints a yellow star if the spec was skipped", function(){ it("prints a yellow star if the spec was skipped", function(){
this.reporter.reportSpecResults(skippedSpec); this.reporter.reportSpecResults(skippedSpec);
expect(this.fakeSys.getOutput()).toEqual( expect(this.out.getOutput()).toEqual(
yellow("*") yellow("*")
); );
}); });
@ -165,19 +167,19 @@ describe("TrivialNodeReporter", function() {
var self = this; var self = this;
repeatedlyInvoke(function(){self.reporter.reportSpecResults(failingSpec);}, 49); repeatedlyInvoke(function(){self.reporter.reportSpecResults(failingSpec);}, 49);
expect(this.fakeSys.getOutput()). expect(this.out.getOutput()).
toEqual(repeat(red("F"), 49).join("")); toEqual(repeat(red("F"), 49).join(""));
repeatedlyInvoke(function(){self.reporter.reportSpecResults(failingSpec);}, 3); repeatedlyInvoke(function(){self.reporter.reportSpecResults(failingSpec);}, 3);
expect(this.fakeSys.getOutput()). expect(this.out.getOutput()).
toEqual(fiftyRedFs + newline + toEqual(fiftyRedFs + newline +
red("F") + red("F")); red("F") + red("F"));
repeatedlyInvoke(function(){self.reporter.reportSpecResults(failingSpec);}, 48); repeatedlyInvoke(function(){self.reporter.reportSpecResults(failingSpec);}, 48);
repeatedlyInvoke(function(){self.reporter.reportSpecResults(passingSpec);}, 2); repeatedlyInvoke(function(){self.reporter.reportSpecResults(passingSpec);}, 2);
expect(this.fakeSys.getOutput()). expect(this.out.getOutput()).
toEqual(fiftyRedFs + newline + toEqual(fiftyRedFs + newline +
fiftyRedFs + newline + fiftyRedFs + newline +
green(".") + green(".")); green(".") + green("."));
@ -247,9 +249,9 @@ describe("TrivialNodeReporter", function() {
this.reporter.reportRunnerResults(failingRun); this.reporter.reportRunnerResults(failingRun);
expect(this.fakeSys.getOutput()).toContain("The oven heats up"); expect(this.out.getOutput()).toContain("The oven heats up");
expect(this.fakeSys.getOutput()).toContain("The oven cleans itself"); expect(this.out.getOutput()).toContain("The oven cleans itself");
expect(this.fakeSys.getOutput()).toContain("The mixer blends things together"); expect(this.out.getOutput()).toContain("The mixer blends things together");
}); });
it("prints stack trace of spec failure", function(){ it("prints stack trace of spec failure", function(){
@ -265,9 +267,9 @@ describe("TrivialNodeReporter", function() {
this.reporter.reportRunnerResults(failingRun); this.reporter.reportRunnerResults(failingRun);
expect(this.fakeSys.getOutput()).toContain("The oven heats up"); expect(this.out.getOutput()).toContain("The oven heats up");
expect(this.fakeSys.getOutput()).toContain("stack trace one"); expect(this.out.getOutput()).toContain("stack trace one");
expect(this.fakeSys.getOutput()).toContain("stack trace two"); expect(this.out.getOutput()).toContain("stack trace two");
}); });
}); });
@ -279,32 +281,32 @@ describe("TrivialNodeReporter", function() {
this.reporter.reportRunnerStarting(); this.reporter.reportRunnerStarting();
this.reporter.now = function(){return 1777;}; this.reporter.now = function(){return 1777;};
this.reporter.reportRunnerResults(passingRun); this.reporter.reportRunnerResults(passingRun);
expect(this.fakeSys.getOutput()).toContain("0.777 seconds"); expect(this.out.getOutput()).toContain("0.777 seconds");
}); });
it("prints round time numbers correctly", function(){ it("prints round time numbers correctly", function(){
var self = this; var self = this;
function run(startTime, endTime) { function run(startTime, endTime) {
self.fakeSys.clear(); self.out.clear();
self.reporter.runnerStartTime = startTime; self.reporter.runnerStartTime = startTime;
self.reporter.now = function(){return endTime;}; self.reporter.now = function(){return endTime;};
self.reporter.reportRunnerResults(passingRun); self.reporter.reportRunnerResults(passingRun);
} }
run(1000, 11000); run(1000, 11000);
expect(this.fakeSys.getOutput()).toContain("10 seconds"); expect(this.out.getOutput()).toContain("10 seconds");
run(1000, 2000); run(1000, 2000);
expect(this.fakeSys.getOutput()).toContain("1 seconds"); expect(this.out.getOutput()).toContain("1 seconds");
run(1000, 1100); run(1000, 1100);
expect(this.fakeSys.getOutput()).toContain("0.1 seconds"); expect(this.out.getOutput()).toContain("0.1 seconds");
run(1000, 1010); run(1000, 1010);
expect(this.fakeSys.getOutput()).toContain("0.01 seconds"); expect(this.out.getOutput()).toContain("0.01 seconds");
run(1000, 1001); run(1000, 1001);
expect(this.fakeSys.getOutput()).toContain("0.001 seconds"); expect(this.out.getOutput()).toContain("0.001 seconds");
}); });
it("prints the full finished message", function(){ it("prints the full finished message", function(){
@ -312,7 +314,7 @@ describe("TrivialNodeReporter", function() {
this.reporter.reportRunnerStarting(); this.reporter.reportRunnerStarting();
this.reporter.now = function(){return 1777;}; this.reporter.now = function(){return 1777;};
this.reporter.reportRunnerResults(failingRun); this.reporter.reportRunnerResults(failingRun);
expect(this.fakeSys.getOutput()).toContain("Finished in 0.777 seconds"); expect(this.out.getOutput()).toContain("Finished in 0.777 seconds");
}); });
}); });
@ -321,7 +323,7 @@ describe("TrivialNodeReporter", function() {
this.reporter.reportRunnerResults({ this.reporter.reportRunnerResults({
results:function(){return {specs: function(){return [null, null, null];}, totalCount: 7, failedCount: 0};} results:function(){return {specs: function(){return [null, null, null];}, totalCount: 7, failedCount: 0};}
}); });
expect(this.fakeSys.getOutput()). expect(this.out.getOutput()).
toContain("3 specs, 7 assertions, 0 failures"); toContain("3 specs, 7 assertions, 0 failures");
}); });
@ -329,7 +331,7 @@ describe("TrivialNodeReporter", function() {
this.reporter.reportRunnerResults({ this.reporter.reportRunnerResults({
results:function(){return {specs: function(){return [null, null, null];}, totalCount: 7, failedCount: 3};} results:function(){return {specs: function(){return [null, null, null];}, totalCount: 7, failedCount: 3};}
}); });
expect(this.fakeSys.getOutput()). expect(this.out.getOutput()).
toContain("3 specs, 7 assertions, 3 failures"); toContain("3 specs, 7 assertions, 3 failures");
}); });
@ -337,7 +339,7 @@ describe("TrivialNodeReporter", function() {
this.reporter.reportRunnerResults({ this.reporter.reportRunnerResults({
results:function(){return {specs: function(){return [null];}, totalCount: 1, failedCount: 1};} results:function(){return {specs: function(){return [null];}, totalCount: 1, failedCount: 1};}
}); });
expect(this.fakeSys.getOutput()). expect(this.out.getOutput()).
toContain("1 spec, 1 assertion, 1 failure"); toContain("1 spec, 1 assertion, 1 failure");
}); });
}); });

View File

@ -1,4 +1,4 @@
jasmine.TrivialNodeReporter = function(sys) { jasmine.TrivialNodeReporter = function(print) {
var ansi = { var ansi = {
green: '\033[32m', green: '\033[32m',
@ -21,29 +21,29 @@ jasmine.TrivialNodeReporter = function(sys) {
function redStr(str) { return coloredStr("red", str); } function redStr(str) { return coloredStr("red", str); }
function yellowStr(str) { return coloredStr("yellow", str); } function yellowStr(str) { return coloredStr("yellow", str); }
function newline() { sys.print("\n"); } function newline() { print("\n"); }
function started() { sys.print("Started"); newline(); } function started() { print("Started"); newline(); }
function greenDot() { sys.print(greenStr(".")); } function greenDot() { print(greenStr(".")); }
function redF() { sys.print(redStr("F")); } function redF() { print(redStr("F")); }
function yellowStar() { sys.print(yellowStr("*")); } function yellowStar() { print(yellowStr("*")); }
function plural(str, count) { return count == 1 ? str : str + "s"; } function plural(str, count) { return count == 1 ? str : str + "s"; }
function specFailureDetails(suiteDescription, specDescription, stackTraces) { function specFailureDetails(suiteDescription, specDescription, stackTraces) {
newline(); newline();
sys.print(suiteDescription + " " + specDescription); print(suiteDescription + " " + specDescription);
newline(); newline();
for(var i=0; i<stackTraces.length; i++) { for(var i=0; i<stackTraces.length; i++) {
sys.print(stackTraces[i]); print(stackTraces[i]);
newline(); newline();
} }
} }
function finished(elapsed) { newline(); function finished(elapsed) { newline();
newline(); newline();
sys.print("Finished in " + elapsed/1000 + " seconds"); } print("Finished in " + elapsed/1000 + " seconds"); }
function summary(colorF, specs, assertions, failed) { newline(); function summary(colorF, specs, assertions, failed) { newline();
sys.print(colorF(specs + " " + plural(language.spec, specs) + ", " + print(colorF(specs + " " + plural(language.spec, specs) + ", " +
assertions + " " + plural(language.assertion, assertions) + ", " + assertions + " " + plural(language.assertion, assertions) + ", " +
failed + " " + plural(language.failure, failed))); failed + " " + plural(language.failure, failed)));
newline(); newline();