From 60a5d60f4243d4353de58c4a68103e589943e64f Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 28 Sep 2010 20:43:50 -0700 Subject: [PATCH] Consolidate all waitsFor specs in the same describe block. --- spec/suites/SpecRunningSpec.js | 168 ++++++++++++++++----------------- 1 file changed, 84 insertions(+), 84 deletions(-) diff --git a/spec/suites/SpecRunningSpec.js b/spec/suites/SpecRunningSpec.js index 289d9468..f4b4c65d 100644 --- a/spec/suites/SpecRunningSpec.js +++ b/spec/suites/SpecRunningSpec.js @@ -398,6 +398,90 @@ describe("jasmine spec running", function () { expect(timeoutSpec.results().getItems()[0].message).toEqual('timeout: timed out after 500 msec waiting for something to happen'); expect(subsequentSpecRan).toEqual(true); }); + + describe('with consecutive calls', function () { + var foo; + beforeEach(function () { + foo = 0; + }); + + it('exits immediately (does not stack) if the latchFunction times out', function () { + var reachedFirstWaitsFor = false; + var reachedSecondWaitsFor = false; + env.describe('suite that waits', function () { + env.it('should stack timeouts', function() { + this.waitsFor(500, function () { + reachedFirstWaitsFor = true; + return false; + }); + this.waitsFor(500, function () { + reachedSecondWaitsFor = true; + }); + this.runs(function () { + foo++; + }); + }); + }); + + expect(reachedFirstWaitsFor).toEqual(false); + env.execute(); + + expect(reachedFirstWaitsFor).toEqual(true); + expect(foo).toEqual(0); + expect(reachedSecondWaitsFor).toEqual(false); + fakeTimer.tick(500); + expect(reachedSecondWaitsFor).toEqual(false); + expect(foo).toEqual(0); + fakeTimer.tick(500); + expect(reachedSecondWaitsFor).toEqual(false); + expect(foo).toEqual(0); + }); + + it('stacks latchFunctions', function () { + var firstWaitsResult = false; + var secondWaitsResult = false; + var waitsSuite = env.describe('suite that waits', function () { + env.it('spec with waitsFors', function() { + this.waitsFor(600, function () { + fakeTimer.setTimeout(function () { + firstWaitsResult = true; + }, 300); + return firstWaitsResult; + }); + this.waitsFor(600, function () { + fakeTimer.setTimeout(function () { + secondWaitsResult = true; + }, 300); + return secondWaitsResult; + }); + this.runs(function () { + foo++; + }); + }); + }); + + expect(firstWaitsResult).toEqual(false); + expect(secondWaitsResult).toEqual(false); + waitsSuite.execute(); + + expect(firstWaitsResult).toEqual(false); + expect(secondWaitsResult).toEqual(false); + expect(foo).toEqual(0); + + fakeTimer.tick(300); + + expect(firstWaitsResult).toEqual(true); + expect(secondWaitsResult).toEqual(false); + expect(foo).toEqual(0); + + fakeTimer.tick(300); + + expect(firstWaitsResult).toEqual(true); + expect(secondWaitsResult).toEqual(true); + expect(foo).toEqual(1); + + }); + }); }); it("testSpecAfter", function() { @@ -579,90 +663,6 @@ describe("jasmine spec running", function () { expect(quux).toEqual(1); }); - describe('#waitsFor should allow consecutive calls', function () { - var foo; - beforeEach(function () { - foo = 0; - }); - - it('exits immediately (does not stack) if the latchFunction times out', function () { - var reachedFirstWaitsFor = false; - var reachedSecondWaitsFor = false; - env.describe('suite that waits', function () { - env.it('should stack timeouts', function() { - this.waitsFor(500, function () { - reachedFirstWaitsFor = true; - return false; - }); - this.waitsFor(500, function () { - reachedSecondWaitsFor = true; - }); - this.runs(function () { - foo++; - }); - }); - }); - - expect(reachedFirstWaitsFor).toEqual(false); - env.execute(); - - expect(reachedFirstWaitsFor).toEqual(true); - expect(foo).toEqual(0); - expect(reachedSecondWaitsFor).toEqual(false); - fakeTimer.tick(500); - expect(reachedSecondWaitsFor).toEqual(false); - expect(foo).toEqual(0); - fakeTimer.tick(500); - expect(reachedSecondWaitsFor).toEqual(false); - expect(foo).toEqual(0); - }); - - it('stacks latchFunctions', function () { - var firstWaitsResult = false; - var secondWaitsResult = false; - var waitsSuite = env.describe('suite that waits', function () { - env.it('spec with waitsFors', function() { - this.waitsFor(600, function () { - fakeTimer.setTimeout(function () { - firstWaitsResult = true; - }, 300); - return firstWaitsResult; - }); - this.waitsFor(600, function () { - fakeTimer.setTimeout(function () { - secondWaitsResult = true; - }, 300); - return secondWaitsResult; - }); - this.runs(function () { - foo++; - }); - }); - }); - - expect(firstWaitsResult).toEqual(false); - expect(secondWaitsResult).toEqual(false); - waitsSuite.execute(); - - expect(firstWaitsResult).toEqual(false); - expect(secondWaitsResult).toEqual(false); - expect(foo).toEqual(0); - - fakeTimer.tick(300); - - expect(firstWaitsResult).toEqual(true); - expect(secondWaitsResult).toEqual(false); - expect(foo).toEqual(0); - - fakeTimer.tick(300); - - expect(firstWaitsResult).toEqual(true); - expect(secondWaitsResult).toEqual(true); - expect(foo).toEqual(1); - - }); - }); - it("#beforeEach should be able to eval runs and waits blocks", function () { var foo = 0; var bar = 0;