Fix getFullName on spec.
- Fixes specFiltering on nested specs
This commit is contained in:
@@ -593,14 +593,8 @@ jasmine.buildExpectationResult = function(params) {
|
|||||||
|
|
||||||
var specConstructor = jasmine.Spec;
|
var specConstructor = jasmine.Spec;
|
||||||
|
|
||||||
// TODO: this deserves a better name (not a Factory the way others are)
|
var getSpecName = function(spec, currentSuite) {
|
||||||
var fullNameFactory = function(spec, currentSuite) {
|
return currentSuite.getFullName() + ' ' + spec.description + '.';
|
||||||
var descriptions = [];
|
|
||||||
for (var suite = currentSuite; suite; suite = suite.parentSuite) {
|
|
||||||
descriptions.push(suite.description)
|
|
||||||
}
|
|
||||||
descriptions.push(spec.description);
|
|
||||||
return descriptions.join(' ') + '.';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var buildExpectationResult = jasmine.buildExpectationResult;
|
var buildExpectationResult = jasmine.buildExpectationResult;
|
||||||
@@ -616,7 +610,7 @@ jasmine.buildExpectationResult = function(params) {
|
|||||||
expectationFactory: expectationFactory,
|
expectationFactory: expectationFactory,
|
||||||
exceptionFormatter: exceptionFormatter,
|
exceptionFormatter: exceptionFormatter,
|
||||||
resultCallback: specResultCallback,
|
resultCallback: specResultCallback,
|
||||||
fullNameFactory: function(spec) { return fullNameFactory(spec, suite) },
|
getSpecName: function(spec) { return getSpecName(spec, suite) },
|
||||||
startCallback: startCallback,
|
startCallback: startCallback,
|
||||||
description: description,
|
description: description,
|
||||||
catchExceptions: self.catchExceptions,
|
catchExceptions: self.catchExceptions,
|
||||||
@@ -1933,7 +1927,7 @@ jasmine.Spec = function(attrs) {
|
|||||||
this.catchExceptions = attrs.catchExceptions;
|
this.catchExceptions = attrs.catchExceptions;
|
||||||
this.startCallback = attrs.startCallback || function() {};
|
this.startCallback = attrs.startCallback || function() {};
|
||||||
this.exceptionFormatter = attrs.exceptionFormatter || function() {};
|
this.exceptionFormatter = attrs.exceptionFormatter || function() {};
|
||||||
this.fullNameFactory = attrs.fullNameFactory;
|
this.getSpecName = attrs.getSpecName;
|
||||||
this.expectationResultFactory = attrs.expectationResultFactory || function() {};
|
this.expectationResultFactory = attrs.expectationResultFactory || function() {};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -2013,9 +2007,8 @@ jasmine.Spec.prototype.status = function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//TODO: remove
|
|
||||||
jasmine.Spec.prototype.getFullName = function() {
|
jasmine.Spec.prototype.getFullName = function() {
|
||||||
return this.fullNameFactory(this);
|
return this.getSpecName(this);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Internal representation of a Jasmine suite.
|
* Internal representation of a Jasmine suite.
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
describe("Clock", function() {
|
describe("Clock", function() {
|
||||||
|
|
||||||
// TODO: fullName/SpecFilter is broken, so don't nest describes you want to filter
|
|
||||||
|
|
||||||
it("calls the global setTimeout directly if Clock is not installed", function() {
|
it("calls the global setTimeout directly if Clock is not installed", function() {
|
||||||
var setTimeout = jasmine.createSpy('setTimeout'),
|
var setTimeout = jasmine.createSpy('setTimeout'),
|
||||||
delayedFunctionScheduler = jasmine.createSpyObj('delayedFunctionScheduler', ['scheduleFunction']),
|
delayedFunctionScheduler = jasmine.createSpyObj('delayedFunctionScheduler', ['scheduleFunction']),
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ describe("jasmine.Env", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("jasmine Env", function() {
|
describe("jasmine Env (integration)", function() {
|
||||||
|
|
||||||
it("Mock clock can be installed and used in tests", function() {
|
it("Mock clock can be installed and used in tests", function() {
|
||||||
var setTimeout = jasmine.createSpy('setTimeout'),
|
var setTimeout = jasmine.createSpy('setTimeout'),
|
||||||
@@ -186,4 +186,28 @@ describe("jasmine Env", function() {
|
|||||||
expect(setTimeout).toHaveBeenCalledWith(globalTimeoutFn, 100);
|
expect(setTimeout).toHaveBeenCalledWith(globalTimeoutFn, 100);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should be possible to get full name from a spec", function() {
|
||||||
|
var env = new jasmine.Env({global: { setTimeout: setTimeout }}),
|
||||||
|
topLevelSpec, nestedSpec, doublyNestedSpec;
|
||||||
|
|
||||||
|
env.describe("my tests", function() {
|
||||||
|
topLevelSpec = env.it("are sometimes top level", function() {
|
||||||
|
});
|
||||||
|
env.describe("are sometimes", function() {
|
||||||
|
nestedSpec = env.it("singly nested", function() {
|
||||||
|
|
||||||
|
});
|
||||||
|
env.describe("even", function() {
|
||||||
|
doublyNestedSpec = env.it("doubly nested", function() {
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
env.execute();
|
||||||
|
expect(topLevelSpec.getFullName()).toBe("my tests are sometimes top level.");
|
||||||
|
expect(nestedSpec.getFullName()).toBe("my tests are sometimes singly nested.");
|
||||||
|
expect(doublyNestedSpec.getFullName()).toBe("my tests are sometimes even doubly nested.");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -166,10 +166,8 @@ describe("Spec (real-ish unit tests)", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("can return its full name", function() {
|
it("can return its full name", function() {
|
||||||
//TODO: not convinced that a spec should provide this as part of its public interface, but adding temporarily
|
|
||||||
//until we fix the reporting
|
|
||||||
var spec = new jasmine.Spec({
|
var spec = new jasmine.Spec({
|
||||||
fullNameFactory: function(passedVal) {
|
getSpecName: function(passedVal) {
|
||||||
expect(passedVal).toBe(spec);
|
expect(passedVal).toBe(spec);
|
||||||
return 'expected val';
|
return 'expected val';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,14 +78,8 @@
|
|||||||
|
|
||||||
var specConstructor = jasmine.Spec;
|
var specConstructor = jasmine.Spec;
|
||||||
|
|
||||||
// TODO: this deserves a better name (not a Factory the way others are)
|
var getSpecName = function(spec, currentSuite) {
|
||||||
var fullNameFactory = function(spec, currentSuite) {
|
return currentSuite.getFullName() + ' ' + spec.description + '.';
|
||||||
var descriptions = [];
|
|
||||||
for (var suite = currentSuite; suite; suite = suite.parentSuite) {
|
|
||||||
descriptions.push(suite.description)
|
|
||||||
}
|
|
||||||
descriptions.push(spec.description);
|
|
||||||
return descriptions.join(' ') + '.';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var buildExpectationResult = jasmine.buildExpectationResult;
|
var buildExpectationResult = jasmine.buildExpectationResult;
|
||||||
@@ -101,7 +95,7 @@
|
|||||||
expectationFactory: expectationFactory,
|
expectationFactory: expectationFactory,
|
||||||
exceptionFormatter: exceptionFormatter,
|
exceptionFormatter: exceptionFormatter,
|
||||||
resultCallback: specResultCallback,
|
resultCallback: specResultCallback,
|
||||||
fullNameFactory: function(spec) { return fullNameFactory(spec, suite) },
|
getSpecName: function(spec) { return getSpecName(spec, suite) },
|
||||||
startCallback: startCallback,
|
startCallback: startCallback,
|
||||||
description: description,
|
description: description,
|
||||||
catchExceptions: self.catchExceptions,
|
catchExceptions: self.catchExceptions,
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ jasmine.Spec = function(attrs) {
|
|||||||
this.catchExceptions = attrs.catchExceptions;
|
this.catchExceptions = attrs.catchExceptions;
|
||||||
this.startCallback = attrs.startCallback || function() {};
|
this.startCallback = attrs.startCallback || function() {};
|
||||||
this.exceptionFormatter = attrs.exceptionFormatter || function() {};
|
this.exceptionFormatter = attrs.exceptionFormatter || function() {};
|
||||||
this.fullNameFactory = attrs.fullNameFactory;
|
this.getSpecName = attrs.getSpecName;
|
||||||
this.expectationResultFactory = attrs.expectationResultFactory || function() {};
|
this.expectationResultFactory = attrs.expectationResultFactory || function() {};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -91,7 +91,6 @@ jasmine.Spec.prototype.status = function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//TODO: remove
|
|
||||||
jasmine.Spec.prototype.getFullName = function() {
|
jasmine.Spec.prototype.getFullName = function() {
|
||||||
return this.fullNameFactory(this);
|
return this.getSpecName(this);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user