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' },
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.suiteDivs[suite.getFullName()] = suiteDiv;
this.suiteDivs[suite.id] = suiteDiv;
var parentDiv = this.outerDiv;
if (suite.parentSuite) {
parentDiv = this.suiteDivs[suite.parentSuite.getFullName()];
parentDiv = this.suiteDivs[suite.parentSuite.id];
}
parentDiv.appendChild(suiteDiv);
}
@ -112,7 +112,7 @@ jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) {
if (results.totalCount == 0) { // todo: change this to check results.skipped
status = 'skipped';
}
this.suiteDivs[suite.getFullName()].className += " " + status;
this.suiteDivs[suite.id].className += " " + status;
};
jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
@ -150,7 +150,7 @@ jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
specDiv.appendChild(messagesDiv);
}
this.suiteDivs[spec.suite.getFullName()].appendChild(specDiv);
this.suiteDivs[spec.suite.id].appendChild(specDiv);
};
jasmine.TrivialReporter.prototype.log = function() {

View File

@ -108,12 +108,10 @@ describe("TrivialReporter", function() {
getItems: function() {
}};
var suite1 = new jasmine.Suite(env, "suite 1", null, null);
spec = {
suite: {
getFullName: function() {
return "suite 1";
}
},
suite: suite1,
getFullName: function() {
return "foo";
},
@ -125,7 +123,7 @@ describe("TrivialReporter", function() {
trivialReporter.reportRunnerStarting({
env: env,
suites: function() {
return [ new jasmine.Suite({}, "suite 1", null, null) ];
return [ suite1 ];
}
});
});
@ -134,7 +132,7 @@ describe("TrivialReporter", function() {
expectationResult = new jasmine.ExpectationResult({
matcherName: "toBeNull", passed: false, message: "Expected 'a' to be null, but it was not"
});
spyOn(results, 'getItems').andReturn([expectationResult]);
trivialReporter.reportSpecResults(spec);
@ -175,4 +173,36 @@ describe("TrivialReporter", function() {
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!");
});
});
});