newline at 50 characters
This commit is contained in:
parent
dccafe33b0
commit
8fbf3ba859
@ -11,6 +11,31 @@ describe("TrivialNodeReporter", function() {
|
||||
|
||||
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() {
|
||||
this.fakeSys = (function(){
|
||||
var output = "";
|
||||
@ -49,13 +74,7 @@ describe("TrivialNodeReporter", function() {
|
||||
describe('A Test Run', function(){
|
||||
|
||||
describe('A spec runs', function(){
|
||||
|
||||
it("prints a green dot if the spec passes", function(){
|
||||
var passingSpec = {
|
||||
results: function(){
|
||||
return {passed:function(){return true;}};
|
||||
}
|
||||
};
|
||||
this.reporter.reportSpecResults(passingSpec);
|
||||
|
||||
expect(this.fakeSys.getOutput()).toEqual(
|
||||
@ -75,7 +94,30 @@ describe("TrivialNodeReporter", function() {
|
||||
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("."));
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -7,15 +7,31 @@ jasmine.TrivialNodeReporter = function(sys) {
|
||||
none: '\033[0m'
|
||||
};
|
||||
|
||||
var defaultColumnsPerLine = 50;
|
||||
|
||||
function coloredStr(color, str) { return ansi[color] + str + ansi.none; }
|
||||
|
||||
function greenStr(str) { return coloredStr("green", str); }
|
||||
function redStr(str) { return coloredStr("red", str); }
|
||||
function yellowStr(str) { return coloredStr("yellow", str); }
|
||||
|
||||
function greenDot(str) { sys.print(greenStr(".")); }
|
||||
function redF(str) { sys.print(redStr("F")); }
|
||||
function newline(str) { sys.print("\n"); }
|
||||
function greenDot() { sys.print(greenStr(".")); }
|
||||
function redF() { sys.print(redStr("F")); }
|
||||
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) {
|
||||
if (spec.results().passed()) {
|
||||
@ -23,6 +39,7 @@ jasmine.TrivialNodeReporter = function(sys) {
|
||||
} else {
|
||||
redF();
|
||||
}
|
||||
startNewLineIfNecessary();
|
||||
};
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user