diff --git a/spec/runner.html b/spec/runner.html index 7ce2e7f..18b801e 100644 --- a/spec/runner.html +++ b/spec/runner.html @@ -29,6 +29,7 @@ + @@ -50,6 +51,7 @@ + diff --git a/spec/suites/TrivialNodeReporterSpec.js b/spec/suites/TrivialNodeReporterSpec.js new file mode 100644 index 0000000..4935ec1 --- /dev/null +++ b/spec/suites/TrivialNodeReporterSpec.js @@ -0,0 +1,70 @@ +describe("TrivialNodeReporter", function() { + + + var green = function(str) { + return '\033[32m' + str + '\033[0m'; //keep these literal. otherwise the test loses value as a test. + }; + + var red = function(str) { + return '\033[31m' + str + '\033[0m'; + }; + + var newline = "\n"; + + beforeEach(function() { + this.fakeSys = (function(){ + var output = ""; + return { + puts:function(str) {output += str + "\n";}, + print:function(str) {output += str;}, + getOutput:function(){return output;} + }; + })(); + + this.env = new jasmine.Env(); + this.env.updateInterval = 0; + + this.reporter = new jasmine.TrivialNodeReporter(this.fakeSys); + }); + + // reportSpecResults: function(spec) { + // var result = spec.results(); + // var msg = ''; + // if (result.passed()) + // { + // msg = (colors) ? (ansi.green + '.' + ansi.none) : '.'; + // // } else if (result.skipped) { TODO: Research why "result.skipped" returns false when "xit" is called on a spec? + // // msg = (colors) ? (ansi.yellow + '*' + ansi.none) : '*'; + // } else { + // msg = (colors) ? (ansi.red + 'F' + ansi.none) : 'F'; + // } + // sys.print(msg); + // if (columnCounter++ < 50) return; + // columnCounter = 0; + // sys.print('\n'); + // }, + + + + 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( + green(".") + ); + }); + + }); + + }); + +}); \ No newline at end of file diff --git a/src/node/TrivialNodeReporter.js b/src/node/TrivialNodeReporter.js new file mode 100644 index 0000000..273f1b0 --- /dev/null +++ b/src/node/TrivialNodeReporter.js @@ -0,0 +1,45 @@ +jasmine.TrivialNodeReporter = function(sys) { + this.sys = sys; + + this.ansi = { + green: '\033[32m', + red: '\033[31m', + yellow: '\033[33m', + none: '\033[0m' + }; +}; + +// reportSpecResults: function(spec) { +// var result = spec.results(); +// var msg = ''; +// if (result.passed()) +// { +// msg = (colors) ? (ansi.green + '.' + ansi.none) : '.'; +// // } else if (result.skipped) { TODO: Research why "result.skipped" returns false when "xit" is called on a spec? +// // msg = (colors) ? (ansi.yellow + '*' + ansi.none) : '*'; +// } else { +// msg = (colors) ? (ansi.red + 'F' + ansi.none) : 'F'; +// } +// sys.print(msg); +// if (columnCounter++ < 50) return; +// columnCounter = 0; +// sys.print('\n'); +// }, + + +jasmine.TrivialNodeReporter.prototype._coloredStr = function(color, str) { + return this.ansi[color] + str + this.ansi.none; +}; + +jasmine.TrivialNodeReporter.prototype._greenStr = function(str) { return this._coloredStr("green", str); }; +jasmine.TrivialNodeReporter.prototype._redStr = function(str) { return this._coloredStr("red", str); }; +jasmine.TrivialNodeReporter.prototype._yellowStr = function(str) { return this._coloredStr("yellow", str); }; + +jasmine.TrivialNodeReporter.prototype._greenDot = function(str) { return this.sys.print(this._greenStr(".")); }; +jasmine.TrivialNodeReporter.prototype._newLine = function(str) { return this.sys.print("\n"); }; + +jasmine.TrivialNodeReporter.prototype.reportSpecResults = function(spec) { + if (spec.results().passed()) this._greenDot(); +}; + +