better handling of nested suites

This commit is contained in:
John Bintz 2011-06-08 13:28:18 -04:00
parent 825a9a1278
commit c68ae4b144
4 changed files with 27 additions and 7 deletions

View File

@ -1917,7 +1917,7 @@ jasmine.Spec = function(env, suite, description) {
}; };
jasmine.Spec.prototype.getFullName = function() { jasmine.Spec.prototype.getFullName = function() {
var description = (this.description.apply ? this.description.name : this.description); var description = (typeof this.description == 'function' || this.description instanceof Function) ? this.description.name : this.description;
return this.suite.getFullName() + ' ' + description + '.'; return this.suite.getFullName() + ' ' + description + '.';
}; };
@ -2154,13 +2154,17 @@ jasmine.Suite = function(env, description, specDefinitions, parentSuite) {
}; };
jasmine.Suite.prototype.getFullName = function() { jasmine.Suite.prototype.getFullName = function() {
var fullName = (this.description.apply ? this.description.name : this.description); var fullName = this.getDescription()
for (var parentSuite = this.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) { for (var parentSuite = this.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) {
fullName = parentSuite.description + ' ' + fullName; fullName = parentSuite.getDescription() + ' ' + fullName;
} }
return fullName; return fullName;
}; };
jasmine.Suite.prototype.getDescription = function() {
return (typeof this.description == 'function' || this.description instanceof Function) ? this.description.name : this.description;
};
jasmine.Suite.prototype.finish = function(onComplete) { jasmine.Suite.prototype.finish = function(onComplete) {
this.env.reporter.reportSuiteResults(this); this.env.reporter.reportSuiteResults(this);
this.finished = true; this.finished = true;
@ -2469,5 +2473,5 @@ jasmine.version_= {
"major": 1, "major": 1,
"minor": 1, "minor": 1,
"build": 0, "build": 0,
"revision": 1307455841 "revision": 1307554069
}; };

View File

@ -80,6 +80,18 @@ describe('Suite', function() {
expect(suite.getFullName()).toEqual("MyClass"); expect(suite.getFullName()).toEqual("MyClass");
expect(suite.children()[0].getFullName()).toEqual("MyClass should be something."); expect(suite.children()[0].getFullName()).toEqual("MyClass should be something.");
}); });
it('should use the name of the parent suite correctly', function() {
suite = env.describe(MyClass, function() {
env.describe('nested', function() {
env.it('should be something', function() {
});
});
});
expect(suite.getFullName()).toEqual("MyClass");
expect(suite.suites()[0].getFullName()).toEqual("MyClass nested");
});
}); });
}); });

View File

@ -29,7 +29,7 @@ jasmine.Spec = function(env, suite, description) {
}; };
jasmine.Spec.prototype.getFullName = function() { jasmine.Spec.prototype.getFullName = function() {
var description = (this.description.apply ? this.description.name : this.description); var description = (typeof this.description == 'function' || this.description instanceof Function) ? this.description.name : this.description;
return this.suite.getFullName() + ' ' + description + '.'; return this.suite.getFullName() + ' ' + description + '.';
}; };

View File

@ -22,13 +22,17 @@ jasmine.Suite = function(env, description, specDefinitions, parentSuite) {
}; };
jasmine.Suite.prototype.getFullName = function() { jasmine.Suite.prototype.getFullName = function() {
var fullName = (this.description.apply ? this.description.name : this.description); var fullName = this.getDescription()
for (var parentSuite = this.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) { for (var parentSuite = this.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) {
fullName = parentSuite.description + ' ' + fullName; fullName = parentSuite.getDescription() + ' ' + fullName;
} }
return fullName; return fullName;
}; };
jasmine.Suite.prototype.getDescription = function() {
return (typeof this.description == 'function' || this.description instanceof Function) ? this.description.name : this.description;
};
jasmine.Suite.prototype.finish = function(onComplete) { jasmine.Suite.prototype.finish = function(onComplete) {
this.env.reporter.reportSuiteResults(this); this.env.reporter.reportSuiteResults(this);
this.finished = true; this.finished = true;