2011-02-28 21:35:53 +00:00
|
|
|
describe("TrivialNodeReporter", function() {
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
var newline = "\n";
|
|
|
|
|
2011-02-28 22:51:03 +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}; } };
|
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-02-28 21:35:53 +00:00
|
|
|
beforeEach(function() {
|
|
|
|
this.fakeSys = (function(){
|
|
|
|
var output = "";
|
|
|
|
return {
|
|
|
|
puts:function(str) {output += str + "\n";},
|
|
|
|
print:function(str) {output += str;},
|
|
|
|
getOutput:function(){return output;}
|
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
|
|
|
this.reporter = new jasmine.TrivialNodeReporter(this.fakeSys);
|
|
|
|
});
|
|
|
|
|
2011-02-28 22:51:03 +00:00
|
|
|
|
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();
|
|
|
|
|
|
|
|
expect(this.fakeSys.getOutput()).toEqual(
|
|
|
|
"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);
|
|
|
|
|
|
|
|
expect(this.fakeSys.getOutput()).toEqual(
|
|
|
|
green(".")
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2011-02-28 21:45:22 +00:00
|
|
|
it("prints a red dot if the spec fails", function(){
|
|
|
|
this.reporter.reportSpecResults(failingSpec);
|
|
|
|
|
|
|
|
expect(this.fakeSys.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);
|
|
|
|
|
|
|
|
expect(this.fakeSys.getOutput()).toEqual(
|
|
|
|
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);
|
|
|
|
|
|
|
|
expect(this.fakeSys.getOutput()).
|
|
|
|
toEqual(repeat(red("F"), 49).join(""));
|
|
|
|
|
|
|
|
repeatedlyInvoke(function(){self.reporter.reportSpecResults(failingSpec);}, 3);
|
|
|
|
|
|
|
|
expect(this.fakeSys.getOutput()).
|
|
|
|
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-02-28 22:39:59 +00:00
|
|
|
expect(this.fakeSys.getOutput()).
|
|
|
|
toEqual(fiftyRedFs + newline +
|
|
|
|
fiftyRedFs + newline +
|
|
|
|
green(".") + green("."));
|
|
|
|
});
|
2011-02-28 21:35:53 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|