newline at 50 characters

This commit is contained in:
Steve Conover 2011-02-28 14:39:59 -08:00
parent dccafe33b0
commit 8fbf3ba859
2 changed files with 69 additions and 10 deletions

View File

@ -11,6 +11,31 @@ describe("TrivialNodeReporter", function() {
var newline = "\n"; var newline = "\n";
var passingSpec = {
results: function(){
return {passed:function(){return true;}};
}
};
var failingSpec = {
results: function(){
return {passed:function(){return false;}};
}
};
function repeatedlyInvoke(f, times) {
for(var i=0; i<times; i++) f(times+1);
}
function repeat(thing, times) {
var arr = [];
for(var i=0; i<times; i++) arr.push(thing);
return arr;
}
var fiftyRedFs = repeat(red("F"), 50).join("");
var fiftyGreenDots = repeat(green("."), 50).join("");
beforeEach(function() { beforeEach(function() {
this.fakeSys = (function(){ this.fakeSys = (function(){
var output = ""; var output = "";
@ -49,13 +74,7 @@ describe("TrivialNodeReporter", function() {
describe('A Test Run', function(){ describe('A Test Run', function(){
describe('A spec runs', function(){ describe('A spec runs', function(){
it("prints a green dot if the spec passes", function(){ it("prints a green dot if the spec passes", function(){
var passingSpec = {
results: function(){
return {passed:function(){return true;}};
}
};
this.reporter.reportSpecResults(passingSpec); this.reporter.reportSpecResults(passingSpec);
expect(this.fakeSys.getOutput()).toEqual( expect(this.fakeSys.getOutput()).toEqual(
@ -75,7 +94,30 @@ describe("TrivialNodeReporter", function() {
red("F") red("F")
); );
}); });
});
describe('many specs run', function(){
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);
expect(this.fakeSys.getOutput()).
toEqual(fiftyRedFs + newline +
fiftyRedFs + newline +
green(".") + green("."));
});
}); });
}); });

View File

@ -7,15 +7,31 @@ jasmine.TrivialNodeReporter = function(sys) {
none: '\033[0m' none: '\033[0m'
}; };
var defaultColumnsPerLine = 50;
function coloredStr(color, str) { return ansi[color] + str + ansi.none; } function coloredStr(color, str) { return ansi[color] + str + ansi.none; }
function greenStr(str) { return coloredStr("green", str); } function greenStr(str) { return coloredStr("green", str); }
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 greenDot(str) { sys.print(greenStr(".")); } function greenDot() { sys.print(greenStr(".")); }
function redF(str) { sys.print(redStr("F")); } function redF() { sys.print(redStr("F")); }
function newline(str) { sys.print("\n"); } function newline() { sys.print("\n"); }
function lineEnder(columnsPerLine) {
var columnsSoFar = 0;
return function() {
columnsSoFar += 1;
if (columnsSoFar == columnsPerLine) {
newline();
columnsSoFar = 0;
}
};
}
var startNewLineIfNecessary = lineEnder(defaultColumnsPerLine);
this.reportSpecResults = function(spec) { this.reportSpecResults = function(spec) {
if (spec.results().passed()) { if (spec.results().passed()) {
@ -23,6 +39,7 @@ jasmine.TrivialNodeReporter = function(sys) {
} else { } else {
redF(); redF();
} }
startNewLineIfNecessary();
}; };
}; };