Refactored TrivialReporter to handle duplicate suite names properly

This commit is contained in:
Lee Byrd & Christian Williams 2010-06-22 17:25:08 -07:00
parent 1154fcaf3b
commit 0539251fe6
2 changed files with 41 additions and 11 deletions

View File

@ -58,10 +58,10 @@ jasmine.TrivialReporter.prototype.reportRunnerStarting = function(runner) {
var suiteDiv = this.createDom('div', { className: 'suite' }, var suiteDiv = this.createDom('div', { className: 'suite' },
this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, "run"), this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, "run"),
this.createDom('a', { className: 'description', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, suite.description)); this.createDom('a', { className: 'description', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, suite.description));
this.suiteDivs[suite.getFullName()] = suiteDiv; this.suiteDivs[suite.id] = suiteDiv;
var parentDiv = this.outerDiv; var parentDiv = this.outerDiv;
if (suite.parentSuite) { if (suite.parentSuite) {
parentDiv = this.suiteDivs[suite.parentSuite.getFullName()]; parentDiv = this.suiteDivs[suite.parentSuite.id];
} }
parentDiv.appendChild(suiteDiv); parentDiv.appendChild(suiteDiv);
} }
@ -112,7 +112,7 @@ jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) {
if (results.totalCount == 0) { // todo: change this to check results.skipped if (results.totalCount == 0) { // todo: change this to check results.skipped
status = 'skipped'; status = 'skipped';
} }
this.suiteDivs[suite.getFullName()].className += " " + status; this.suiteDivs[suite.id].className += " " + status;
}; };
jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) { jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
@ -150,7 +150,7 @@ jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
specDiv.appendChild(messagesDiv); specDiv.appendChild(messagesDiv);
} }
this.suiteDivs[spec.suite.getFullName()].appendChild(specDiv); this.suiteDivs[spec.suite.id].appendChild(specDiv);
}; };
jasmine.TrivialReporter.prototype.log = function() { jasmine.TrivialReporter.prototype.log = function() {

View File

@ -108,12 +108,10 @@ describe("TrivialReporter", function() {
getItems: function() { getItems: function() {
}}; }};
var suite1 = new jasmine.Suite(env, "suite 1", null, null);
spec = { spec = {
suite: { suite: suite1,
getFullName: function() {
return "suite 1";
}
},
getFullName: function() { getFullName: function() {
return "foo"; return "foo";
}, },
@ -125,7 +123,7 @@ describe("TrivialReporter", function() {
trivialReporter.reportRunnerStarting({ trivialReporter.reportRunnerStarting({
env: env, env: env,
suites: function() { suites: function() {
return [ new jasmine.Suite({}, "suite 1", null, null) ]; return [ suite1 ];
} }
}); });
}); });
@ -134,7 +132,7 @@ describe("TrivialReporter", function() {
expectationResult = new jasmine.ExpectationResult({ expectationResult = new jasmine.ExpectationResult({
matcherName: "toBeNull", passed: false, message: "Expected 'a' to be null, but it was not" matcherName: "toBeNull", passed: false, message: "Expected 'a' to be null, but it was not"
}); });
spyOn(results, 'getItems').andReturn([expectationResult]); spyOn(results, 'getItems').andReturn([expectationResult]);
trivialReporter.reportSpecResults(spec); trivialReporter.reportSpecResults(spec);
@ -175,4 +173,36 @@ describe("TrivialReporter", function() {
expect(errorDiv.innerHTML).toEqual("this is a multipart log message"); expect(errorDiv.innerHTML).toEqual("this is a multipart log message");
}); });
}); });
describe("duplicate example names", function() {
it("should report failures correctly", function() {
var suite1 = env.describe("suite", function() {
env.it("will have log messages", function() {
this.log("this one fails!");
this.expect(true).toBeFalsy();
});
});
var suite2 = env.describe("suite", function() {
env.it("will have log messages", function() {
this.log("this one passes!");
this.expect(true).toBeTruthy();
});
});
env.addReporter(trivialReporter);
env.execute();
var divs = body.getElementsByTagName("div");
var passedSpecDiv = findElement(divs, 'suite passed');
expect(passedSpecDiv.className).toEqual('suite passed');
expect(passedSpecDiv.innerHTML).toContain("this one passes!");
expect(passedSpecDiv.innerHTML).not.toContain("this one fails!");
var failedSpecDiv = findElement(divs, 'suite failed');
expect(failedSpecDiv.className).toEqual('suite failed');
expect(failedSpecDiv.innerHTML).toContain("this one fails!");
expect(failedSpecDiv.innerHTML).not.toContain("this one passes!");
});
});
}); });