Squashed commit of work to make Jasmine a collection of isolated modules. Note now that in our test suite, "jasmine" now always refers to the build jasmine loaded from jasmine.js and "j$" always refers to the code in the src directories.
Also, dev_boot.js is now a copy of boot.js and has additional changes to load jasmine the second time, into the j$ reference.
This commit is contained in:
228
src/core/Spec.js
228
src/core/Spec.js
@@ -1,118 +1,126 @@
|
||||
jasmine.Spec = function(attrs) {
|
||||
this.encounteredExpectations = false;
|
||||
this.expectationFactory = attrs.expectationFactory;
|
||||
this.resultCallback = attrs.resultCallback || function() {};
|
||||
this.id = attrs.id;
|
||||
this.description = attrs.description || '';
|
||||
this.fn = attrs.fn;
|
||||
this.beforeFns = attrs.beforeFns || function() {};
|
||||
this.afterFns = attrs.afterFns || function() {};
|
||||
this.catchingExceptions = attrs.catchingExceptions;
|
||||
this.onStart = attrs.onStart || function() {};
|
||||
this.exceptionFormatter = attrs.exceptionFormatter || function() {};
|
||||
this.getSpecName = attrs.getSpecName || function() { return ''; };
|
||||
this.expectationResultFactory = attrs.expectationResultFactory || function() { };
|
||||
this.queueRunner = attrs.queueRunner || function() {};
|
||||
this.catchingExceptions = attrs.catchingExceptions || function() { return true; };
|
||||
getJasmineRequireObj().Spec = function() {
|
||||
function Spec(attrs) {
|
||||
this.encounteredExpectations = false;
|
||||
this.expectationFactory = attrs.expectationFactory;
|
||||
this.resultCallback = attrs.resultCallback || function() {};
|
||||
this.id = attrs.id;
|
||||
this.description = attrs.description || '';
|
||||
this.fn = attrs.fn;
|
||||
this.beforeFns = attrs.beforeFns || function() {};
|
||||
this.afterFns = attrs.afterFns || function() {};
|
||||
this.catchingExceptions = attrs.catchingExceptions;
|
||||
this.onStart = attrs.onStart || function() {};
|
||||
this.exceptionFormatter = attrs.exceptionFormatter || function() {};
|
||||
this.getSpecName = attrs.getSpecName || function() { return ''; };
|
||||
this.expectationResultFactory = attrs.expectationResultFactory || function() { };
|
||||
this.queueRunner = attrs.queueRunner || function() {};
|
||||
this.catchingExceptions = attrs.catchingExceptions || function() { return true; };
|
||||
|
||||
if (!this.fn) {
|
||||
this.pend();
|
||||
}
|
||||
|
||||
this.result = {
|
||||
id: this.id,
|
||||
description: this.description,
|
||||
fullName: this.getFullName(),
|
||||
status: this.status(),
|
||||
failedExpectations: []
|
||||
};
|
||||
};
|
||||
|
||||
jasmine.Spec.prototype.addExpectationResult = function(passed, data) {
|
||||
this.encounteredExpectations = true;
|
||||
if (passed) {
|
||||
return;
|
||||
}
|
||||
this.result.failedExpectations.push(this.expectationResultFactory(data));
|
||||
};
|
||||
|
||||
jasmine.Spec.prototype.expect = function(actual) {
|
||||
return this.expectationFactory(actual, this);
|
||||
};
|
||||
|
||||
jasmine.Spec.prototype.execute = function(onComplete) {
|
||||
var self = this;
|
||||
|
||||
this.onStart(this);
|
||||
|
||||
if (this.markedPending || this.disabled) {
|
||||
complete();
|
||||
return;
|
||||
}
|
||||
|
||||
var befores = this.beforeFns() || [],
|
||||
afters = this.afterFns() || [];
|
||||
var allFns = befores.concat(this.fn).concat(afters);
|
||||
|
||||
this.queueRunner({
|
||||
fns: allFns,
|
||||
onException: function(e) {
|
||||
if (jasmine.Spec.isPendingSpecException(e)) {
|
||||
self.pend();
|
||||
return;
|
||||
}
|
||||
|
||||
self.addExpectationResult(false, {
|
||||
matcherName: "",
|
||||
passed: false,
|
||||
expected: "",
|
||||
actual: "",
|
||||
error: e
|
||||
});
|
||||
},
|
||||
onComplete: complete
|
||||
});
|
||||
|
||||
function complete() {
|
||||
self.result.status = self.status();
|
||||
self.resultCallback(self.result);
|
||||
|
||||
if (onComplete) {
|
||||
onComplete();
|
||||
if (!this.fn) {
|
||||
this.pend();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
jasmine.Spec.prototype.disable = function() {
|
||||
this.disabled = true;
|
||||
};
|
||||
|
||||
jasmine.Spec.prototype.pend = function() {
|
||||
this.markedPending = true;
|
||||
};
|
||||
|
||||
jasmine.Spec.prototype.status = function() {
|
||||
if (this.disabled) {
|
||||
return 'disabled';
|
||||
this.result = {
|
||||
id: this.id,
|
||||
description: this.description,
|
||||
fullName: this.getFullName(),
|
||||
status: this.status(),
|
||||
failedExpectations: []
|
||||
};
|
||||
}
|
||||
|
||||
if (this.markedPending || !this.encounteredExpectations) {
|
||||
return 'pending';
|
||||
}
|
||||
Spec.prototype.addExpectationResult = function(passed, data) {
|
||||
this.encounteredExpectations = true;
|
||||
if (passed) {
|
||||
return;
|
||||
}
|
||||
this.result.failedExpectations.push(this.expectationResultFactory(data));
|
||||
};
|
||||
|
||||
if (this.result.failedExpectations.length > 0) {
|
||||
return 'failed';
|
||||
} else {
|
||||
return 'passed';
|
||||
}
|
||||
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 befores = this.beforeFns() || [],
|
||||
afters = this.afterFns() || [];
|
||||
var allFns = befores.concat(this.fn).concat(afters);
|
||||
|
||||
this.queueRunner({
|
||||
fns: allFns,
|
||||
onException: function(e) {
|
||||
if (Spec.isPendingSpecException(e)) {
|
||||
self.pend();
|
||||
return;
|
||||
}
|
||||
|
||||
self.addExpectationResult(false, {
|
||||
matcherName: "",
|
||||
passed: false,
|
||||
expected: "",
|
||||
actual: "",
|
||||
error: e
|
||||
});
|
||||
},
|
||||
onComplete: complete
|
||||
});
|
||||
|
||||
function complete() {
|
||||
self.result.status = self.status();
|
||||
self.resultCallback(self.result);
|
||||
|
||||
if (onComplete) {
|
||||
onComplete();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
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 || !this.encounteredExpectations) {
|
||||
return 'pending';
|
||||
}
|
||||
|
||||
if (this.result.failedExpectations.length > 0) {
|
||||
return 'failed';
|
||||
} else {
|
||||
return 'passed';
|
||||
}
|
||||
};
|
||||
|
||||
Spec.prototype.getFullName = function() {
|
||||
return this.getSpecName(this);
|
||||
};
|
||||
|
||||
Spec.pendingSpecExceptionMessage = "=> marked Pending";
|
||||
|
||||
Spec.isPendingSpecException = function(e) {
|
||||
return e.toString().indexOf(Spec.pendingSpecExceptionMessage) !== -1;
|
||||
};
|
||||
|
||||
return Spec;
|
||||
};
|
||||
|
||||
jasmine.Spec.prototype.getFullName = function() {
|
||||
return this.getSpecName(this);
|
||||
};
|
||||
|
||||
jasmine.Spec.pendingSpecExceptionMessage = "=> marked Pending";
|
||||
|
||||
jasmine.Spec.isPendingSpecException = function(e) {
|
||||
return e.toString().indexOf(jasmine.Spec.pendingSpecExceptionMessage) !== -1;
|
||||
};
|
||||
if (typeof window == void 0 && typeof exports == "object") {
|
||||
exports.Spec = jasmineRequire.Spec;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user