129 lines
3.3 KiB
JavaScript
129 lines
3.3 KiB
JavaScript
getJasmineRequireObj().Spec = function(j$) {
|
|
function Spec(attrs) {
|
|
this.expectationFactory = attrs.expectationFactory;
|
|
this.resultCallback = attrs.resultCallback || function() {};
|
|
this.id = attrs.id;
|
|
this.description = attrs.description || '';
|
|
this.queueableFn = attrs.queueableFn;
|
|
this.beforeFns = attrs.beforeFns || function() { return []; };
|
|
this.afterFns = attrs.afterFns || function() { return []; };
|
|
this.userContext = attrs.userContext || function() { return {}; };
|
|
this.onStart = attrs.onStart || function() {};
|
|
this.exceptionFormatter = attrs.exceptionFormatter || function() {};
|
|
this.getSpecName = attrs.getSpecName || function() { return ''; };
|
|
this.expectationResultFactory = attrs.expectationResultFactory || function() { };
|
|
this.queueRunnerFactory = attrs.queueRunnerFactory || function() {};
|
|
this.catchingExceptions = attrs.catchingExceptions || function() { return true; };
|
|
|
|
if (!this.queueableFn.fn) {
|
|
this.pend();
|
|
}
|
|
|
|
this.result = {
|
|
id: this.id,
|
|
description: this.description,
|
|
fullName: this.getFullName(),
|
|
failedExpectations: []
|
|
};
|
|
}
|
|
|
|
Spec.prototype.addExpectationResult = function(passed, data) {
|
|
if (passed) {
|
|
return;
|
|
}
|
|
this.result.failedExpectations.push(this.expectationResultFactory(data));
|
|
};
|
|
|
|
Spec.prototype.expect = function(actual) {
|
|
return this.expectationFactory(actual, this);
|
|
};
|
|
|
|
Spec.prototype.execute = function(onComplete) {
|
|
var self = this;
|
|
|
|
this.onStart(this);
|
|
|
|
if (this.markedPending || this.disabled) {
|
|
complete();
|
|
return;
|
|
}
|
|
|
|
var allFns = this.beforeFns().concat(this.queueableFn).concat(this.afterFns());
|
|
|
|
this.queueRunnerFactory({
|
|
queueableFns: allFns,
|
|
onException: function() { self.onException.apply(self, arguments); },
|
|
onComplete: complete,
|
|
userContext: this.userContext()
|
|
});
|
|
|
|
function complete() {
|
|
self.result.status = self.status();
|
|
self.resultCallback(self.result);
|
|
|
|
if (onComplete) {
|
|
onComplete();
|
|
}
|
|
}
|
|
};
|
|
|
|
Spec.prototype.onException = function onException(e) {
|
|
if (Spec.isPendingSpecException(e)) {
|
|
this.pend();
|
|
return;
|
|
}
|
|
|
|
this.addExpectationResult(false, {
|
|
matcherName: '',
|
|
passed: false,
|
|
expected: '',
|
|
actual: '',
|
|
error: e
|
|
});
|
|
};
|
|
|
|
Spec.prototype.disable = function() {
|
|
this.disabled = true;
|
|
};
|
|
|
|
Spec.prototype.pend = function() {
|
|
this.markedPending = true;
|
|
};
|
|
|
|
Spec.prototype.status = function() {
|
|
if (this.disabled) {
|
|
return 'disabled';
|
|
}
|
|
|
|
if (this.markedPending) {
|
|
return 'pending';
|
|
}
|
|
|
|
if (this.result.failedExpectations.length > 0) {
|
|
return 'failed';
|
|
} else {
|
|
return 'passed';
|
|
}
|
|
};
|
|
|
|
Spec.prototype.isExecutable = function() {
|
|
return !this.disabled && !this.markedPending;
|
|
};
|
|
|
|
Spec.prototype.getFullName = function() {
|
|
return this.getSpecName(this);
|
|
};
|
|
|
|
Spec.pendingSpecExceptionMessage = '=> marked Pending';
|
|
|
|
Spec.isPendingSpecException = function(e) {
|
|
return !!(e && e.toString && e.toString().indexOf(Spec.pendingSpecExceptionMessage) !== -1);
|
|
};
|
|
|
|
return Spec;
|
|
};
|
|
|
|
if (typeof window == void 0 && typeof exports == 'object') {
|
|
exports.Spec = jasmineRequire.Spec;
|
|
}
|