integration test - failure scenario

This commit is contained in:
Steve Conover 2011-02-28 22:30:03 -08:00
parent e42026ee84
commit b9cbd3c5a0
2 changed files with 82 additions and 3 deletions

View File

@ -51,7 +51,7 @@ describe("TrivialConsoleReporter", function() {
});
describe('Integration test', function(){
describe('Integration', function(){
it("prints the proper output under a pass scenario. small numbers.", function(){
simulateRun(this.reporter,
repeat(passingSpec, 3),
@ -121,6 +121,70 @@ describe("TrivialConsoleReporter", function() {
].join("\n") + "\n"
);
});
it("prints the proper output under a failure scenario.", function(){
simulateRun(this.reporter,
[failingSpec, passingSpec, failingSpec],
[{description:"The oven",
results:function(){
return {
items_:[
{failedCount:2,
description:"heats up",
items_:[
{trace:{stack:"stack trace one\n second line"}},
{trace:{stack:"stack trace two"}}
]}
]
};
}},
{description:"The washing machine",
results:function(){
return {
items_:[
{failedCount:2,
description:"washes clothes",
items_:[
{trace:{stack:"stack trace one"}}
]}
]
};
}}
],
{
results:function(){
return {
specs: function(){return [null, null, null];},
totalCount: 7,
failedCount: 2
};
}
},
1000,
1777);
expect(this.out.getOutput()).toEqual(
[
"Started",
red("F") + green(".") + red("F"),
"",
"The oven heats up",
" stack trace one",
" second line",
" stack trace two",
"",
"The washing machine washes clothes",
" stack trace one",
"",
"Finished in 0.777 seconds",
red("3 specs, 7 assertions, 2 failures"),
""
].join("\n") + "\n"
);
});
});
describe('A Test Run', function(){

View File

@ -30,17 +30,30 @@ jasmine.TrivialConsoleReporter = function(print) {
function plural(str, count) { return count == 1 ? str : str + "s"; }
function repeat(thing, times) { var arr = [];
for(var i=0; i<times; i++) arr.push(thing);
return arr;
}
function indent(str, spaces) { var lines = str.split("\n");
var newArr = []
for(var i=0; i<lines.length; i++) {
newArr.push(repeat(" ", spaces).join("") + lines[i])
}
return newArr.join("\n")
}
function specFailureDetails(suiteDescription, specDescription, stackTraces) {
newline();
print(suiteDescription + " " + specDescription);
newline();
for(var i=0; i<stackTraces.length; i++) {
print(stackTraces[i]);
print(indent(stackTraces[i], 2));
newline();
}
}
function finished(elapsed) { newline();
newline();
print("Finished in " + elapsed/1000 + " seconds"); }
function summary(colorF, specs, assertions, failed) { newline();
print(colorF(specs + " " + plural(language.spec, specs) + ", " +
@ -120,6 +133,8 @@ jasmine.TrivialConsoleReporter = function(print) {
}
this.reportRunnerResults = function(runner) {
newline();
eachSpecFailure(this.suiteResults, function(suiteDescription, specDescription, stackTraces) {
specFailureDetails(suiteDescription, specDescription, stackTraces);
});