Remove results from Queue

- consequently, Runner & Suite no longer have results.
- Results come back to reporters from Spec, we should not have a need to
  walk them later via suite/runner (in fact, no reporter used results on
  suite/runner -- only bad tests)
- Remove/clean up tests relying on #results
- Remove integration tests that duplicate already tested behavior
This commit is contained in:
Davis W. Frank & Rajan Agaskar
2012-11-30 10:08:20 -08:00
parent 1f5e790c41
commit 779dee1211
18 changed files with 354 additions and 1682 deletions

View File

@@ -59,117 +59,36 @@ describe('Exceptions:', function() {
describe("with catch on exception", function() {
it('should handle exceptions thrown, but continue', function() {
var fakeTimer = new jasmine.FakeTimer();
env.setTimeout = fakeTimer.setTimeout;
env.clearTimeout = fakeTimer.clearTimeout;
env.setInterval = fakeTimer.setInterval;
env.clearInterval = fakeTimer.clearInterval;
//we run two exception tests to make sure we continue after throwing an exception
var suite = env.describe('Suite for handles exceptions', function () {
var ranSecondTest = false,
suite = env.describe('Suite for handles exceptions', function () {
env.it('should be a test that fails because it throws an exception', function() {
throw new Error('fake error 1');
throw new Error();
});
env.it('should be another test that fails because it throws an exception', function() {
this.runs(function () {
throw new Error('fake error 2');
});
this.runs(function () {
this.expect(true).toEqual(true);
});
});
env.it('should be a passing test that runs after exceptions are thrown', function() {
this.expect(true).toEqual(true);
});
env.it('should be another test that fails because it throws an exception after a wait', function() {
this.runs(function () {
var foo = 'foo';
});
this.waits(250);
this.runs(function () {
throw new Error('fake error 3');
});
});
env.it('should be a passing test that runs after exceptions are thrown from a async test', function() {
this.expect(true).toEqual(true);
ranSecondTest = true;
});
});
var runner = env.currentRunner();
suite.execute();
fakeTimer.tick(2500);
var suiteResults = suite.results();
var specResults = suiteResults.getItems();
expect(suiteResults.passed()).toEqual(false);
//
expect(specResults.length).toEqual(5);
expect(specResults[0].passed()).toMatch(false);
var blockResults = specResults[0].getItems();
expect(blockResults[0].passed).toEqual(false);
expect(blockResults[0].message).toMatch(/fake error 1/);
expect(specResults[1].passed()).toEqual(false);
blockResults = specResults[1].getItems();
expect(blockResults[0].passed).toEqual(false);
expect(blockResults[0].message).toMatch(/fake error 2/);
expect(blockResults[1].passed).toEqual(true);
expect(specResults[2].passed()).toEqual(true);
expect(specResults[3].passed()).toEqual(false);
blockResults = specResults[3].getItems();
expect(blockResults[0].message).toMatch(/fake error 3/);
expect(specResults[4].passed()).toEqual(true);
expect(ranSecondTest).toBe(true);
});
it("should handle exceptions thrown directly in top-level describe blocks and continue", function () {
var suite = env.describe("a top level describe block that throws an exception", function () {
var ranSecondDescribe = false, suite, suite2, runner = env.currentRunner();
suite = env.describe("a suite that throws an exception", function () {
env.it("is a test that should pass", function () {
this.expect(true).toEqual(true);
});
throw new Error("top level error");
});
suite.execute();
var suiteResults = suite.results();
var specResults = suiteResults.getItems();
expect(suiteResults.passed()).toEqual(false);
expect(specResults.length).toEqual(2);
expect(specResults[1].description).toMatch(/encountered a declaration exception/);
});
it("should handle exceptions thrown directly in nested describe blocks and continue", function () {
var suite = env.describe("a top level describe", function () {
env.describe("a mid-level describe that throws an exception", function () {
env.it("is a test that should pass", function () {
this.expect(true).toEqual(true);
});
throw new Error("a mid-level error");
});
suite2 = env.describe("a suite that doesn't throw an exception", function () {
ranSecondDescribe = true;
});
suite.execute();
var suiteResults = suite.results();
var specResults = suiteResults.getItems();
expect(suiteResults.passed()).toEqual(false);
expect(specResults.length).toEqual(1);
var nestedSpecResults = specResults[0].getItems();
expect(nestedSpecResults.length).toEqual(2);
expect(nestedSpecResults[1].description).toMatch(/encountered a declaration exception/);
runner.execute();
expect(ranSecondDescribe).toBe(true);
});
});
});

View File

@@ -14,105 +14,83 @@ describe('RunnerTest', function() {
});
describe('beforeEach', function() {
it('should run before each spec for all suites', function () {
it('should run before each spec for all suites', function() {
var foo;
env.beforeEach(function () {
env.beforeEach(function() {
foo = 0;
});
env.describe('suite 1', function () {
env.describe('suite 1', function() {
env.it('test 1-1', function() {
foo++;
this.expect(foo).toEqual(1);
expect(foo).toEqual(1);
});
env.it('test 1-2', function() {
foo++;
this.expect(foo).toEqual(1);
expect(foo).toEqual(1);
});
});
env.describe('suite 2', function () {
env.describe('suite 2', function() {
env.it('test 2-1', function() {
foo++;
this.expect(foo).toEqual(1);
expect(foo).toEqual(1);
});
});
env.currentRunner().execute();
var runnerResults = env.currentRunner().results();
expect(runnerResults.totalCount).toEqual(3);
expect(runnerResults.passedCount).toEqual(3);
});
it('should provide all specs', function() {
it('should provide all specs', function () {
var foo;
env.beforeEach(function () {
foo = 0;
});
env.describe('suite 1', function () {
env.describe('suite 1', function() {
env.it('test 1-1', function() {
foo++;
this.expect(foo).toEqual(1);
});
env.it('test 1-2', function() {
foo++;
this.expect(foo).toEqual(1);
});
});
env.describe('suite 2', function () {
env.describe('suite 2', function() {
env.it('test 2-1', function() {
foo++;
this.expect(foo).toEqual(1);
});
});
env.currentRunner().execute();
expect(env.currentRunner().specs().length).toEqual(3);
});
});
describe('afterEach', function() {
it('should run after each spec for all suites', function () {
it('should run after each spec for all suites', function() {
var foo = 3;
env.afterEach(function () {
env.afterEach(function() {
foo = foo - 1;
});
env.describe('suite 1', function () {
env.describe('suite 1', function() {
env.it('test 1-1', function() {
this.expect(foo).toEqual(3);
expect(foo).toEqual(3);
});
env.it('test 1-2', function() {
this.expect(foo).toEqual(2);
expect(foo).toEqual(2);
});
});
env.describe('suite 2', function () {
env.describe('suite 2', function() {
env.it('test 2-1', function() {
this.expect(foo).toEqual(1);
expect(foo).toEqual(1);
});
});
env.currentRunner().execute();
var runnerResults = env.currentRunner().results();
expect(runnerResults.totalCount).toEqual(3);
expect(runnerResults.passedCount).toEqual(3);
});
it('should run after a failing spec', function () {
var afterEach = originalJasmine.createSpy();
env.afterEach(afterEach);
env.describe('suite', function () {
env.it('fails', function () {
this.explodes();
env.describe('suite',function() {
env.it('fails', function() {
this.fail();
});
}).execute();
@@ -120,103 +98,32 @@ describe('RunnerTest', function() {
});
});
it('should run child suites and specs and generate results when execute is called', function() {
env.describe('one suite description', function () {
env.it('should be a test', function() {
this.runs(function () {
this.expect(true).toEqual(true);
});
});
});
env.describe('another suite description', function () {
env.it('should be another test', function() {
this.runs(function () {
this.expect(true).toEqual(false);
});
});
});
env.currentRunner().execute();
var runnerResults = env.currentRunner().results();
expect(runnerResults.totalCount).toEqual(2);
expect(runnerResults.passedCount).toEqual(1);
expect(runnerResults.failedCount).toEqual(1);
});
it('should ignore suites that have been x\'d', function() {
env.xdescribe('one suite description', function () {
env.it('should be a test', function() {
this.runs(function () {
this.expect(true).toEqual(true);
});
});
});
env.describe('another suite description', function () {
env.it('should be another test', function() {
this.runs(function () {
this.expect(true).toEqual(false);
});
});
});
var disabledDescribe = jasmine.createSpy('xdescribe');
env.xdescribe('one suite description', disabledDescribe);
env.currentRunner().execute();
var runnerResults = env.currentRunner().results();
expect(runnerResults.totalCount).toEqual(1);
expect(runnerResults.passedCount).toEqual(0);
expect(runnerResults.failedCount).toEqual(1);
expect(disabledDescribe).not.toHaveBeenCalled();
});
it('should roll up results from all specs', function() {
env.describe('one suite description', function () {
env.it('should be a test', function() {
this.runs(function () {
this.expect(true).toEqual(true);
});
});
});
env.describe('another suite description', function () {
env.it('should be another test', function() {
this.runs(function () {
this.expect(true).toEqual(false);
});
});
});
env.currentRunner().execute();
var results = env.currentRunner().results();
expect(results.totalCount).toEqual(2);
expect(results.passedCount).toEqual(1);
expect(results.failedCount).toEqual(1);
});
describe('reporting', function () {
describe('reporting', function() {
var fakeReporter;
beforeEach(function () {
fakeReporter = originalJasmine.createSpyObj("fakeReporter", ["log", "reportRunnerStarting", "reportRunnerResults"]);
env.addReporter(fakeReporter);
});
it('should report runner results when the runner has completed running', function() {
env.describe('one suite description', function () {
env.describe('one suite description', function() {
env.it('should be a test', function() {
this.runs(function () {
this.runs(function() {
this.expect(true).toEqual(true);
});
});
});
env.describe('another suite description', function () {
env.describe('another suite description', function() {
env.it('should be another test', function() {
this.waits(200);
this.runs(function () {
this.runs(function() {
this.expect(true).toEqual(false);
});
});
@@ -225,10 +132,7 @@ describe('RunnerTest', function() {
env.currentRunner().execute();
expect(fakeReporter.reportRunnerResults).not.toHaveBeenCalled();
fakeTimer.tick(200);
//This blows up the JSApiReporter.
//expect(fakeReporter.reportRunnerResults).toHaveBeenCalledWith(env.currentRunner);
expect(fakeReporter.reportRunnerResults).toHaveBeenCalled();
expect(fakeReporter.reportRunnerResults.mostRecentCall.args[0].results()).toEqual(env.currentRunner().results());
expect(fakeReporter.reportRunnerResults).toHaveBeenCalledWith(env.currentRunner());
});
});
@@ -264,7 +168,8 @@ describe('RunnerTest', function() {
suite2 = env.describe("suite 2", function() {
});
});
suite3 = env.describe("suite 3", function() {});
suite3 = env.describe("suite 3", function() {
});
});
it("#suites should return a flat array of all suites, including nested suites", function() {

View File

@@ -576,66 +576,6 @@ describe("jasmine spec running", function () {
});
it("testBeforeAndAfterCallbacks", function () {
var suiteWithBefore = env.describe('one suite with a before', function () {
this.beforeEach(function () {
this.foo = 1;
});
env.it('should be a spec', function () {
this.runs(function() {
this.foo++;
this.expect(this.foo).toEqual(2);
});
});
env.it('should be another spec', function () {
this.runs(function() {
this.foo++;
this.expect(this.foo).toEqual(2);
});
});
});
suiteWithBefore.execute();
var suite = suiteWithBefore;
expect(suite.results().getItems()[0].passed()).toEqual(true); // "testBeforeAndAfterCallbacks: the first spec's foo should have been 2");
expect(suite.results().getItems()[1].passed()).toEqual(true); // "testBeforeAndAfterCallbacks: the second spec's this.foo should have been 2");
var foo = 1;
var suiteWithAfter = env.describe('one suite with an after_each', function () {
env.it('should be a spec with an after_each', function () {
this.expect(foo).toEqual(1);
foo++;
this.expect(foo).toEqual(2);
});
env.it('should be another spec with an after_each', function () {
this.expect(foo).toEqual(0);
foo++;
this.expect(foo).toEqual(1);
});
this.afterEach(function () {
foo = 0;
});
});
suiteWithAfter.execute();
suite = suiteWithAfter;
expect(suite.afterEach.length).toEqual(1);
expect(suite.results().getItems()[0].passed()).toEqual(true);
expect(suite.results().getItems()[1].passed()).toEqual(true);
expect(foo).toEqual(0);
});
it('#waits should allow consecutive waits calls', function () {
var foo = 0;
var waitsSuite = env.describe('suite that waits', function () {
@@ -873,85 +813,6 @@ describe("jasmine spec running", function () {
expect(secondSpecHasRun).toEqual(true);
});
it("testBeforeExecutesSafely", function() {
var report = "";
var suite = env.describe('before fails on first test, passes on second', function() {
var counter = 0;
this.beforeEach(function() {
counter++;
if (counter == 1) {
throw "before failure";
}
});
env.it("first should not run because before fails", function() {
this.runs(function() {
report += "first";
this.expect(true).toEqual(true);
});
});
env.it("second should run and pass because before passes", function() {
this.runs(function() {
report += "second";
this.expect(true).toEqual(true);
});
});
});
suite.execute();
expect(report).toEqual("firstsecond");
var suiteResults = suite.results();
expect(suiteResults.getItems()[0].getItems()[0].passed).toEqual(false);
expect(suiteResults.getItems()[1].getItems()[0].passed).toEqual(true);
});
it("testAfterExecutesSafely", function() {
var report = "";
var suite = env.describe('after fails on first test, then passes', function() {
var counter = 0;
this.afterEach(function() {
counter++;
if (counter == 1) {
throw "after failure";
}
});
env.it("first should run, expectation passes, but spec fails because after fails", function() {
this.runs(function() {
report += "first";
this.expect(true).toEqual(true);
});
});
env.it("second should run and pass because after passes", function() {
this.runs(function() {
report += "second";
this.expect(true).toEqual(true);
});
});
env.it("third should run and pass because after passes", function() {
this.runs(function() {
report += "third";
this.expect(true).toEqual(true);
});
});
});
suite.execute();
expect(report).toEqual("firstsecondthird"); // "all tests should run");
//After each errors should not go in spec results because it confuses the count.
var suiteResults = suite.results();
expect(suiteResults.getItems().length).toEqual(3, 'testAfterExecutesSafely should have results for three specs');
expect(suiteResults.getItems()[0].getItems()[0].passed).toEqual(true, "testAfterExecutesSafely 1st spec should pass");
expect(suiteResults.getItems()[1].getItems()[0].passed).toEqual(true, "testAfterExecutesSafely 2nd spec should pass");
expect(suiteResults.getItems()[2].getItems()[0].passed).toEqual(true, "testAfterExecutesSafely 3rd spec should pass");
expect(suiteResults.getItems()[0].getItems()[0].passed).toEqual(true, "testAfterExecutesSafely 1st result for 1st suite spec should pass");
expect(suiteResults.getItems()[0].getItems()[1].passed).toEqual(false, "testAfterExecutesSafely 2nd result for 1st suite spec should fail because afterEach failed");
expect(suiteResults.getItems()[1].getItems()[0].passed).toEqual(true, "testAfterExecutesSafely 2nd suite spec should pass");
expect(suiteResults.getItems()[2].getItems()[0].passed).toEqual(true, "testAfterExecutesSafely 3rd suite spec should pass");
});
it("should permit nested describes", function() {
var actions = [];
@@ -1115,101 +976,36 @@ describe("jasmine spec running", function () {
expect(nestedSpec.getFullName()).toEqual('Test Subject when under circumstance A and circumstance B behaves thusly.'); //, "Spec.fullName was incorrect: " + nestedSpec.getFullName());
});
it("should skip empty suites", function () {
env.describe('NonEmptySuite1', function() {
env.it('should pass', function() {
this.expect(true).toEqual(true);
});
env.describe('NestedEmptySuite', function() {
});
env.it('should pass', function() {
this.expect(true).toEqual(true);
});
});
env.describe('EmptySuite', function() {
});
env.describe('NonEmptySuite2', function() {
env.it('should pass', function() {
this.expect(true).toEqual(true);
});
});
env.execute();
var runnerResults = env.currentRunner_.results();
expect(runnerResults.totalCount).toEqual(3);
expect(runnerResults.passedCount).toEqual(3);
expect(runnerResults.failedCount).toEqual(0);
});
it("should bind 'this' to the running spec within the spec body", function() {
var spec;
var suite = env.describe('one suite description', function () {
env.it('should be a test with queuedFunctions', function() {
spec = this.runs(function() {
var specExecuted = jasmine.createSpy(), spec;
env.describe('Test Subject', function() {
spec = env.it('should be a test with queuedFunctions', function() {
this.runs(function() {
this.foo = 0;
expect(this.foo).toBe(0);
specExecuted();
});
this.runs(function() {
this.foo++;
});
this.runs(function() {
var that = this;
fakeTimer.setTimeout(function() {
that.foo++;
}, 250);
});
this.runs(function() {
this.expect(this.foo).toEqual(2);
});
this.waits(300);
this.runs(function() {
this.expect(this.foo).toEqual(2);
expect(this.foo).toBe(1);
specExecuted();
});
});
});
suite.execute();
fakeTimer.tick(600);
expect(spec.foo).toEqual(2);
var suiteResults = suite.results();
expect(suiteResults.getItems()[0].getItems().length).toEqual(2);
expect(suiteResults.getItems()[0].getItems()[0].passed).toEqual(false);
expect(suiteResults.getItems()[0].getItems()[1].passed).toEqual(true);
spec.execute();
expect(specExecuted.callCount).toBe(2);
});
it("shouldn't run disabled tests", function() {
var xitSpecWasRun = false;
var suite = env.describe('default current suite', function() {
env.xit('disabled spec').runs(function () {
xitSpecWasRun = true;
});
env.it('enabled spec').runs(function () {
var foo = 'bar';
expect(foo).toEqual('bar');
});
var disabledSpec = originalJasmine.createSpy('disabledSpec'),
suite = env.describe('default current suite', function() {
env.xit('disabled spec').runs(disabledSpec);
});
suite.execute();
expect(xitSpecWasRun).toEqual(false);
});
it('shouldn\'t execute specs in disabled suites', function() {
var spy = originalJasmine.createSpy();
var disabledSuite = env.xdescribe('a disabled suite', function() {
env.it('enabled spec, but should not be run', function() {
spy();
});
});
disabledSuite.execute();
expect(spy).not.toHaveBeenCalled();
expect(disabledSpec).not.toHaveBeenCalled();
});
it('#explodes should throw an exception when it is called inside a spec', function() {