Major refactoring of Spec. Moved QueuedFunction to Block, WaitsBlock and WaitsForBlock. Waits and WaitsFor blocks now sequentially stackable

This commit is contained in:
ragaskar
2009-07-29 22:27:11 -07:00
parent 708d148d31
commit a1a278ee69
10 changed files with 912 additions and 754 deletions

38
src/WaitsForBlock.js Normal file
View File

@@ -0,0 +1,38 @@
jasmine.WaitsForBlock = function(env, timeout, latchFunction, message, spec) {
this.timeout = timeout;
this.latchFunction = latchFunction;
this.message = message;
this.totalTimeSpentWaitingForLatch = 0;
jasmine.Block.call(this, env, null, spec);
};
jasmine.util.inherit(jasmine.WaitsForBlock, jasmine.Block);
jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 100;
jasmine.WaitsForBlock.prototype.execute = function () {
var self = this;
self.env.reporter.log('>> Jasmine waiting for ' + (self.message || 'something to happen'));
var latchFunctionResult;
try {
latchFunctionResult = self.latchFunction.apply(self.spec);
} catch (e) {
self.fail(e);
self.next();
return;
}
if (latchFunctionResult) {
self.next();
} else if (self.totalTimeSpentWaitingForLatch >= self.timeout) {
var message = 'timed out after ' + self.timeout + ' msec waiting for ' + (self.message || 'something to happen');
self.fail({
name: 'timeout',
message: message
});
self.spec.next();
} else {
self.totalTimeSpentWaitingForLatch += jasmine.WaitsForBlock.TIMEOUT_INCREMENT;
self.env.setTimeout(function () { self.execute(); }, jasmine.WaitsForBlock.TIMEOUT_INCREMENT);
}
};