2011-03-01 02:02:44 +00:00
|
|
|
describe("TrivialConsoleReporter", function() {
|
2011-02-28 21:35:53 +00:00
|
|
|
|
|
|
|
|
2011-02-28 22:51:03 +00:00
|
|
|
//keep these literal. otherwise the test loses value as a test.
|
|
|
|
function green(str) { return '\033[32m' + str + '\033[0m'; }
|
|
|
|
function red(str) { return '\033[31m' + str + '\033[0m'; }
|
|
|
|
function yellow(str) { return '\033[33m' + str + '\033[0m'; }
|
2011-02-28 21:35:53 +00:00
|
|
|
|
2011-02-28 23:13:46 +00:00
|
|
|
function prefixGreen(str) { return '\033[32m' + str; }
|
|
|
|
function prefixRed(str) { return '\033[31m' + str; }
|
|
|
|
|
2011-02-28 21:35:53 +00:00
|
|
|
var newline = "\n";
|
|
|
|
|
2011-03-01 00:50:54 +00:00
|
|
|
var passingSpec = { results: function(){ return {passed: function(){return true;}}; } },
|
|
|
|
failingSpec = { results: function(){ return {passed: function(){return false;}}; } },
|
|
|
|
skippedSpec = { results: function(){ return {skipped: true}; } },
|
|
|
|
passingRun = { results: function(){ return {failedCount: 0, specs: function(){return [null, null, null];}}; } },
|
|
|
|
failingRun = { results: function(){ return {failedCount: 7, specs: function(){return [null, null, null];}}; } };
|
2011-02-28 22:39:59 +00:00
|
|
|
|
2011-02-28 22:51:03 +00:00
|
|
|
function repeatedlyInvoke(f, times) { for(var i=0; i<times; i++) f(times+1); }
|
2011-02-28 22:39:59 +00:00
|
|
|
|
|
|
|
function repeat(thing, times) {
|
|
|
|
var arr = [];
|
|
|
|
for(var i=0; i<times; i++) arr.push(thing);
|
|
|
|
return arr;
|
|
|
|
}
|
|
|
|
|
2011-02-28 22:51:03 +00:00
|
|
|
var fiftyRedFs = repeat(red("F"), 50).join(""),
|
|
|
|
fiftyGreenDots = repeat(green("."), 50).join("");
|
2011-02-28 22:39:59 +00:00
|
|
|
|
2011-03-01 01:50:16 +00:00
|
|
|
function simulateRun(reporter, specResults, suiteResults, finalRunner, startTime, endTime) {
|
|
|
|
reporter.reportRunnerStarting();
|
|
|
|
for(var i=0; i<specResults.length; i++) reporter.reportSpecResults(specResults[i]);
|
|
|
|
for(i=0; i<suiteResults.length; i++) reporter.reportSuiteResults(suiteResults[i]);
|
|
|
|
reporter.runnerStartTime = startTime;
|
|
|
|
reporter.now = function(){return endTime;};
|
|
|
|
reporter.reportRunnerResults(finalRunner);
|
|
|
|
}
|
|
|
|
|
2011-02-28 21:35:53 +00:00
|
|
|
beforeEach(function() {
|
2011-03-01 01:58:29 +00:00
|
|
|
this.out = (function(){
|
2011-02-28 21:35:53 +00:00
|
|
|
var output = "";
|
|
|
|
return {
|
|
|
|
print:function(str) {output += str;},
|
2011-02-28 23:31:48 +00:00
|
|
|
getOutput:function(){return output;},
|
|
|
|
clear: function(){output = "";}
|
2011-02-28 21:35:53 +00:00
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
2011-03-01 02:02:44 +00:00
|
|
|
this.reporter = new jasmine.TrivialConsoleReporter(this.out.print);
|
2011-02-28 21:35:53 +00:00
|
|
|
});
|
|
|
|
|
2011-02-28 22:51:03 +00:00
|
|
|
|
2011-03-01 01:50:16 +00:00
|
|
|
describe('Integration test', function(){
|
|
|
|
it("prints the proper output under a pass scenario. small numbers.", function(){
|
|
|
|
simulateRun(this.reporter,
|
|
|
|
repeat(passingSpec, 3),
|
|
|
|
[],
|
|
|
|
{
|
|
|
|
results:function(){
|
|
|
|
return {
|
|
|
|
specs: function(){return [null, null, null];},
|
|
|
|
totalCount: 7,
|
|
|
|
failedCount: 0
|
|
|
|
};
|
|
|
|
}
|
|
|
|
},
|
|
|
|
1000,
|
|
|
|
1777);
|
|
|
|
|
2011-03-01 01:58:29 +00:00
|
|
|
expect(this.out.getOutput()).toEqual(
|
2011-03-01 01:50:16 +00:00
|
|
|
[
|
|
|
|
"Started",
|
|
|
|
green(".") + green(".") + green("."),
|
|
|
|
"",
|
|
|
|
"Finished in 0.777 seconds",
|
|
|
|
green("3 specs, 7 assertions, 0 failures"),
|
|
|
|
""
|
|
|
|
].join("\n") + "\n"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("prints the proper output under a pass scenario. large numbers.", function(){
|
|
|
|
simulateRun(this.reporter,
|
|
|
|
repeat(passingSpec, 57),
|
|
|
|
[],
|
|
|
|
{
|
|
|
|
results:function(){
|
|
|
|
return {
|
|
|
|
specs: function(){return [null, null, null];},
|
|
|
|
totalCount: 7,
|
|
|
|
failedCount: 0
|
|
|
|
};
|
|
|
|
}
|
|
|
|
},
|
|
|
|
1000,
|
|
|
|
1777);
|
|
|
|
|
2011-03-01 01:58:29 +00:00
|
|
|
expect(this.out.getOutput()).toEqual(
|
2011-03-01 01:50:16 +00:00
|
|
|
[
|
|
|
|
"Started",
|
2011-03-01 01:58:29 +00:00
|
|
|
|
|
|
|
green(".") + green(".") + green(".") + green(".") + green(".") + //50 green dots
|
2011-03-01 01:50:16 +00:00
|
|
|
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(".") +
|
2011-03-01 01:58:29 +00:00
|
|
|
green(".") + green(".") + green(".") + green(".") + green(".") + newline +
|
|
|
|
|
|
|
|
green(".") + green(".") + green(".") + green(".") + green(".") + //7 green dots
|
2011-03-01 01:50:16 +00:00
|
|
|
green(".") + green("."),
|
2011-03-01 01:58:29 +00:00
|
|
|
|
2011-03-01 01:50:16 +00:00
|
|
|
"",
|
|
|
|
"Finished in 0.777 seconds",
|
|
|
|
green("3 specs, 7 assertions, 0 failures"),
|
|
|
|
""
|
|
|
|
].join("\n") + "\n"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2011-02-28 21:35:53 +00:00
|
|
|
describe('A Test Run', function(){
|
2011-02-28 22:56:09 +00:00
|
|
|
|
|
|
|
describe('Starts', function(){
|
|
|
|
it("prints Started", function(){
|
|
|
|
this.reporter.reportRunnerStarting();
|
|
|
|
|
2011-03-01 01:58:29 +00:00
|
|
|
expect(this.out.getOutput()).toEqual(
|
2011-02-28 22:56:09 +00:00
|
|
|
"Started" + newline
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2011-02-28 21:35:53 +00:00
|
|
|
|
|
|
|
describe('A spec runs', function(){
|
|
|
|
it("prints a green dot if the spec passes", function(){
|
|
|
|
this.reporter.reportSpecResults(passingSpec);
|
|
|
|
|
2011-03-01 01:58:29 +00:00
|
|
|
expect(this.out.getOutput()).toEqual(
|
2011-02-28 21:35:53 +00:00
|
|
|
green(".")
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2011-02-28 21:45:22 +00:00
|
|
|
it("prints a red dot if the spec fails", function(){
|
|
|
|
this.reporter.reportSpecResults(failingSpec);
|
|
|
|
|
2011-03-01 01:58:29 +00:00
|
|
|
expect(this.out.getOutput()).toEqual(
|
2011-02-28 21:46:30 +00:00
|
|
|
red("F")
|
2011-02-28 21:45:22 +00:00
|
|
|
);
|
|
|
|
});
|
2011-02-28 22:51:03 +00:00
|
|
|
|
|
|
|
it("prints a yellow star if the spec was skipped", function(){
|
|
|
|
this.reporter.reportSpecResults(skippedSpec);
|
|
|
|
|
2011-03-01 01:58:29 +00:00
|
|
|
expect(this.out.getOutput()).toEqual(
|
2011-02-28 22:51:03 +00:00
|
|
|
yellow("*")
|
|
|
|
);
|
|
|
|
});
|
2011-02-28 22:39:59 +00:00
|
|
|
});
|
|
|
|
|
2011-02-28 21:45:22 +00:00
|
|
|
|
2011-02-28 22:56:09 +00:00
|
|
|
describe('Many specs run', function(){
|
2011-02-28 22:39:59 +00:00
|
|
|
it("starts a new line every 50 specs", function(){
|
|
|
|
var self = this;
|
|
|
|
repeatedlyInvoke(function(){self.reporter.reportSpecResults(failingSpec);}, 49);
|
|
|
|
|
2011-03-01 01:58:29 +00:00
|
|
|
expect(this.out.getOutput()).
|
2011-02-28 22:39:59 +00:00
|
|
|
toEqual(repeat(red("F"), 49).join(""));
|
|
|
|
|
|
|
|
repeatedlyInvoke(function(){self.reporter.reportSpecResults(failingSpec);}, 3);
|
|
|
|
|
2011-03-01 01:58:29 +00:00
|
|
|
expect(this.out.getOutput()).
|
2011-02-28 22:39:59 +00:00
|
|
|
toEqual(fiftyRedFs + newline +
|
|
|
|
red("F") + red("F"));
|
|
|
|
|
|
|
|
repeatedlyInvoke(function(){self.reporter.reportSpecResults(failingSpec);}, 48);
|
|
|
|
repeatedlyInvoke(function(){self.reporter.reportSpecResults(passingSpec);}, 2);
|
2011-02-28 22:51:03 +00:00
|
|
|
|
2011-03-01 01:58:29 +00:00
|
|
|
expect(this.out.getOutput()).
|
2011-02-28 22:39:59 +00:00
|
|
|
toEqual(fiftyRedFs + newline +
|
|
|
|
fiftyRedFs + newline +
|
|
|
|
green(".") + green("."));
|
|
|
|
});
|
2011-02-28 21:35:53 +00:00
|
|
|
});
|
2011-02-28 23:13:46 +00:00
|
|
|
|
2011-03-01 00:16:20 +00:00
|
|
|
describe('A suite runs', function(){
|
|
|
|
it("remembers suite results", function(){
|
|
|
|
var emptyResults = function(){return {items_:[]};};
|
2011-03-01 00:50:54 +00:00
|
|
|
this.reporter.reportSuiteResults({description:"Oven", results:emptyResults});
|
|
|
|
this.reporter.reportSuiteResults({description:"Mixer", results:emptyResults});
|
2011-03-01 00:16:20 +00:00
|
|
|
|
2011-03-01 00:50:54 +00:00
|
|
|
var self = this;
|
|
|
|
var descriptions = [];
|
2011-03-01 00:16:20 +00:00
|
|
|
for(var i=0; i<self.reporter.suiteResults.length; i++)
|
2011-03-01 00:50:54 +00:00
|
|
|
descriptions.push(self.reporter.suiteResults[i].description);
|
2011-03-01 00:16:20 +00:00
|
|
|
|
2011-03-01 00:50:54 +00:00
|
|
|
expect(descriptions).toEqual(["Oven", "Mixer"]);
|
2011-03-01 00:16:20 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("creates a description out of the current suite and any parent suites", function(){
|
|
|
|
var emptyResults = function(){return {items_:[]};};
|
2011-03-01 00:50:54 +00:00
|
|
|
var grandparentSuite = {description:"My house", results:emptyResults};
|
|
|
|
var parentSuite = {description:"kitchen", parentSuite: grandparentSuite, results:emptyResults};
|
|
|
|
this.reporter.reportSuiteResults({description:"oven", parentSuite: parentSuite, results:emptyResults});
|
2011-03-01 00:16:20 +00:00
|
|
|
|
2011-03-01 00:50:54 +00:00
|
|
|
expect(this.reporter.suiteResults[0].description).toEqual("My house kitchen oven");
|
2011-03-01 00:16:20 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("gathers failing spec results from the suite. the spec must have a description.", function(){
|
|
|
|
this.reporter.reportSuiteResults({description:"Oven",
|
|
|
|
results:function(){
|
|
|
|
return {
|
|
|
|
items_:[
|
|
|
|
{failedCount:0, description:"specOne"},
|
|
|
|
{failedCount:99, description:"specTwo"},
|
|
|
|
{failedCount:0, description:"specThree"},
|
|
|
|
{failedCount:88, description:"specFour"},
|
|
|
|
{failedCount:3}
|
|
|
|
]
|
2011-03-01 00:50:54 +00:00
|
|
|
};
|
|
|
|
}});
|
2011-03-01 00:16:20 +00:00
|
|
|
|
|
|
|
expect(this.reporter.suiteResults[0].failedSpecResults).
|
|
|
|
toEqual([
|
|
|
|
{failedCount:99, description:"specTwo"},
|
|
|
|
{failedCount:88, description:"specFour"}
|
2011-03-01 00:50:54 +00:00
|
|
|
]);
|
2011-03-01 00:16:20 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
2011-02-28 23:13:46 +00:00
|
|
|
|
|
|
|
describe('Finishes', function(){
|
2011-03-01 01:13:04 +00:00
|
|
|
|
|
|
|
describe('Spec failure information', function(){
|
|
|
|
|
|
|
|
it("prints suite and spec descriptions together as a sentence", function(){
|
|
|
|
this.reporter.suiteResults = [
|
|
|
|
{description:"The oven", failedSpecResults:[
|
2011-03-01 01:20:22 +00:00
|
|
|
{description:"heats up", items_:[]},
|
|
|
|
{description:"cleans itself", items_:[]}
|
2011-03-01 01:13:04 +00:00
|
|
|
]},
|
|
|
|
{description:"The mixer", failedSpecResults:[
|
2011-03-01 01:20:22 +00:00
|
|
|
{description:"blends things together", items_:[]}
|
2011-03-01 01:13:04 +00:00
|
|
|
]}
|
2011-03-01 01:20:22 +00:00
|
|
|
];
|
2011-03-01 01:13:04 +00:00
|
|
|
|
|
|
|
this.reporter.reportRunnerResults(failingRun);
|
|
|
|
|
2011-03-01 01:58:29 +00:00
|
|
|
expect(this.out.getOutput()).toContain("The oven heats up");
|
|
|
|
expect(this.out.getOutput()).toContain("The oven cleans itself");
|
|
|
|
expect(this.out.getOutput()).toContain("The mixer blends things together");
|
2011-03-01 01:13:04 +00:00
|
|
|
});
|
|
|
|
|
2011-03-01 01:20:22 +00:00
|
|
|
it("prints stack trace of spec failure", function(){
|
|
|
|
this.reporter.suiteResults = [
|
|
|
|
{description:"The oven", failedSpecResults:[
|
|
|
|
{description:"heats up",
|
|
|
|
items_:[
|
|
|
|
{trace:{stack:"stack trace one"}},
|
|
|
|
{trace:{stack:"stack trace two"}}
|
|
|
|
]}
|
|
|
|
]}
|
|
|
|
];
|
|
|
|
|
|
|
|
this.reporter.reportRunnerResults(failingRun);
|
|
|
|
|
2011-03-01 01:58:29 +00:00
|
|
|
expect(this.out.getOutput()).toContain("The oven heats up");
|
|
|
|
expect(this.out.getOutput()).toContain("stack trace one");
|
|
|
|
expect(this.out.getOutput()).toContain("stack trace two");
|
2011-03-01 01:20:22 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
2011-03-01 01:13:04 +00:00
|
|
|
|
2011-03-01 00:50:54 +00:00
|
|
|
describe('Finished line', function(){
|
2011-02-28 23:31:48 +00:00
|
|
|
|
2011-03-01 00:50:54 +00:00
|
|
|
it("prints the elapsed time in the summary message", function(){
|
|
|
|
this.reporter.now = function(){return 1000;};
|
|
|
|
this.reporter.reportRunnerStarting();
|
|
|
|
this.reporter.now = function(){return 1777;};
|
|
|
|
this.reporter.reportRunnerResults(passingRun);
|
2011-03-01 01:58:29 +00:00
|
|
|
expect(this.out.getOutput()).toContain("0.777 seconds");
|
2011-03-01 00:50:54 +00:00
|
|
|
});
|
2011-02-28 23:31:48 +00:00
|
|
|
|
2011-03-01 00:50:54 +00:00
|
|
|
it("prints round time numbers correctly", function(){
|
|
|
|
var self = this;
|
|
|
|
function run(startTime, endTime) {
|
2011-03-01 01:58:29 +00:00
|
|
|
self.out.clear();
|
2011-03-01 00:50:54 +00:00
|
|
|
self.reporter.runnerStartTime = startTime;
|
|
|
|
self.reporter.now = function(){return endTime;};
|
|
|
|
self.reporter.reportRunnerResults(passingRun);
|
|
|
|
}
|
2011-02-28 23:31:48 +00:00
|
|
|
|
2011-03-01 00:50:54 +00:00
|
|
|
run(1000, 11000);
|
2011-03-01 01:58:29 +00:00
|
|
|
expect(this.out.getOutput()).toContain("10 seconds");
|
2011-02-28 23:31:48 +00:00
|
|
|
|
2011-03-01 00:50:54 +00:00
|
|
|
run(1000, 2000);
|
2011-03-01 01:58:29 +00:00
|
|
|
expect(this.out.getOutput()).toContain("1 seconds");
|
2011-02-28 23:31:48 +00:00
|
|
|
|
2011-03-01 00:50:54 +00:00
|
|
|
run(1000, 1100);
|
2011-03-01 01:58:29 +00:00
|
|
|
expect(this.out.getOutput()).toContain("0.1 seconds");
|
2011-03-01 00:50:54 +00:00
|
|
|
|
|
|
|
run(1000, 1010);
|
2011-03-01 01:58:29 +00:00
|
|
|
expect(this.out.getOutput()).toContain("0.01 seconds");
|
2011-03-01 00:50:54 +00:00
|
|
|
|
|
|
|
run(1000, 1001);
|
2011-03-01 01:58:29 +00:00
|
|
|
expect(this.out.getOutput()).toContain("0.001 seconds");
|
2011-03-01 00:50:54 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("prints the full finished message", function(){
|
|
|
|
this.reporter.now = function(){return 1000;};
|
|
|
|
this.reporter.reportRunnerStarting();
|
|
|
|
this.reporter.now = function(){return 1777;};
|
|
|
|
this.reporter.reportRunnerResults(failingRun);
|
2011-03-01 01:58:29 +00:00
|
|
|
expect(this.out.getOutput()).toContain("Finished in 0.777 seconds");
|
2011-03-01 00:50:54 +00:00
|
|
|
});
|
2011-02-28 23:31:48 +00:00
|
|
|
});
|
|
|
|
|
2011-03-01 00:50:54 +00:00
|
|
|
describe("specs/assertions/failures summary", function(){
|
|
|
|
it("prints statistics in green if there were no failures", function() {
|
|
|
|
this.reporter.reportRunnerResults({
|
|
|
|
results:function(){return {specs: function(){return [null, null, null];}, totalCount: 7, failedCount: 0};}
|
|
|
|
});
|
2011-03-01 01:58:29 +00:00
|
|
|
expect(this.out.getOutput()).
|
2011-03-01 00:50:54 +00:00
|
|
|
toContain("3 specs, 7 assertions, 0 failures");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("prints statistics in red if there was a failure", function() {
|
|
|
|
this.reporter.reportRunnerResults({
|
|
|
|
results:function(){return {specs: function(){return [null, null, null];}, totalCount: 7, failedCount: 3};}
|
|
|
|
});
|
2011-03-01 01:58:29 +00:00
|
|
|
expect(this.out.getOutput()).
|
2011-03-01 00:50:54 +00:00
|
|
|
toContain("3 specs, 7 assertions, 3 failures");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("handles pluralization with 1's ones appropriately", function() {
|
|
|
|
this.reporter.reportRunnerResults({
|
|
|
|
results:function(){return {specs: function(){return [null];}, totalCount: 1, failedCount: 1};}
|
|
|
|
});
|
2011-03-01 01:58:29 +00:00
|
|
|
expect(this.out.getOutput()).
|
2011-03-01 00:50:54 +00:00
|
|
|
toContain("1 spec, 1 assertion, 1 failure");
|
|
|
|
});
|
2011-02-28 23:31:48 +00:00
|
|
|
});
|
|
|
|
|
2011-02-28 23:13:46 +00:00
|
|
|
});
|
2011-02-28 21:35:53 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|