Refactor Spec block execution into Queue

This commit is contained in:
ragaskar
2009-08-01 14:56:29 -07:00
parent d5489a3e0d
commit f73fd8ae95
5 changed files with 97 additions and 134 deletions

29
src/Queue.js Normal file
View File

@@ -0,0 +1,29 @@
jasmine.Queue = function() {
this.blocks = [];
};
jasmine.Queue.prototype.add = function(block) {
this.setNextOnLastInQueue(block);
this.blocks.push(block);
};
jasmine.Queue.prototype.start = function(onComplete) {
if (this.blocks[0]) {
this.blocks[0].execute();
} else {
onComplete();
}
};
/**
* @private
*/
jasmine.Queue.prototype.setNextOnLastInQueue = function (block) {
if (this.blocks.length > 0) {
var previousBlock = this.blocks[this.blocks.length - 1];
previousBlock.next = function() {
block.execute();
};
}
};