Files
jasmine/spec/core/RunnerSpec.js
Davis W. Frank & Rajan Agaskar 779dee1211 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
2012-12-03 15:57:16 -08:00

186 lines
5.3 KiB
JavaScript

describe('RunnerTest', function() {
var fakeTimer;
var env;
beforeEach(function() {
env = new jasmine.Env();
env.updateInterval = 0;
fakeTimer = new jasmine.FakeTimer();
env.setTimeout = fakeTimer.setTimeout;
env.clearTimeout = fakeTimer.clearTimeout;
env.setInterval = fakeTimer.setInterval;
env.clearInterval = fakeTimer.clearInterval;
});
describe('beforeEach', function() {
it('should run before each spec for all suites', function() {
var foo;
env.beforeEach(function() {
foo = 0;
});
env.describe('suite 1', function() {
env.it('test 1-1', function() {
foo++;
expect(foo).toEqual(1);
});
env.it('test 1-2', function() {
foo++;
expect(foo).toEqual(1);
});
});
env.describe('suite 2', function() {
env.it('test 2-1', function() {
foo++;
expect(foo).toEqual(1);
});
});
env.currentRunner().execute();
});
it('should provide all specs', function() {
env.describe('suite 1', function() {
env.it('test 1-1', function() {
});
env.it('test 1-2', function() {
});
});
env.describe('suite 2', function() {
env.it('test 2-1', function() {
});
});
expect(env.currentRunner().specs().length).toEqual(3);
});
});
describe('afterEach', function() {
it('should run after each spec for all suites', function() {
var foo = 3;
env.afterEach(function() {
foo = foo - 1;
});
env.describe('suite 1', function() {
env.it('test 1-1', function() {
expect(foo).toEqual(3);
});
env.it('test 1-2', function() {
expect(foo).toEqual(2);
});
});
env.describe('suite 2', function() {
env.it('test 2-1', function() {
expect(foo).toEqual(1);
});
});
env.currentRunner().execute();
});
it('should run after a failing spec', function () {
var afterEach = originalJasmine.createSpy();
env.afterEach(afterEach);
env.describe('suite',function() {
env.it('fails', function() {
this.fail();
});
}).execute();
expect(afterEach).toHaveBeenCalled();
});
});
it('should ignore suites that have been x\'d', function() {
var disabledDescribe = jasmine.createSpy('xdescribe');
env.xdescribe('one suite description', disabledDescribe);
env.currentRunner().execute();
expect(disabledDescribe).not.toHaveBeenCalled();
});
describe('reporting', function() {
var fakeReporter;
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.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.waits(200);
this.runs(function() {
this.expect(true).toEqual(false);
});
});
});
env.currentRunner().execute();
expect(fakeReporter.reportRunnerResults).not.toHaveBeenCalled();
fakeTimer.tick(200);
expect(fakeReporter.reportRunnerResults).toHaveBeenCalledWith(env.currentRunner());
});
});
it("should report when the tests start running", function() {
var fakeReporter = originalJasmine.createSpyObj("fakeReporter", ["log", "reportRunnerStarting"]);
env.addReporter(fakeReporter);
var runner = new jasmine.Runner(env);
runner.arbitraryVariable = 'foo';
spyOn(runner.queue, 'start');
expect(fakeReporter.reportRunnerStarting).not.toHaveBeenCalled();
runner.execute();
expect(fakeReporter.reportRunnerStarting).toHaveBeenCalled();
var reportedRunner = fakeReporter.reportRunnerStarting.mostRecentCall.args[0];
expect(reportedRunner.arbitraryVariable).toEqual('foo');
expect(runner.queue.start).toHaveBeenCalled();
});
describe("when suites are nested", function() {
var suite1, suite2, suite3;
function suiteNames(suites) {
var suiteDescriptions = [];
for (var i = 0; i < suites.length; i++) {
suiteDescriptions.push(suites[i].getFullName());
}
return suiteDescriptions;
}
beforeEach(function() {
suite1 = env.describe("suite 1", function() {
suite2 = env.describe("suite 2", function() {
});
});
suite3 = env.describe("suite 3", function() {
});
});
it("#suites should return a flat array of all suites, including nested suites", function() {
var suites = env.currentRunner().suites();
expect(suiteNames(suites)).toEqual([suite1.getFullName(), suite2.getFullName(), suite3.getFullName()]);
});
it("#topLevelSuites should return a flat array of all top-level suites only", function() {
var suites = env.currentRunner().topLevelSuites();
expect(suiteNames(suites)).toEqual([suite1.getFullName(), suite3.getFullName()]);
});
});
});