diff --git a/doc/files.html b/doc/files.html index 191b1e76..5a0987d0 100644 --- a/doc/files.html +++ b/doc/files.html @@ -258,7 +258,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Mon Oct 05 2009 22:35:02 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 13 2009 14:15:02 GMT-0700 (PDT)
\ No newline at end of file diff --git a/doc/index.html b/doc/index.html index c18596ca..dcb08177 100644 --- a/doc/index.html +++ b/doc/index.html @@ -300,7 +300,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Mon Oct 05 2009 22:35:02 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 13 2009 14:15:02 GMT-0700 (PDT)
\ No newline at end of file diff --git a/doc/symbols/_global_.html b/doc/symbols/_global_.html index d1f943c6..886f9ff0 100644 --- a/doc/symbols/_global_.html +++ b/doc/symbols/_global_.html @@ -908,7 +908,7 @@ A convenience method that allows existing specs to be disabled temporarily durin
- Documentation generated by JsDoc Toolkit 2.1.0 on Mon Oct 05 2009 22:35:01 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 13 2009 14:15:02 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Block.html b/doc/symbols/jasmine.Block.html index 516de84a..c667e5c8 100644 --- a/doc/symbols/jasmine.Block.html +++ b/doc/symbols/jasmine.Block.html @@ -339,7 +339,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Mon Oct 05 2009 22:35:01 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 13 2009 14:15:02 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Env.html b/doc/symbols/jasmine.Env.html index 7c915008..33a043ef 100644 --- a/doc/symbols/jasmine.Env.html +++ b/doc/symbols/jasmine.Env.html @@ -507,7 +507,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Mon Oct 05 2009 22:35:01 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 13 2009 14:15:02 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.JsApiReporter.html b/doc/symbols/jasmine.JsApiReporter.html index 8ae2c51e..e8abfda1 100644 --- a/doc/symbols/jasmine.JsApiReporter.html +++ b/doc/symbols/jasmine.JsApiReporter.html @@ -316,7 +316,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Mon Oct 05 2009 22:35:01 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 13 2009 14:15:02 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.MultiReporter.html b/doc/symbols/jasmine.MultiReporter.html index 86f9536c..4216eb51 100644 --- a/doc/symbols/jasmine.MultiReporter.html +++ b/doc/symbols/jasmine.MultiReporter.html @@ -316,7 +316,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Mon Oct 05 2009 22:35:01 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 13 2009 14:15:02 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.NestedResults.html b/doc/symbols/jasmine.NestedResults.html index 886d6dfb..f5883e24 100644 --- a/doc/symbols/jasmine.NestedResults.html +++ b/doc/symbols/jasmine.NestedResults.html @@ -700,7 +700,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Mon Oct 05 2009 22:35:01 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 13 2009 14:15:02 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Reporter.html b/doc/symbols/jasmine.Reporter.html index 7415850a..bdf00470 100644 --- a/doc/symbols/jasmine.Reporter.html +++ b/doc/symbols/jasmine.Reporter.html @@ -316,7 +316,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Mon Oct 05 2009 22:35:01 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 13 2009 14:15:02 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Runner.html b/doc/symbols/jasmine.Runner.html index 81de6a7c..1d9baeb4 100644 --- a/doc/symbols/jasmine.Runner.html +++ b/doc/symbols/jasmine.Runner.html @@ -418,7 +418,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Mon Oct 05 2009 22:35:01 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 13 2009 14:15:02 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Spec.html b/doc/symbols/jasmine.Spec.html index 8cf1a31c..28f5ffa8 100644 --- a/doc/symbols/jasmine.Spec.html +++ b/doc/symbols/jasmine.Spec.html @@ -396,7 +396,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Mon Oct 05 2009 22:35:02 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 13 2009 14:15:02 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Spy.html b/doc/symbols/jasmine.Spy.html index c266cca1..9d2ea11e 100644 --- a/doc/symbols/jasmine.Spy.html +++ b/doc/symbols/jasmine.Spy.html @@ -845,7 +845,7 @@ expect(foo.bar.callCount).toEqual(0);
- Documentation generated by JsDoc Toolkit 2.1.0 on Mon Oct 05 2009 22:35:02 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 13 2009 14:15:02 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Suite.html b/doc/symbols/jasmine.Suite.html index d340ac74..0bbfdffa 100644 --- a/doc/symbols/jasmine.Suite.html +++ b/doc/symbols/jasmine.Suite.html @@ -436,7 +436,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Mon Oct 05 2009 22:35:02 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 13 2009 14:15:02 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.html b/doc/symbols/jasmine.html index a13eb8dd..903d8030 100644 --- a/doc/symbols/jasmine.html +++ b/doc/symbols/jasmine.html @@ -728,7 +728,7 @@ Jasmine environment.
- Documentation generated by JsDoc Toolkit 2.1.0 on Mon Oct 05 2009 22:35:01 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 13 2009 14:15:02 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.util.html b/doc/symbols/jasmine.util.html index 67e89880..c5dac055 100644 --- a/doc/symbols/jasmine.util.html +++ b/doc/symbols/jasmine.util.html @@ -316,7 +316,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Mon Oct 05 2009 22:35:02 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 13 2009 14:15:02 GMT-0700 (PDT)
diff --git a/doc/symbols/src/lib_jasmine-0.9.0.js.html b/doc/symbols/src/lib_jasmine-0.9.0.js.html index 03e66441..75dcaabb 100644 --- a/doc/symbols/src/lib_jasmine-0.9.0.js.html +++ b/doc/symbols/src/lib_jasmine-0.9.0.js.html @@ -530,7 +530,7 @@ 523 "major": 0, 524 "minor": 9, 525 "build": 0, -526 "revision": 1254806558 +526 "revision": 1255468384 527 }; 528 /** 529 * @namespace @@ -1490,7 +1490,7 @@ 1483 this.offset = 0; 1484 }; 1485 -1486 jasmine.Queue.prototype.addBefore = function (block) { +1486 jasmine.Queue.prototype.addBefore = function(block) { 1487 this.blocks.unshift(block); 1488 }; 1489 @@ -1498,667 +1498,682 @@ 1491 this.blocks.push(block); 1492 }; 1493 -1494 jasmine.Queue.prototype.insertNext = function (block) { +1494 jasmine.Queue.prototype.insertNext = function(block) { 1495 this.blocks.splice((this.index + this.offset + 1), 0, block); 1496 this.offset++; 1497 }; 1498 1499 jasmine.Queue.prototype.start = function(onComplete) { -1500 var self = this; -1501 self.running = true; -1502 self.onComplete = onComplete; -1503 if (self.blocks[0]) { -1504 self.blocks[0].execute(function () { -1505 self._next(); -1506 }); -1507 } else { -1508 self.finish(); -1509 } -1510 }; -1511 -1512 jasmine.Queue.prototype.isRunning = function () { -1513 return this.running; -1514 }; -1515 -1516 jasmine.Queue.prototype._next = function () { -1517 var self = this; -1518 var doNext = function () { -1519 self.offset = 0; -1520 self.index++; -1521 if (self.index < self.blocks.length) { -1522 self.blocks[self.index].execute(function () { -1523 self._next(); -1524 }); -1525 } else { -1526 self.finish(); -1527 } -1528 }; -1529 var now = new Date().getTime(); -1530 if (this.env.updateInterval && now - this.env.lastUpdate > this.env.updateInterval) { -1531 this.env.lastUpdate = now; -1532 this.env.setTimeout(doNext, 0); -1533 } else { -1534 doNext(); -1535 } -1536 -1537 }; -1538 -1539 jasmine.Queue.prototype.finish = function () { -1540 this.running = false; -1541 if (this.onComplete) { -1542 this.onComplete(); -1543 } -1544 }; -1545 -1546 jasmine.Queue.prototype.results = function () { -1547 var results = new jasmine.NestedResults(); -1548 for (var i = 0; i < this.blocks.length; i++) { -1549 if (this.blocks[i].results) { -1550 results.addResult(this.blocks[i].results()); -1551 } -1552 } -1553 return results; -1554 }; -1555 -1556 -1557 /* JasmineReporters.reporter -1558 * Base object that will get called whenever a Spec, Suite, or Runner is done. It is up to -1559 * descendants of this object to do something with the results (see json_reporter.js) -1560 */ -1561 jasmine.Reporters = {}; -1562 -1563 jasmine.Reporters.reporter = function(callbacks) { -1564 var that = { -1565 callbacks: callbacks || {}, -1566 -1567 doCallback: function(callback, results) { -1568 if (callback) { -1569 callback(results); -1570 } -1571 }, -1572 -1573 reportRunnerResults: function(runner) { -1574 that.doCallback(that.callbacks.runnerCallback, runner); -1575 }, -1576 reportSuiteResults: function(suite) { -1577 that.doCallback(that.callbacks.suiteCallback, suite); -1578 }, -1579 reportSpecResults: function(spec) { -1580 that.doCallback(that.callbacks.specCallback, spec); -1581 }, -1582 log: function (str) { -1583 if (console && console.log) console.log(str); -1584 } -1585 }; -1586 -1587 return that; -1588 }; -1589 -1590 /** -1591 * Runner -1592 * -1593 * @constructor -1594 * @param {jasmine.Env} env -1595 */ -1596 jasmine.Runner = function(env) { -1597 var self = this; -1598 self.env = env; -1599 self.queue = new jasmine.Queue(env); -1600 self.before_ = []; -1601 self.after_ = []; -1602 self.suites_ = []; +1500 this.running = true; +1501 this.onComplete = onComplete; +1502 this.next_(); +1503 }; +1504 +1505 jasmine.Queue.prototype.isRunning = function() { +1506 return this.running; +1507 }; +1508 +1509 jasmine.Queue.LOOP_DONT_RECURSE = true; +1510 +1511 jasmine.Queue.prototype.next_ = function() { +1512 var self = this; +1513 var goAgain = true; +1514 +1515 while (goAgain) { +1516 goAgain = false; +1517 +1518 if (self.index < self.blocks.length) { +1519 var calledSynchronously = true; +1520 var completedSynchronously = false; +1521 +1522 var onComplete = function () { +1523 if (jasmine.Queue.LOOP_DONT_RECURSE && calledSynchronously) { +1524 completedSynchronously = true; +1525 return; +1526 } +1527 +1528 self.offset = 0; +1529 self.index++; +1530 +1531 var now = new Date().getTime(); +1532 if (self.env.updateInterval && now - self.env.lastUpdate > self.env.updateInterval) { +1533 self.env.lastUpdate = now; +1534 self.env.setTimeout(function() { +1535 self.next_(); +1536 }, 0); +1537 } else { +1538 if (jasmine.Queue.LOOP_DONT_RECURSE && completedSynchronously) { +1539 goAgain = true; +1540 } else { +1541 self.next_(); +1542 } +1543 } +1544 }; +1545 self.blocks[self.index].execute(onComplete); +1546 +1547 calledSynchronously = false; +1548 if (completedSynchronously) { +1549 onComplete(); +1550 } +1551 +1552 } else { +1553 self.running = false; +1554 if (self.onComplete) { +1555 self.onComplete(); +1556 } +1557 } +1558 } +1559 }; +1560 +1561 jasmine.Queue.prototype.results = function() { +1562 var results = new jasmine.NestedResults(); +1563 for (var i = 0; i < this.blocks.length; i++) { +1564 if (this.blocks[i].results) { +1565 results.addResult(this.blocks[i].results()); +1566 } +1567 } +1568 return results; +1569 }; +1570 +1571 +1572 /* JasmineReporters.reporter +1573 * Base object that will get called whenever a Spec, Suite, or Runner is done. It is up to +1574 * descendants of this object to do something with the results (see json_reporter.js) +1575 */ +1576 jasmine.Reporters = {}; +1577 +1578 jasmine.Reporters.reporter = function(callbacks) { +1579 var that = { +1580 callbacks: callbacks || {}, +1581 +1582 doCallback: function(callback, results) { +1583 if (callback) { +1584 callback(results); +1585 } +1586 }, +1587 +1588 reportRunnerResults: function(runner) { +1589 that.doCallback(that.callbacks.runnerCallback, runner); +1590 }, +1591 reportSuiteResults: function(suite) { +1592 that.doCallback(that.callbacks.suiteCallback, suite); +1593 }, +1594 reportSpecResults: function(spec) { +1595 that.doCallback(that.callbacks.specCallback, spec); +1596 }, +1597 log: function (str) { +1598 if (console && console.log) console.log(str); +1599 } +1600 }; +1601 +1602 return that; 1603 }; 1604 -1605 jasmine.Runner.prototype.execute = function() { -1606 var self = this; -1607 if (self.env.reporter.reportRunnerStarting) { -1608 self.env.reporter.reportRunnerStarting(this); -1609 } -1610 self.queue.start(function () { -1611 self.finishCallback(); -1612 }); -1613 }; -1614 -1615 jasmine.Runner.prototype.beforeEach = function(beforeEachFunction) { -1616 beforeEachFunction.typeName = 'beforeEach'; -1617 this.before_.push(beforeEachFunction); +1605 /** +1606 * Runner +1607 * +1608 * @constructor +1609 * @param {jasmine.Env} env +1610 */ +1611 jasmine.Runner = function(env) { +1612 var self = this; +1613 self.env = env; +1614 self.queue = new jasmine.Queue(env); +1615 self.before_ = []; +1616 self.after_ = []; +1617 self.suites_ = []; 1618 }; 1619 -1620 jasmine.Runner.prototype.afterEach = function(afterEachFunction) { -1621 afterEachFunction.typeName = 'afterEach'; -1622 this.after_.push(afterEachFunction); -1623 }; -1624 -1625 -1626 jasmine.Runner.prototype.finishCallback = function() { -1627 this.env.reporter.reportRunnerResults(this); +1620 jasmine.Runner.prototype.execute = function() { +1621 var self = this; +1622 if (self.env.reporter.reportRunnerStarting) { +1623 self.env.reporter.reportRunnerStarting(this); +1624 } +1625 self.queue.start(function () { +1626 self.finishCallback(); +1627 }); 1628 }; 1629 -1630 jasmine.Runner.prototype.addSuite = function(suite) { -1631 this.suites_.push(suite); -1632 }; -1633 -1634 jasmine.Runner.prototype.add = function(block) { -1635 if (block instanceof jasmine.Suite) { -1636 this.addSuite(block); -1637 } -1638 this.queue.add(block); -1639 }; +1630 jasmine.Runner.prototype.beforeEach = function(beforeEachFunction) { +1631 beforeEachFunction.typeName = 'beforeEach'; +1632 this.before_.push(beforeEachFunction); +1633 }; +1634 +1635 jasmine.Runner.prototype.afterEach = function(afterEachFunction) { +1636 afterEachFunction.typeName = 'afterEach'; +1637 this.after_.push(afterEachFunction); +1638 }; +1639 1640 -1641 /** @deprecated */ -1642 jasmine.Runner.prototype.getAllSuites = function() { -1643 return this.suites_; -1644 }; -1645 -1646 -1647 jasmine.Runner.prototype.suites = function() { -1648 return this.suites_; -1649 }; -1650 -1651 jasmine.Runner.prototype.results = function() { -1652 return this.queue.results(); -1653 }; -1654 -1655 /** @deprecated */ -1656 jasmine.Runner.prototype.getResults = function() { -1657 return this.queue.results(); -1658 }; -1659 /** -1660 * Internal representation of a Jasmine specification, or test. -1661 * -1662 * @constructor -1663 * @param {jasmine.Env} env -1664 * @param {jasmine.Suite} suite -1665 * @param {String} description -1666 */ -1667 jasmine.Spec = function(env, suite, description) { -1668 if (!env) { -1669 throw new Error('jasmine.Env() required'); -1670 } -1671 ; -1672 if (!suite) { -1673 throw new Error('jasmine.Suite() required'); -1674 } -1675 ; -1676 var spec = this; -1677 spec.id = env.nextSpecId ? env.nextSpecId() : null; -1678 spec.env = env; -1679 spec.suite = suite; -1680 spec.description = description; -1681 spec.queue = new jasmine.Queue(env); -1682 -1683 spec.afterCallbacks = []; -1684 spec.spies_ = []; -1685 -1686 spec.results_ = new jasmine.NestedResults(); -1687 spec.results_.description = description; -1688 spec.matchersClass = null; -1689 }; -1690 -1691 jasmine.Spec.prototype.getFullName = function() { -1692 return this.suite.getFullName() + ' ' + this.description + '.'; -1693 }; -1694 -1695 -1696 jasmine.Spec.prototype.results = function() { -1697 return this.results_; -1698 }; -1699 -1700 jasmine.Spec.prototype.log = function(message) { -1701 return this.results_.log(message); -1702 }; -1703 -1704 /** @deprecated */ -1705 jasmine.Spec.prototype.getResults = function() { -1706 return this.results_; -1707 }; -1708 -1709 jasmine.Spec.prototype.runs = function (func) { -1710 var block = new jasmine.Block(this.env, func, this); -1711 this.addToQueue(block); -1712 return this; +1641 jasmine.Runner.prototype.finishCallback = function() { +1642 this.env.reporter.reportRunnerResults(this); +1643 }; +1644 +1645 jasmine.Runner.prototype.addSuite = function(suite) { +1646 this.suites_.push(suite); +1647 }; +1648 +1649 jasmine.Runner.prototype.add = function(block) { +1650 if (block instanceof jasmine.Suite) { +1651 this.addSuite(block); +1652 } +1653 this.queue.add(block); +1654 }; +1655 +1656 /** @deprecated */ +1657 jasmine.Runner.prototype.getAllSuites = function() { +1658 return this.suites_; +1659 }; +1660 +1661 +1662 jasmine.Runner.prototype.suites = function() { +1663 return this.suites_; +1664 }; +1665 +1666 jasmine.Runner.prototype.results = function() { +1667 return this.queue.results(); +1668 }; +1669 +1670 /** @deprecated */ +1671 jasmine.Runner.prototype.getResults = function() { +1672 return this.queue.results(); +1673 }; +1674 /** +1675 * Internal representation of a Jasmine specification, or test. +1676 * +1677 * @constructor +1678 * @param {jasmine.Env} env +1679 * @param {jasmine.Suite} suite +1680 * @param {String} description +1681 */ +1682 jasmine.Spec = function(env, suite, description) { +1683 if (!env) { +1684 throw new Error('jasmine.Env() required'); +1685 } +1686 ; +1687 if (!suite) { +1688 throw new Error('jasmine.Suite() required'); +1689 } +1690 ; +1691 var spec = this; +1692 spec.id = env.nextSpecId ? env.nextSpecId() : null; +1693 spec.env = env; +1694 spec.suite = suite; +1695 spec.description = description; +1696 spec.queue = new jasmine.Queue(env); +1697 +1698 spec.afterCallbacks = []; +1699 spec.spies_ = []; +1700 +1701 spec.results_ = new jasmine.NestedResults(); +1702 spec.results_.description = description; +1703 spec.matchersClass = null; +1704 }; +1705 +1706 jasmine.Spec.prototype.getFullName = function() { +1707 return this.suite.getFullName() + ' ' + this.description + '.'; +1708 }; +1709 +1710 +1711 jasmine.Spec.prototype.results = function() { +1712 return this.results_; 1713 }; 1714 -1715 jasmine.Spec.prototype.addToQueue = function (block) { -1716 if (this.queue.isRunning()) { -1717 this.queue.insertNext(block); -1718 } else { -1719 this.queue.add(block); -1720 } -1721 }; -1722 -1723 /** -1724 * @private -1725 * @deprecated -1726 */ -1727 jasmine.Spec.prototype.expects_that = function(actual) { -1728 return this.expect(actual); -1729 }; -1730 -1731 jasmine.Spec.prototype.expect = function(actual) { -1732 return new (this.getMatchersClass_())(this.env, actual, this.results_); -1733 }; -1734 -1735 jasmine.Spec.prototype.waits = function(timeout) { -1736 var waitsFunc = new jasmine.WaitsBlock(this.env, timeout, this); -1737 this.addToQueue(waitsFunc); -1738 return this; -1739 }; -1740 -1741 jasmine.Spec.prototype.waitsFor = function(timeout, latchFunction, timeoutMessage) { -1742 var waitsForFunc = new jasmine.WaitsForBlock(this.env, timeout, latchFunction, timeoutMessage, this); -1743 this.addToQueue(waitsForFunc); -1744 return this; -1745 }; -1746 -1747 jasmine.Spec.prototype.fail = function (e) { -1748 this.results_.addResult(new jasmine.ExpectationResult(false, e ? jasmine.util.formatException(e) : null, null)); -1749 }; -1750 -1751 jasmine.Spec.prototype.getMatchersClass_ = function() { -1752 return this.matchersClass || jasmine.Matchers; -1753 }; -1754 -1755 jasmine.Spec.prototype.addMatchers = function(matchersPrototype) { -1756 var parent = this.getMatchersClass_(); -1757 var newMatchersClass = function() { -1758 parent.apply(this, arguments); -1759 }; -1760 jasmine.util.inherit(newMatchersClass, parent); -1761 for (var method in matchersPrototype) { -1762 newMatchersClass.prototype[method] = matchersPrototype[method]; -1763 } -1764 this.matchersClass = newMatchersClass; -1765 }; -1766 -1767 jasmine.Spec.prototype.finishCallback = function() { -1768 this.env.reporter.reportSpecResults(this); -1769 }; -1770 -1771 jasmine.Spec.prototype.finish = function(onComplete) { -1772 this.removeAllSpies(); -1773 this.finishCallback(); -1774 if (onComplete) { -1775 onComplete(); -1776 } -1777 }; -1778 -1779 jasmine.Spec.prototype.after = function(doAfter, test) { -1780 -1781 if (this.queue.isRunning()) { -1782 this.queue.add(new jasmine.Block(this.env, doAfter, this)); -1783 } else { -1784 this.afterCallbacks.unshift(doAfter); -1785 } -1786 }; -1787 -1788 jasmine.Spec.prototype.execute = function(onComplete) { -1789 var spec = this; -1790 if (!spec.env.specFilter(spec)) { -1791 spec.results_.skipped = true; -1792 spec.finish(onComplete); -1793 return; -1794 } -1795 this.env.reporter.log('>> Jasmine Running ' + this.suite.description + ' ' + this.description + '...'); -1796 -1797 spec.env.currentSpec = spec; -1798 spec.env.currentlyRunningTests = true; -1799 -1800 spec.addBeforesAndAftersToQueue(); -1801 -1802 spec.queue.start(function () { -1803 spec.finish(onComplete); -1804 }); -1805 spec.env.currentlyRunningTests = false; -1806 }; -1807 -1808 jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() { -1809 var runner = this.env.currentRunner(); -1810 for (var suite = this.suite; suite; suite = suite.parentSuite) { -1811 for (var i = 0; i < suite.before_.length; i++) { -1812 this.queue.addBefore(new jasmine.Block(this.env, suite.before_[i], this)); -1813 } -1814 } -1815 for (var i = 0; i < runner.before_.length; i++) { -1816 this.queue.addBefore(new jasmine.Block(this.env, runner.before_[i], this)); -1817 } -1818 for (i = 0; i < this.afterCallbacks.length; i++) { -1819 this.queue.add(new jasmine.Block(this.env, this.afterCallbacks[i], this)); -1820 } -1821 for (suite = this.suite; suite; suite = suite.parentSuite) { -1822 for (var i = 0; i < suite.after_.length; i++) { -1823 this.queue.add(new jasmine.Block(this.env, suite.after_[i], this)); -1824 } -1825 } -1826 for (var i = 0; i < runner.after_.length; i++) { -1827 this.queue.add(new jasmine.Block(this.env, runner.after_[i], this)); -1828 } -1829 }; -1830 -1831 jasmine.Spec.prototype.explodes = function() { -1832 throw 'explodes function should not have been called'; -1833 }; -1834 -1835 jasmine.Spec.prototype.spyOn = function(obj, methodName, ignoreMethodDoesntExist) { -1836 if (obj == undefined) { -1837 throw "spyOn could not find an object to spy upon for " + methodName + "()"; -1838 } -1839 -1840 if (!ignoreMethodDoesntExist && obj[methodName] === undefined) { -1841 throw methodName + '() method does not exist'; -1842 } -1843 -1844 if (!ignoreMethodDoesntExist && obj[methodName] && obj[methodName].isSpy) { -1845 throw new Error(methodName + ' has already been spied upon'); -1846 } -1847 -1848 var spyObj = jasmine.createSpy(methodName); +1715 jasmine.Spec.prototype.log = function(message) { +1716 return this.results_.log(message); +1717 }; +1718 +1719 /** @deprecated */ +1720 jasmine.Spec.prototype.getResults = function() { +1721 return this.results_; +1722 }; +1723 +1724 jasmine.Spec.prototype.runs = function (func) { +1725 var block = new jasmine.Block(this.env, func, this); +1726 this.addToQueue(block); +1727 return this; +1728 }; +1729 +1730 jasmine.Spec.prototype.addToQueue = function (block) { +1731 if (this.queue.isRunning()) { +1732 this.queue.insertNext(block); +1733 } else { +1734 this.queue.add(block); +1735 } +1736 }; +1737 +1738 /** +1739 * @private +1740 * @deprecated +1741 */ +1742 jasmine.Spec.prototype.expects_that = function(actual) { +1743 return this.expect(actual); +1744 }; +1745 +1746 jasmine.Spec.prototype.expect = function(actual) { +1747 return new (this.getMatchersClass_())(this.env, actual, this.results_); +1748 }; +1749 +1750 jasmine.Spec.prototype.waits = function(timeout) { +1751 var waitsFunc = new jasmine.WaitsBlock(this.env, timeout, this); +1752 this.addToQueue(waitsFunc); +1753 return this; +1754 }; +1755 +1756 jasmine.Spec.prototype.waitsFor = function(timeout, latchFunction, timeoutMessage) { +1757 var waitsForFunc = new jasmine.WaitsForBlock(this.env, timeout, latchFunction, timeoutMessage, this); +1758 this.addToQueue(waitsForFunc); +1759 return this; +1760 }; +1761 +1762 jasmine.Spec.prototype.fail = function (e) { +1763 this.results_.addResult(new jasmine.ExpectationResult(false, e ? jasmine.util.formatException(e) : null, null)); +1764 }; +1765 +1766 jasmine.Spec.prototype.getMatchersClass_ = function() { +1767 return this.matchersClass || jasmine.Matchers; +1768 }; +1769 +1770 jasmine.Spec.prototype.addMatchers = function(matchersPrototype) { +1771 var parent = this.getMatchersClass_(); +1772 var newMatchersClass = function() { +1773 parent.apply(this, arguments); +1774 }; +1775 jasmine.util.inherit(newMatchersClass, parent); +1776 for (var method in matchersPrototype) { +1777 newMatchersClass.prototype[method] = matchersPrototype[method]; +1778 } +1779 this.matchersClass = newMatchersClass; +1780 }; +1781 +1782 jasmine.Spec.prototype.finishCallback = function() { +1783 this.env.reporter.reportSpecResults(this); +1784 }; +1785 +1786 jasmine.Spec.prototype.finish = function(onComplete) { +1787 this.removeAllSpies(); +1788 this.finishCallback(); +1789 if (onComplete) { +1790 onComplete(); +1791 } +1792 }; +1793 +1794 jasmine.Spec.prototype.after = function(doAfter, test) { +1795 +1796 if (this.queue.isRunning()) { +1797 this.queue.add(new jasmine.Block(this.env, doAfter, this)); +1798 } else { +1799 this.afterCallbacks.unshift(doAfter); +1800 } +1801 }; +1802 +1803 jasmine.Spec.prototype.execute = function(onComplete) { +1804 var spec = this; +1805 if (!spec.env.specFilter(spec)) { +1806 spec.results_.skipped = true; +1807 spec.finish(onComplete); +1808 return; +1809 } +1810 this.env.reporter.log('>> Jasmine Running ' + this.suite.description + ' ' + this.description + '...'); +1811 +1812 spec.env.currentSpec = spec; +1813 spec.env.currentlyRunningTests = true; +1814 +1815 spec.addBeforesAndAftersToQueue(); +1816 +1817 spec.queue.start(function () { +1818 spec.finish(onComplete); +1819 }); +1820 spec.env.currentlyRunningTests = false; +1821 }; +1822 +1823 jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() { +1824 var runner = this.env.currentRunner(); +1825 for (var suite = this.suite; suite; suite = suite.parentSuite) { +1826 for (var i = 0; i < suite.before_.length; i++) { +1827 this.queue.addBefore(new jasmine.Block(this.env, suite.before_[i], this)); +1828 } +1829 } +1830 for (var i = 0; i < runner.before_.length; i++) { +1831 this.queue.addBefore(new jasmine.Block(this.env, runner.before_[i], this)); +1832 } +1833 for (i = 0; i < this.afterCallbacks.length; i++) { +1834 this.queue.add(new jasmine.Block(this.env, this.afterCallbacks[i], this)); +1835 } +1836 for (suite = this.suite; suite; suite = suite.parentSuite) { +1837 for (var i = 0; i < suite.after_.length; i++) { +1838 this.queue.add(new jasmine.Block(this.env, suite.after_[i], this)); +1839 } +1840 } +1841 for (var i = 0; i < runner.after_.length; i++) { +1842 this.queue.add(new jasmine.Block(this.env, runner.after_[i], this)); +1843 } +1844 }; +1845 +1846 jasmine.Spec.prototype.explodes = function() { +1847 throw 'explodes function should not have been called'; +1848 }; 1849 -1850 this.spies_.push(spyObj); -1851 spyObj.baseObj = obj; -1852 spyObj.methodName = methodName; -1853 spyObj.originalValue = obj[methodName]; +1850 jasmine.Spec.prototype.spyOn = function(obj, methodName, ignoreMethodDoesntExist) { +1851 if (obj == undefined) { +1852 throw "spyOn could not find an object to spy upon for " + methodName + "()"; +1853 } 1854 -1855 obj[methodName] = spyObj; -1856 -1857 return spyObj; -1858 }; -1859 -1860 jasmine.Spec.prototype.removeAllSpies = function() { -1861 for (var i = 0; i < this.spies_.length; i++) { -1862 var spy = this.spies_[i]; -1863 spy.baseObj[spy.methodName] = spy.originalValue; -1864 } -1865 this.spies_ = []; -1866 }; -1867 -1868 /** -1869 * Internal representation of a Jasmine suite. -1870 * -1871 * @constructor -1872 * @param {jasmine.Env} env -1873 * @param {String} description -1874 * @param {Function} specDefinitions -1875 * @param {jasmine.Suite} parentSuite -1876 */ -1877 jasmine.Suite = function(env, description, specDefinitions, parentSuite) { -1878 var self = this; -1879 self.id = env.nextSuiteId ? env.nextSuiteId() : null; -1880 self.description = description; -1881 self.queue = new jasmine.Queue(env); -1882 self.parentSuite = parentSuite; -1883 self.env = env; -1884 self.before_ = []; -1885 self.after_ = []; -1886 self.specs_ = []; -1887 }; -1888 -1889 jasmine.Suite.prototype.getFullName = function() { -1890 var fullName = this.description; -1891 for (var parentSuite = this.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) { -1892 fullName = parentSuite.description + ' ' + fullName; -1893 } -1894 return fullName; -1895 }; -1896 -1897 jasmine.Suite.prototype.finish = function(onComplete) { -1898 this.env.reporter.reportSuiteResults(this); -1899 this.finished = true; -1900 if (typeof(onComplete) == 'function') { -1901 onComplete(); -1902 } -1903 }; -1904 -1905 jasmine.Suite.prototype.beforeEach = function(beforeEachFunction) { -1906 beforeEachFunction.typeName = 'beforeEach'; -1907 this.before_.push(beforeEachFunction); -1908 }; -1909 -1910 jasmine.Suite.prototype.afterEach = function(afterEachFunction) { -1911 afterEachFunction.typeName = 'afterEach'; -1912 this.after_.push(afterEachFunction); -1913 }; -1914 -1915 /** @deprecated */ -1916 jasmine.Suite.prototype.getResults = function() { -1917 return this.queue.results(); +1855 if (!ignoreMethodDoesntExist && obj[methodName] === undefined) { +1856 throw methodName + '() method does not exist'; +1857 } +1858 +1859 if (!ignoreMethodDoesntExist && obj[methodName] && obj[methodName].isSpy) { +1860 throw new Error(methodName + ' has already been spied upon'); +1861 } +1862 +1863 var spyObj = jasmine.createSpy(methodName); +1864 +1865 this.spies_.push(spyObj); +1866 spyObj.baseObj = obj; +1867 spyObj.methodName = methodName; +1868 spyObj.originalValue = obj[methodName]; +1869 +1870 obj[methodName] = spyObj; +1871 +1872 return spyObj; +1873 }; +1874 +1875 jasmine.Spec.prototype.removeAllSpies = function() { +1876 for (var i = 0; i < this.spies_.length; i++) { +1877 var spy = this.spies_[i]; +1878 spy.baseObj[spy.methodName] = spy.originalValue; +1879 } +1880 this.spies_ = []; +1881 }; +1882 +1883 /** +1884 * Internal representation of a Jasmine suite. +1885 * +1886 * @constructor +1887 * @param {jasmine.Env} env +1888 * @param {String} description +1889 * @param {Function} specDefinitions +1890 * @param {jasmine.Suite} parentSuite +1891 */ +1892 jasmine.Suite = function(env, description, specDefinitions, parentSuite) { +1893 var self = this; +1894 self.id = env.nextSuiteId ? env.nextSuiteId() : null; +1895 self.description = description; +1896 self.queue = new jasmine.Queue(env); +1897 self.parentSuite = parentSuite; +1898 self.env = env; +1899 self.before_ = []; +1900 self.after_ = []; +1901 self.specs_ = []; +1902 }; +1903 +1904 jasmine.Suite.prototype.getFullName = function() { +1905 var fullName = this.description; +1906 for (var parentSuite = this.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) { +1907 fullName = parentSuite.description + ' ' + fullName; +1908 } +1909 return fullName; +1910 }; +1911 +1912 jasmine.Suite.prototype.finish = function(onComplete) { +1913 this.env.reporter.reportSuiteResults(this); +1914 this.finished = true; +1915 if (typeof(onComplete) == 'function') { +1916 onComplete(); +1917 } 1918 }; 1919 -1920 jasmine.Suite.prototype.results = function() { -1921 return this.queue.results(); -1922 }; -1923 -1924 jasmine.Suite.prototype.add = function(block) { -1925 if (block instanceof jasmine.Suite) { -1926 this.env.currentRunner().addSuite(block); -1927 } else { -1928 this.specs_.push(block); -1929 } -1930 this.queue.add(block); -1931 }; -1932 -1933 /** @deprecated */ -1934 jasmine.Suite.prototype.specCount = function() { -1935 return this.specs_.length; -1936 }; -1937 -1938 jasmine.Suite.prototype.specs = function() { -1939 return this.specs_; -1940 }; -1941 -1942 jasmine.Suite.prototype.execute = function(onComplete) { -1943 var self = this; -1944 this.queue.start(function () { -1945 self.finish(onComplete); -1946 }); -1947 }; -1948 jasmine.WaitsBlock = function(env, timeout, spec) { -1949 this.timeout = timeout; -1950 jasmine.Block.call(this, env, null, spec); +1920 jasmine.Suite.prototype.beforeEach = function(beforeEachFunction) { +1921 beforeEachFunction.typeName = 'beforeEach'; +1922 this.before_.push(beforeEachFunction); +1923 }; +1924 +1925 jasmine.Suite.prototype.afterEach = function(afterEachFunction) { +1926 afterEachFunction.typeName = 'afterEach'; +1927 this.after_.push(afterEachFunction); +1928 }; +1929 +1930 /** @deprecated */ +1931 jasmine.Suite.prototype.getResults = function() { +1932 return this.queue.results(); +1933 }; +1934 +1935 jasmine.Suite.prototype.results = function() { +1936 return this.queue.results(); +1937 }; +1938 +1939 jasmine.Suite.prototype.add = function(block) { +1940 if (block instanceof jasmine.Suite) { +1941 this.env.currentRunner().addSuite(block); +1942 } else { +1943 this.specs_.push(block); +1944 } +1945 this.queue.add(block); +1946 }; +1947 +1948 /** @deprecated */ +1949 jasmine.Suite.prototype.specCount = function() { +1950 return this.specs_.length; 1951 }; 1952 -1953 jasmine.util.inherit(jasmine.WaitsBlock, jasmine.Block); -1954 -1955 jasmine.WaitsBlock.prototype.execute = function (onComplete) { -1956 this.env.reporter.log('>> Jasmine waiting for ' + this.timeout + ' ms...'); -1957 this.env.setTimeout(function () { -1958 onComplete(); -1959 }, this.timeout); -1960 }; -1961 jasmine.WaitsForBlock = function(env, timeout, latchFunction, message, spec) { -1962 this.timeout = timeout; -1963 this.latchFunction = latchFunction; -1964 this.message = message; -1965 this.totalTimeSpentWaitingForLatch = 0; -1966 jasmine.Block.call(this, env, null, spec); -1967 }; -1968 -1969 jasmine.util.inherit(jasmine.WaitsForBlock, jasmine.Block); -1970 -1971 jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 100; -1972 -1973 jasmine.WaitsForBlock.prototype.execute = function (onComplete) { -1974 var self = this; -1975 self.env.reporter.log('>> Jasmine waiting for ' + (self.message || 'something to happen')); -1976 var latchFunctionResult; -1977 try { -1978 latchFunctionResult = self.latchFunction.apply(self.spec); -1979 } catch (e) { -1980 self.spec.fail(e); -1981 onComplete(); -1982 return; -1983 } -1984 -1985 if (latchFunctionResult) { -1986 onComplete(); -1987 } else if (self.totalTimeSpentWaitingForLatch >= self.timeout) { -1988 var message = 'timed out after ' + self.timeout + ' msec waiting for ' + (self.message || 'something to happen'); -1989 self.spec.fail({ -1990 name: 'timeout', -1991 message: message -1992 }); -1993 self.spec._next(); -1994 } else { -1995 self.totalTimeSpentWaitingForLatch += jasmine.WaitsForBlock.TIMEOUT_INCREMENT; -1996 self.env.setTimeout(function () { self.execute(onComplete); }, jasmine.WaitsForBlock.TIMEOUT_INCREMENT); -1997 } -1998 }; -1999 // Mock setTimeout, clearTimeout -2000 // Contributed by Pivotal Computer Systems, www.pivotalsf.com -2001 -2002 jasmine.FakeTimer = function() { -2003 this.reset(); -2004 -2005 var self = this; -2006 self.setTimeout = function(funcToCall, millis) { -2007 self.timeoutsMade++; -2008 self.scheduleFunction(self.timeoutsMade, funcToCall, millis, false); -2009 return self.timeoutsMade; -2010 }; -2011 -2012 self.setInterval = function(funcToCall, millis) { -2013 self.timeoutsMade++; -2014 self.scheduleFunction(self.timeoutsMade, funcToCall, millis, true); -2015 return self.timeoutsMade; -2016 }; -2017 -2018 self.clearTimeout = function(timeoutKey) { -2019 self.scheduledFunctions[timeoutKey] = undefined; -2020 }; -2021 -2022 self.clearInterval = function(timeoutKey) { -2023 self.scheduledFunctions[timeoutKey] = undefined; -2024 }; -2025 -2026 }; -2027 -2028 jasmine.FakeTimer.prototype.reset = function() { -2029 this.timeoutsMade = 0; -2030 this.scheduledFunctions = {}; -2031 this.nowMillis = 0; -2032 }; -2033 -2034 jasmine.FakeTimer.prototype.tick = function(millis) { -2035 var oldMillis = this.nowMillis; -2036 var newMillis = oldMillis + millis; -2037 this.runFunctionsWithinRange(oldMillis, newMillis); -2038 this.nowMillis = newMillis; -2039 }; +1953 jasmine.Suite.prototype.specs = function() { +1954 return this.specs_; +1955 }; +1956 +1957 jasmine.Suite.prototype.execute = function(onComplete) { +1958 var self = this; +1959 this.queue.start(function () { +1960 self.finish(onComplete); +1961 }); +1962 }; +1963 jasmine.WaitsBlock = function(env, timeout, spec) { +1964 this.timeout = timeout; +1965 jasmine.Block.call(this, env, null, spec); +1966 }; +1967 +1968 jasmine.util.inherit(jasmine.WaitsBlock, jasmine.Block); +1969 +1970 jasmine.WaitsBlock.prototype.execute = function (onComplete) { +1971 this.env.reporter.log('>> Jasmine waiting for ' + this.timeout + ' ms...'); +1972 this.env.setTimeout(function () { +1973 onComplete(); +1974 }, this.timeout); +1975 }; +1976 jasmine.WaitsForBlock = function(env, timeout, latchFunction, message, spec) { +1977 this.timeout = timeout; +1978 this.latchFunction = latchFunction; +1979 this.message = message; +1980 this.totalTimeSpentWaitingForLatch = 0; +1981 jasmine.Block.call(this, env, null, spec); +1982 }; +1983 +1984 jasmine.util.inherit(jasmine.WaitsForBlock, jasmine.Block); +1985 +1986 jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 100; +1987 +1988 jasmine.WaitsForBlock.prototype.execute = function (onComplete) { +1989 var self = this; +1990 self.env.reporter.log('>> Jasmine waiting for ' + (self.message || 'something to happen')); +1991 var latchFunctionResult; +1992 try { +1993 latchFunctionResult = self.latchFunction.apply(self.spec); +1994 } catch (e) { +1995 self.spec.fail(e); +1996 onComplete(); +1997 return; +1998 } +1999 +2000 if (latchFunctionResult) { +2001 onComplete(); +2002 } else if (self.totalTimeSpentWaitingForLatch >= self.timeout) { +2003 var message = 'timed out after ' + self.timeout + ' msec waiting for ' + (self.message || 'something to happen'); +2004 self.spec.fail({ +2005 name: 'timeout', +2006 message: message +2007 }); +2008 self.spec._next(); +2009 } else { +2010 self.totalTimeSpentWaitingForLatch += jasmine.WaitsForBlock.TIMEOUT_INCREMENT; +2011 self.env.setTimeout(function () { self.execute(onComplete); }, jasmine.WaitsForBlock.TIMEOUT_INCREMENT); +2012 } +2013 }; +2014 // Mock setTimeout, clearTimeout +2015 // Contributed by Pivotal Computer Systems, www.pivotalsf.com +2016 +2017 jasmine.FakeTimer = function() { +2018 this.reset(); +2019 +2020 var self = this; +2021 self.setTimeout = function(funcToCall, millis) { +2022 self.timeoutsMade++; +2023 self.scheduleFunction(self.timeoutsMade, funcToCall, millis, false); +2024 return self.timeoutsMade; +2025 }; +2026 +2027 self.setInterval = function(funcToCall, millis) { +2028 self.timeoutsMade++; +2029 self.scheduleFunction(self.timeoutsMade, funcToCall, millis, true); +2030 return self.timeoutsMade; +2031 }; +2032 +2033 self.clearTimeout = function(timeoutKey) { +2034 self.scheduledFunctions[timeoutKey] = undefined; +2035 }; +2036 +2037 self.clearInterval = function(timeoutKey) { +2038 self.scheduledFunctions[timeoutKey] = undefined; +2039 }; 2040 -2041 jasmine.FakeTimer.prototype.runFunctionsWithinRange = function(oldMillis, nowMillis) { -2042 var scheduledFunc; -2043 var funcsToRun = []; -2044 for (var timeoutKey in this.scheduledFunctions) { -2045 scheduledFunc = this.scheduledFunctions[timeoutKey]; -2046 if (scheduledFunc != undefined && -2047 scheduledFunc.runAtMillis >= oldMillis && -2048 scheduledFunc.runAtMillis <= nowMillis) { -2049 funcsToRun.push(scheduledFunc); -2050 this.scheduledFunctions[timeoutKey] = undefined; -2051 } -2052 } -2053 -2054 if (funcsToRun.length > 0) { -2055 funcsToRun.sort(function(a, b) { -2056 return a.runAtMillis - b.runAtMillis; -2057 }); -2058 for (var i = 0; i < funcsToRun.length; ++i) { -2059 try { -2060 var funcToRun = funcsToRun[i]; -2061 this.nowMillis = funcToRun.runAtMillis; -2062 funcToRun.funcToCall(); -2063 if (funcToRun.recurring) { -2064 this.scheduleFunction(funcToRun.timeoutKey, -2065 funcToRun.funcToCall, -2066 funcToRun.millis, -2067 true); -2068 } -2069 } catch(e) { -2070 } -2071 } -2072 this.runFunctionsWithinRange(oldMillis, nowMillis); -2073 } -2074 }; -2075 -2076 jasmine.FakeTimer.prototype.scheduleFunction = function(timeoutKey, funcToCall, millis, recurring) { -2077 this.scheduledFunctions[timeoutKey] = { -2078 runAtMillis: this.nowMillis + millis, -2079 funcToCall: funcToCall, -2080 recurring: recurring, -2081 timeoutKey: timeoutKey, -2082 millis: millis -2083 }; -2084 }; -2085 -2086 -2087 jasmine.Clock = { -2088 defaultFakeTimer: new jasmine.FakeTimer(), -2089 -2090 reset: function() { -2091 jasmine.Clock.assertInstalled(); -2092 jasmine.Clock.defaultFakeTimer.reset(); -2093 }, -2094 -2095 tick: function(millis) { -2096 jasmine.Clock.assertInstalled(); -2097 jasmine.Clock.defaultFakeTimer.tick(millis); -2098 }, -2099 -2100 runFunctionsWithinRange: function(oldMillis, nowMillis) { -2101 jasmine.Clock.defaultFakeTimer.runFunctionsWithinRange(oldMillis, nowMillis); -2102 }, -2103 -2104 scheduleFunction: function(timeoutKey, funcToCall, millis, recurring) { -2105 jasmine.Clock.defaultFakeTimer.scheduleFunction(timeoutKey, funcToCall, millis, recurring); -2106 }, -2107 -2108 useMock: function() { -2109 var spec = jasmine.getEnv().currentSpec; -2110 spec.after(jasmine.Clock.uninstallMock); -2111 -2112 jasmine.Clock.installMock(); +2041 }; +2042 +2043 jasmine.FakeTimer.prototype.reset = function() { +2044 this.timeoutsMade = 0; +2045 this.scheduledFunctions = {}; +2046 this.nowMillis = 0; +2047 }; +2048 +2049 jasmine.FakeTimer.prototype.tick = function(millis) { +2050 var oldMillis = this.nowMillis; +2051 var newMillis = oldMillis + millis; +2052 this.runFunctionsWithinRange(oldMillis, newMillis); +2053 this.nowMillis = newMillis; +2054 }; +2055 +2056 jasmine.FakeTimer.prototype.runFunctionsWithinRange = function(oldMillis, nowMillis) { +2057 var scheduledFunc; +2058 var funcsToRun = []; +2059 for (var timeoutKey in this.scheduledFunctions) { +2060 scheduledFunc = this.scheduledFunctions[timeoutKey]; +2061 if (scheduledFunc != undefined && +2062 scheduledFunc.runAtMillis >= oldMillis && +2063 scheduledFunc.runAtMillis <= nowMillis) { +2064 funcsToRun.push(scheduledFunc); +2065 this.scheduledFunctions[timeoutKey] = undefined; +2066 } +2067 } +2068 +2069 if (funcsToRun.length > 0) { +2070 funcsToRun.sort(function(a, b) { +2071 return a.runAtMillis - b.runAtMillis; +2072 }); +2073 for (var i = 0; i < funcsToRun.length; ++i) { +2074 try { +2075 var funcToRun = funcsToRun[i]; +2076 this.nowMillis = funcToRun.runAtMillis; +2077 funcToRun.funcToCall(); +2078 if (funcToRun.recurring) { +2079 this.scheduleFunction(funcToRun.timeoutKey, +2080 funcToRun.funcToCall, +2081 funcToRun.millis, +2082 true); +2083 } +2084 } catch(e) { +2085 } +2086 } +2087 this.runFunctionsWithinRange(oldMillis, nowMillis); +2088 } +2089 }; +2090 +2091 jasmine.FakeTimer.prototype.scheduleFunction = function(timeoutKey, funcToCall, millis, recurring) { +2092 this.scheduledFunctions[timeoutKey] = { +2093 runAtMillis: this.nowMillis + millis, +2094 funcToCall: funcToCall, +2095 recurring: recurring, +2096 timeoutKey: timeoutKey, +2097 millis: millis +2098 }; +2099 }; +2100 +2101 +2102 jasmine.Clock = { +2103 defaultFakeTimer: new jasmine.FakeTimer(), +2104 +2105 reset: function() { +2106 jasmine.Clock.assertInstalled(); +2107 jasmine.Clock.defaultFakeTimer.reset(); +2108 }, +2109 +2110 tick: function(millis) { +2111 jasmine.Clock.assertInstalled(); +2112 jasmine.Clock.defaultFakeTimer.tick(millis); 2113 }, 2114 -2115 installMock: function() { -2116 jasmine.Clock.installed = jasmine.Clock.defaultFakeTimer; +2115 runFunctionsWithinRange: function(oldMillis, nowMillis) { +2116 jasmine.Clock.defaultFakeTimer.runFunctionsWithinRange(oldMillis, nowMillis); 2117 }, 2118 -2119 uninstallMock: function() { -2120 jasmine.Clock.assertInstalled(); -2121 jasmine.Clock.installed = jasmine.Clock.real; -2122 }, -2123 -2124 real: { -2125 setTimeout: window.setTimeout, -2126 clearTimeout: window.clearTimeout, -2127 setInterval: window.setInterval, -2128 clearInterval: window.clearInterval -2129 }, -2130 -2131 assertInstalled: function() { -2132 if (jasmine.Clock.installed != jasmine.Clock.defaultFakeTimer) { -2133 throw new Error("Mock clock is not installed, use jasmine.Clock.useMock()"); -2134 } -2135 }, -2136 -2137 installed: null -2138 }; -2139 jasmine.Clock.installed = jasmine.Clock.real; -2140 -2141 window.setTimeout = function(funcToCall, millis) { -2142 return jasmine.Clock.installed.setTimeout.apply(this, arguments); -2143 }; -2144 -2145 window.setInterval = function(funcToCall, millis) { -2146 return jasmine.Clock.installed.setInterval.apply(this, arguments); -2147 }; -2148 -2149 window.clearTimeout = function(timeoutKey) { -2150 return jasmine.Clock.installed.clearTimeout.apply(this, arguments); -2151 }; -2152 -2153 window.clearInterval = function(timeoutKey) { -2154 return jasmine.Clock.installed.clearInterval.apply(this, arguments); -2155 }; -2156 -2157 \ No newline at end of file +2119 scheduleFunction: function(timeoutKey, funcToCall, millis, recurring) { +2120 jasmine.Clock.defaultFakeTimer.scheduleFunction(timeoutKey, funcToCall, millis, recurring); +2121 }, +2122 +2123 useMock: function() { +2124 var spec = jasmine.getEnv().currentSpec; +2125 spec.after(jasmine.Clock.uninstallMock); +2126 +2127 jasmine.Clock.installMock(); +2128 }, +2129 +2130 installMock: function() { +2131 jasmine.Clock.installed = jasmine.Clock.defaultFakeTimer; +2132 }, +2133 +2134 uninstallMock: function() { +2135 jasmine.Clock.assertInstalled(); +2136 jasmine.Clock.installed = jasmine.Clock.real; +2137 }, +2138 +2139 real: { +2140 setTimeout: window.setTimeout, +2141 clearTimeout: window.clearTimeout, +2142 setInterval: window.setInterval, +2143 clearInterval: window.clearInterval +2144 }, +2145 +2146 assertInstalled: function() { +2147 if (jasmine.Clock.installed != jasmine.Clock.defaultFakeTimer) { +2148 throw new Error("Mock clock is not installed, use jasmine.Clock.useMock()"); +2149 } +2150 }, +2151 +2152 installed: null +2153 }; +2154 jasmine.Clock.installed = jasmine.Clock.real; +2155 +2156 window.setTimeout = function(funcToCall, millis) { +2157 return jasmine.Clock.installed.setTimeout.apply(this, arguments); +2158 }; +2159 +2160 window.setInterval = function(funcToCall, millis) { +2161 return jasmine.Clock.installed.setInterval.apply(this, arguments); +2162 }; +2163 +2164 window.clearTimeout = function(timeoutKey) { +2165 return jasmine.Clock.installed.clearTimeout.apply(this, arguments); +2166 }; +2167 +2168 window.clearInterval = function(timeoutKey) { +2169 return jasmine.Clock.installed.clearInterval.apply(this, arguments); +2170 }; +2171 +2172 \ No newline at end of file diff --git a/lib/jasmine-0.9.0.js b/lib/jasmine-0.9.0.js index f32f89ab..faec0a53 100644 --- a/lib/jasmine-0.9.0.js +++ b/lib/jasmine-0.9.0.js @@ -523,7 +523,7 @@ jasmine.version_= { "major": 0, "minor": 9, "build": 0, - "revision": 1254807302 + "revision": 1255468502 }; /** * @namespace @@ -1483,7 +1483,7 @@ jasmine.Queue = function(env) { this.offset = 0; }; -jasmine.Queue.prototype.addBefore = function (block) { +jasmine.Queue.prototype.addBefore = function(block) { this.blocks.unshift(block); }; @@ -1491,59 +1491,74 @@ jasmine.Queue.prototype.add = function(block) { this.blocks.push(block); }; -jasmine.Queue.prototype.insertNext = function (block) { +jasmine.Queue.prototype.insertNext = function(block) { this.blocks.splice((this.index + this.offset + 1), 0, block); this.offset++; }; jasmine.Queue.prototype.start = function(onComplete) { - var self = this; - self.running = true; - self.onComplete = onComplete; - if (self.blocks[0]) { - self.blocks[0].execute(function () { - self._next(); - }); - } else { - self.finish(); - } + this.running = true; + this.onComplete = onComplete; + this.next_(); }; -jasmine.Queue.prototype.isRunning = function () { +jasmine.Queue.prototype.isRunning = function() { return this.running; }; -jasmine.Queue.prototype._next = function () { +jasmine.Queue.LOOP_DONT_RECURSE = true; + +jasmine.Queue.prototype.next_ = function() { var self = this; - var doNext = function () { - self.offset = 0; - self.index++; + var goAgain = true; + + while (goAgain) { + goAgain = false; + if (self.index < self.blocks.length) { - self.blocks[self.index].execute(function () { - self._next(); - }); + var calledSynchronously = true; + var completedSynchronously = false; + + var onComplete = function () { + if (jasmine.Queue.LOOP_DONT_RECURSE && calledSynchronously) { + completedSynchronously = true; + return; + } + + self.offset = 0; + self.index++; + + var now = new Date().getTime(); + if (self.env.updateInterval && now - self.env.lastUpdate > self.env.updateInterval) { + self.env.lastUpdate = now; + self.env.setTimeout(function() { + self.next_(); + }, 0); + } else { + if (jasmine.Queue.LOOP_DONT_RECURSE && completedSynchronously) { + goAgain = true; + } else { + self.next_(); + } + } + }; + self.blocks[self.index].execute(onComplete); + + calledSynchronously = false; + if (completedSynchronously) { + onComplete(); + } + } else { - self.finish(); + self.running = false; + if (self.onComplete) { + self.onComplete(); + } } - }; - var now = new Date().getTime(); - if (this.env.updateInterval && now - this.env.lastUpdate > this.env.updateInterval) { - this.env.lastUpdate = now; - this.env.setTimeout(doNext, 0); - } else { - doNext(); - } - -}; - -jasmine.Queue.prototype.finish = function () { - this.running = false; - if (this.onComplete) { - this.onComplete(); } }; -jasmine.Queue.prototype.results = function () { +jasmine.Queue.prototype.results = function() { var results = new jasmine.NestedResults(); for (var i = 0; i < this.blocks.length; i++) { if (this.blocks[i].results) {