Support pending specs with:

- xit
- it with a null function body ( it("should be pending");
- calling pending() inside a spec
- having a spec without any expectations

Pending and Filtered specs now call Reporter interface specStarted so that reporting acts as expected.
Pending and Filtered spec names are present and styled in the HTML reporter

Using xit used to disable a spec. Disabling is now just when a spec is filtered out at run time (usually w/ the reporter).

Suites are still disabled with xdescribe and means its specs are never executed.
This commit is contained in:
Dan Hansen and Davis W. Frank
2013-02-28 12:04:29 -08:00
parent d6da13a8dd
commit b7af6abca5
20 changed files with 346 additions and 126 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
source :rubygems source :rubygems
gem "rake" gem "rake"
gem "jasmine", :git => 'https://github.com/pivotal/jasmine-gem.git', :branch => '2_0' gem "jasmine", :git => 'https://github.com/pivotal/jasmine-gem.git', :branch => '2_0'
#gem "jasmine", path: "/Users/pivotal/workspace/jasmine-gem"
unless ENV["TRAVIS"] unless ENV["TRAVIS"]
group :debug do group :debug do
gem 'debugger' gem 'debugger'
+4
View File
@@ -30,6 +30,10 @@
return env.expect(actual); return env.expect(actual);
}, },
pending: function() {
return env.pending();
},
addMatchers: function(matchers) { addMatchers: function(matchers) {
return env.addMatchers(matchers); return env.addMatchers(matchers);
}, },
+9 -2
View File
@@ -8,6 +8,7 @@ jasmine.HtmlReporter = function(options) {
startTime, startTime,
specsExecuted = 0, specsExecuted = 0,
failureCount = 0, failureCount = 0,
pendingSpecCount = 0,
htmlReporterMain, htmlReporterMain,
symbols; symbols;
@@ -85,6 +86,10 @@ jasmine.HtmlReporter = function(options) {
failures.push(failure); failures.push(failure);
} }
if(result.status == "pending") {
pendingSpecCount++;
}
}; };
this.jasmineDone = function() { this.jasmineDone = function() {
@@ -116,8 +121,10 @@ jasmine.HtmlReporter = function(options) {
) )
); );
} }
var statusBarMessage = "" + pluralize("spec", specsExecuted) + ", " + pluralize("failure", failureCount), var statusBarMessage = "" + pluralize("spec", specsExecuted) + ", " + pluralize("failure", failureCount);
statusBarClassName = "bar " + ((failureCount > 0) ? "failed" : "passed"); if(pendingSpecCount) { statusBarMessage += ", " + pluralize("pending spec", pendingSpecCount); }
var statusBarClassName = "bar " + ((failureCount > 0) ? "failed" : "passed");
alert.appendChild(createDom("span", {className: statusBarClassName}, statusBarMessage)); alert.appendChild(createDom("span", {className: statusBarClassName}, statusBarMessage));
var results = find(".results")[0]; var results = find(".results")[0];
+3 -2
View File
@@ -18,8 +18,8 @@ body { background-color: #eeeeee; padding: 0; margin: 5px; overflow-y: scroll; }
.html-reporter .symbol-summary li.failed:before { color: #b03911; content: "x"; font-weight: bold; margin-left: -1px; } .html-reporter .symbol-summary li.failed:before { color: #b03911; content: "x"; font-weight: bold; margin-left: -1px; }
.html-reporter .symbol-summary li.disabled { font-size: 14px; } .html-reporter .symbol-summary li.disabled { font-size: 14px; }
.html-reporter .symbol-summary li.disabled:before { color: #bababa; content: "\02022"; } .html-reporter .symbol-summary li.disabled:before { color: #bababa; content: "\02022"; }
.html-reporter .symbol-summary li.pending { line-height: 11px; } .html-reporter .symbol-summary li.pending { line-height: 17px; }
.html-reporter .symbol-summary li.pending:before { color: #aaaaaa; content: "-"; } .html-reporter .symbol-summary li.pending:before { color: #ba9d37; content: "*"; }
.html-reporter .exceptions { color: #fff; float: right; margin-top: 5px; margin-right: 5px; } .html-reporter .exceptions { color: #fff; float: right; margin-top: 5px; margin-right: 5px; }
.html-reporter .bar { line-height: 28px; font-size: 14px; display: block; color: #eee; } .html-reporter .bar { line-height: 28px; font-size: 14px; display: block; color: #eee; }
.html-reporter .bar.failed { background-color: #b03911; } .html-reporter .bar.failed { background-color: #b03911; }
@@ -43,6 +43,7 @@ body { background-color: #eeeeee; padding: 0; margin: 5px; overflow-y: scroll; }
.html-reporter .summary ul.suite { margin-top: 7px; margin-bottom: 7px; } .html-reporter .summary ul.suite { margin-top: 7px; margin-bottom: 7px; }
.html-reporter .summary li.passed a { color: #5e7d00; } .html-reporter .summary li.passed a { color: #5e7d00; }
.html-reporter .summary li.failed a { color: #b03911; } .html-reporter .summary li.failed a { color: #b03911; }
.html-reporter .summary li.pending a { color: #ba9d37; }
.html-reporter .description + .suite { margin-top: 0; } .html-reporter .description + .suite { margin-top: 0; }
.html-reporter .suite { margin-top: 14px; } .html-reporter .suite { margin-top: 14px; }
.html-reporter .suite a { color: #333333; } .html-reporter .suite a { color: #333333; }
+42 -15
View File
@@ -599,6 +599,10 @@ jasmine.buildExpectationResult = function(options) {
return catchExceptions; return catchExceptions;
}; };
this.catchException = function(e){
return jasmine.Spec.isPendingSpecException(e) || catchExceptions;
};
var maximumSpecCallbackDepth = 100; var maximumSpecCallbackDepth = 100;
var currentSpecCallbackDepth = 0; var currentSpecCallbackDepth = 0;
@@ -613,13 +617,12 @@ jasmine.buildExpectationResult = function(options) {
} }
var queueRunnerFactory = function(options) { var queueRunnerFactory = function(options) {
options.catchingExceptions = self.catchingExceptions; options.catchException = self.catchException;
options.encourageGC = options.encourageGarbageCollection || encourageGarbageCollection; options.encourageGC = options.encourageGarbageCollection || encourageGarbageCollection;
new jasmine.QueueRunner(options).run(options.fns, 0); new jasmine.QueueRunner(options).run(options.fns, 0);
}; };
var totalSpecsDefined = 0; var totalSpecsDefined = 0;
this.specFactory = function(description, fn, suite) { this.specFactory = function(description, fn, suite) {
totalSpecsDefined++; totalSpecsDefined++;
@@ -824,7 +827,7 @@ jasmine.buildExpectationResult = function(options) {
// TODO: move this to closure // TODO: move this to closure
jasmine.Env.prototype.xit = function(description, fn) { jasmine.Env.prototype.xit = function(description, fn) {
var spec = this.it(description, fn); var spec = this.it(description, fn);
spec.disable(); spec.pend();
return spec; return spec;
}; };
@@ -838,6 +841,11 @@ jasmine.buildExpectationResult = function(options) {
this.currentSuite.afterEach(afterEachFunction); this.currentSuite.afterEach(afterEachFunction);
}; };
// TODO: move this to closure
jasmine.Env.prototype.pending = function() {
throw new Error(jasmine.Spec.pendingSpecExceptionMessage);
};
// TODO: Still needed? // TODO: Still needed?
jasmine.Env.prototype.currentRunner = function() { jasmine.Env.prototype.currentRunner = function() {
return this.topSuite; return this.topSuite;
@@ -1014,12 +1022,12 @@ jasmine.JsApiReporter = function(jasmine) {
}; };
var specs = []; var specs = [];
this.specStarted = function(result) { this.specStarted = function(result) { };
this.specDone = function(result) {
specs.push(result); specs.push(result);
}; };
this.specDone = function(result) { };
this.specResults = function(index, length) { this.specResults = function(index, length) {
return specs.slice(index, index + length); return specs.slice(index, index + length);
}; };
@@ -1558,7 +1566,7 @@ jasmine.QueueRunner = function(attrs) {
this.onComplete = attrs.onComplete || function() {}; this.onComplete = attrs.onComplete || function() {};
this.encourageGC = attrs.encourageGC || function(fn) {fn()}; this.encourageGC = attrs.encourageGC || function(fn) {fn()};
this.onException = attrs.onException || function() {}; this.onException = attrs.onException || function() {};
this.catchingExceptions = attrs.catchingExceptions || function() { return true; }; this.catchException = attrs.catchException || function() { return true; };
}; };
jasmine.QueueRunner.prototype.execute = function() { jasmine.QueueRunner.prototype.execute = function() {
@@ -1585,7 +1593,7 @@ jasmine.QueueRunner.prototype.run = function(fns, index) {
fn(); fn();
} catch (e) { } catch (e) {
self.onException(e); self.onException(e);
if (!self.catchingExceptions()) { if (!self.catchException(e)) {
//TODO: set a var when we catch an exception and //TODO: set a var when we catch an exception and
//use a finally block to close the loop in a nice way.. //use a finally block to close the loop in a nice way..
throw e; throw e;
@@ -1606,10 +1614,14 @@ jasmine.Spec = function(attrs) {
this.onStart = attrs.onStart || function() {}; this.onStart = attrs.onStart || function() {};
this.exceptionFormatter = attrs.exceptionFormatter || function() {}; this.exceptionFormatter = attrs.exceptionFormatter || function() {};
this.getSpecName = attrs.getSpecName || function() { return ''; }; this.getSpecName = attrs.getSpecName || function() { return ''; };
this.expectationResultFactory = attrs.expectationResultFactory || function() {}; this.expectationResultFactory = attrs.expectationResultFactory || function() { };
this.queueRunner = attrs.queueRunner || { execute: function() {}}; this.queueRunner = attrs.queueRunner || function() {};
this.catchingExceptions = attrs.catchingExceptions || function() { return true; }; this.catchingExceptions = attrs.catchingExceptions || function() { return true; };
if (!this.fn) {
this.pend();
}
this.result = { this.result = {
id: this.id, id: this.id,
description: this.description, description: this.description,
@@ -1634,7 +1646,9 @@ jasmine.Spec.prototype.expect = function(actual) {
jasmine.Spec.prototype.execute = function(onComplete) { jasmine.Spec.prototype.execute = function(onComplete) {
var self = this; var self = this;
if (this.disabled) { this.onStart(this);
if (this.markedPending || this.disabled) {
complete(); complete();
return; return;
} }
@@ -1643,10 +1657,14 @@ jasmine.Spec.prototype.execute = function(onComplete) {
afters = this.afterFns() || []; afters = this.afterFns() || [];
var allFns = befores.concat(this.fn).concat(afters); var allFns = befores.concat(this.fn).concat(afters);
this.onStart(this);
this.queueRunner({ this.queueRunner({
fns: allFns, fns: allFns,
onException: function(e) { onException: function(e) {
if (jasmine.Spec.isPendingSpecException(e)) {
self.pend();
return;
}
self.addExpectationResult(false, { self.addExpectationResult(false, {
matcherName: "", matcherName: "",
passed: false, passed: false,
@@ -1672,13 +1690,17 @@ jasmine.Spec.prototype.disable = function() {
this.disabled = true; this.disabled = true;
}; };
jasmine.Spec.prototype.pend = function() {
this.markedPending = true;
};
jasmine.Spec.prototype.status = function() { jasmine.Spec.prototype.status = function() {
if (this.disabled) { if (this.disabled) {
return 'disabled'; return 'disabled';
} }
if (!this.encounteredExpectations) { if (this.markedPending || !this.encounteredExpectations) {
return null; return 'pending';
} }
if (this.result.failedExpectations.length > 0) { if (this.result.failedExpectations.length > 0) {
@@ -1691,7 +1713,12 @@ jasmine.Spec.prototype.status = function() {
jasmine.Spec.prototype.getFullName = function() { jasmine.Spec.prototype.getFullName = function() {
return this.getSpecName(this); return this.getSpecName(this);
}; };
jasmine.Suite = function(attrs) {
jasmine.Spec.pendingSpecExceptionMessage = "=> marked Pending";
jasmine.Spec.isPendingSpecException = function(e) {
return e.message.indexOf(jasmine.Spec.pendingSpecExceptionMessage) === 0;
};jasmine.Suite = function(attrs) {
this.env = attrs.env; this.env = attrs.env;
this.id = attrs.id; this.id = attrs.id;
this.parentSuite = attrs.parentSuite; this.parentSuite = attrs.parentSuite;
+15 -7
View File
@@ -58,6 +58,16 @@ describe("ConsoleReporter", function() {
expect(out.getOutput()).toEqual("F"); expect(out.getOutput()).toEqual("F");
}); });
it("reports a pending spec as a '*'", function() {
var reporter = new jasmine.ConsoleReporter({
print: out.print
});
reporter.specDone({status: "pending"});
expect(out.getOutput()).toEqual("*");
});
it("reports a summary when done (singluar spec and time)", function() { it("reports a summary when done (singluar spec and time)", function() {
var fakeNow = jasmine.createSpy('fake Date.now'), var fakeNow = jasmine.createSpy('fake Date.now'),
reporter = new jasmine.ConsoleReporter({ reporter = new jasmine.ConsoleReporter({
@@ -75,6 +85,7 @@ describe("ConsoleReporter", function() {
reporter.jasmineDone(); reporter.jasmineDone();
expect(out.getOutput()).toMatch(/1 spec, 0 failures/); expect(out.getOutput()).toMatch(/1 spec, 0 failures/);
expect(out.getOutput()).not.toMatch(/0 pending specs/);
expect(out.getOutput()).toMatch("Finished in 1 second\n"); expect(out.getOutput()).toMatch("Finished in 1 second\n");
}); });
@@ -88,6 +99,7 @@ describe("ConsoleReporter", function() {
fakeNow.andReturn(500); fakeNow.andReturn(500);
reporter.jasmineStarted(); reporter.jasmineStarted();
reporter.specDone({status: "passed"}); reporter.specDone({status: "passed"});
reporter.specDone({status: "pending"});
reporter.specDone({ reporter.specDone({
status: "failed", status: "failed",
description: "with a failing spec", description: "with a failing spec",
@@ -98,9 +110,7 @@ describe("ConsoleReporter", function() {
message: "Expected true to be false.", message: "Expected true to be false.",
expected: false, expected: false,
actual: true, actual: true,
trace: { stack: "foo\nbar\nbaz"
stack: "foo\nbar\nbaz"
}
} }
] ]
}); });
@@ -110,7 +120,7 @@ describe("ConsoleReporter", function() {
fakeNow.andReturn(600); fakeNow.andReturn(600);
reporter.jasmineDone(); reporter.jasmineDone();
expect(out.getOutput()).toMatch(/2 specs, 1 failure/); expect(out.getOutput()).toMatch(/3 specs, 1 failure, 1 pending spec/);
expect(out.getOutput()).toMatch("Finished in 0.1 seconds\n"); expect(out.getOutput()).toMatch("Finished in 0.1 seconds\n");
}); });
@@ -131,9 +141,7 @@ describe("ConsoleReporter", function() {
message: "Expected true to be false.", message: "Expected true to be false.",
expected: false, expected: false,
actual: true, actual: true,
trace: { stack: "foo bar baz"
stack: "foo bar baz"
}
} }
] ]
}); });
+24 -1
View File
@@ -163,6 +163,29 @@ describe("Env", function() {
}); });
}); });
}); });
describe("#catchException", function() {
it("returns true if the exception is a pending spec exception", function() {
env.catchExceptions(false);
expect(env.catchException(new Error(jasmine.Spec.pendingSpecExceptionMessage))).toBe(true);
});
it("returns false if the exception is not a pending spec exception and not catching exceptions", function() {
env.catchExceptions(false);
expect(env.catchException(new Error("external error"))).toBe(false);
expect(env.catchException(new Error(jasmine.Spec.pendingSpecExceptionMessage))).toBe(true);
});
});
describe("#pending", function() {
it("throws the Pending Spec exception", function() {
expect(function() {
env.pending();
}).toThrow(jasmine.Spec.pendingSpecExceptionMessage);
});
});
}); });
describe("Env (integration)", function() { describe("Env (integration)", function() {
@@ -294,7 +317,7 @@ describe("Env (integration)", function() {
env.expect(true).toBe(true); env.expect(true).toBe(true);
}); });
env.describe("with a nested suite", function() { env.describe("with a nested suite", function() {
env.xit("with a disabled spec", function() { env.xit("with a pending spec", function() {
env.expect(true).toBe(true); env.expect(true).toBe(true);
}); });
env.it("with a spec", function() { env.it("with a spec", function() {
+2 -22
View File
@@ -149,26 +149,6 @@ describe("JsApiReporter", function() {
expect(suites).toEqual({123: {id: 123, description: "A suite", status: 'passed'}}); expect(suites).toEqual({123: {id: 123, description: "A suite", status: 'passed'}});
}); });
it("tracks a spec", function() {
var reporter = new jasmine.JsApiReporter(),
result = {
id: 123,
description: "A spec"
};
reporter.specStarted(result);
var specs = reporter.specs();
expect(specs).toEqual([result]);
result.status = "passed";
reporter.specDone(result);
expect(specs).toEqual([result]);
});
describe("#specResults", function() { describe("#specResults", function() {
var reporter, specResult1, specResult2; var reporter, specResult1, specResult2;
beforeEach(function() { beforeEach(function() {
@@ -182,8 +162,8 @@ describe("JsApiReporter", function() {
description: "Another spec" description: "Another spec"
}; };
reporter.specStarted(specResult1); reporter.specDone(specResult1);
reporter.specStarted(specResult2); reporter.specDone(specResult2);
}); });
it("should return a slice of results", function() { it("should return a slice of results", function() {
+1 -1
View File
@@ -96,7 +96,7 @@ describe("QueueRunner", function() {
}, },
queueRunner = new jasmine.QueueRunner({ queueRunner = new jasmine.QueueRunner({
fns: [fn], fns: [fn],
catchingExceptions: function() { return false; } catchException: function(e) { return false; }
}); });
expect(function() { queueRunner.execute(); }).toThrow(); expect(function() { queueRunner.execute(); }).toThrow();
+10 -7
View File
@@ -224,7 +224,7 @@ describe("jasmine spec running", function () {
var specInADisabledSuite = originalJasmine.createSpy("specInADisabledSuite"), var specInADisabledSuite = originalJasmine.createSpy("specInADisabledSuite"),
suite = env.describe('A Suite', function() { suite = env.describe('A Suite', function() {
env.xdescribe('with a disabled suite', function(){ env.xdescribe('with a disabled suite', function(){
env.it('disabled spec', specInADisabledSuite); env.it('spec inside a disabled suite', specInADisabledSuite);
}); });
}); });
@@ -233,15 +233,18 @@ describe("jasmine spec running", function () {
expect(specInADisabledSuite).not.toHaveBeenCalled(); expect(specInADisabledSuite).not.toHaveBeenCalled();
}); });
it("shouldn't run disabled tests", function() { it("should set all pending specs to pending when a suite is run", function() {
var disabledSpec = originalJasmine.createSpy('disabledSpec'), var pendingSpec,
suite = env.describe('default current suite', function() { suite = env.describe('default current suite', function() {
env.xit('disabled spec', disabledSpec); pendingSpec = env.it("I am a pending spec");
}); });
suite.execute(); suite.execute();
expect(disabledSpec).not.toHaveBeenCalled();
expect(pendingSpec.status()).toBe("pending");
}); });
// TODO: is this useful? It doesn't catch syntax errors // TODO: is this useful? It doesn't catch syntax errors
xit("should recover gracefully when there are errors in describe functions", function() { xit("should recover gracefully when there are errors in describe functions", function() {
var specs = []; var specs = [];
+70 -18
View File
@@ -1,5 +1,17 @@
describe("Spec", function() { describe("Spec", function() {
it("#isPendingSpecException returns true for a pending spec exception", function() {
var e = new Error(jasmine.Spec.pendingSpecExceptionMessage);
expect(jasmine.Spec.isPendingSpecException(e)).toBe(true);
});
it("#isPendingSpecException returns true for a pending spec exception", function() {
var e = new Error("foo");
expect(jasmine.Spec.isPendingSpecException(e)).toBe(false);
});
it("delegates execution to a QueueRunner", function() { it("delegates execution to a QueueRunner", function() {
var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'), var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
spec = new jasmine.Spec({ spec = new jasmine.Spec({
@@ -78,9 +90,24 @@ describe("Spec", function() {
expect(allSpecFns).toEqual([before, fn, after]); expect(allSpecFns).toEqual([before, fn, after]);
}); });
it("can be disabled, but still calls callbacks", function() { it("is marked pending if created without a function body", function() {
var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'), var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
startCallback = originalJasmine.createSpy('startCallback'),
resultCallback = originalJasmine.createSpy('resultCallback'),
spec = new jasmine.Spec({
onStart: startCallback,
fn: null,
resultCallback: resultCallback,
queueRunner: fakeQueueRunner
});
expect(spec.status()).toBe('pending');
});
it("can be disabled, but still calls callbacks", function() {
var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
startCallback = originalJasmine.createSpy('startCallback'), startCallback = originalJasmine.createSpy('startCallback'),
specBody = originalJasmine.createSpy('specBody'), specBody = originalJasmine.createSpy('specBody'),
resultCallback = originalJasmine.createSpy('resultCallback'), resultCallback = originalJasmine.createSpy('resultCallback'),
@@ -97,41 +124,39 @@ describe("Spec", function() {
spec.execute(); spec.execute();
expect(startCallback).not.toHaveBeenCalled();
expect(fakeQueueRunner).not.toHaveBeenCalled(); expect(fakeQueueRunner).not.toHaveBeenCalled();
expect(specBody).not.toHaveBeenCalled(); expect(specBody).not.toHaveBeenCalled();
expect(startCallback).toHaveBeenCalled();
expect(resultCallback).toHaveBeenCalled(); expect(resultCallback).toHaveBeenCalled();
}); });
it("should call the results callback on execution complete", function() { it("can be marked pending, but still calls callbacks when executed", function() {
var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'), var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
startCallback = originalJasmine.createSpy('startCallback'), startCallback = originalJasmine.createSpy('startCallback'),
specBody = originalJasmine.createSpy('specBody'),
resultCallback = originalJasmine.createSpy('resultCallback'), resultCallback = originalJasmine.createSpy('resultCallback'),
spec = new jasmine.Spec({ spec = new jasmine.Spec({
onStart:startCallback, onStart: startCallback,
fn: specBody,
resultCallback: resultCallback, resultCallback: resultCallback,
description: "with a spec", description: "with a spec",
getSpecName: function() { return "a suite with a spec"}, getSpecName: function() {
return "a suite with a spec"
},
queueRunner: fakeQueueRunner queueRunner: fakeQueueRunner
}); });
spec.disable(); spec.pend();
expect(spec.status()).toBe('disabled'); expect(spec.status()).toBe('pending');
spec.execute(); spec.execute();
expect(startCallback).not.toHaveBeenCalled();
expect(fakeQueueRunner).not.toHaveBeenCalled(); expect(fakeQueueRunner).not.toHaveBeenCalled();
expect(specBody).not.toHaveBeenCalled();
expect(startCallback).toHaveBeenCalled();
expect(resultCallback).toHaveBeenCalledWith({ expect(resultCallback).toHaveBeenCalledWith({
id: spec.id, id: spec.id,
status: 'disabled', status: 'pending',
description: 'with a spec', description: 'with a spec',
fullName: 'a suite with a spec', fullName: 'a suite with a spec',
failedExpectations: [] failedExpectations: []
@@ -152,19 +177,28 @@ describe("Spec", function() {
expect(done).toHaveBeenCalled(); expect(done).toHaveBeenCalled();
}); });
it("#status returns null by default", function() { it("#status returns pending by default", function() {
var spec = new jasmine.Spec({}); var spec = new jasmine.Spec({fn: jasmine.createSpy("spec body")});
expect(spec.status()).toBeNull(); expect(spec.status()).toEqual('pending');
});
it("#status returns pending if no expectations were encountered", function() {
var specBody = jasmine.createSpy("spec body"),
spec = new jasmine.Spec({fn: specBody});
spec.execute();
expect(spec.status()).toEqual('pending');
}); });
it("#status returns passed if all expectations in the spec have passed", function() { it("#status returns passed if all expectations in the spec have passed", function() {
var spec = new jasmine.Spec({}); var spec = new jasmine.Spec({fn: jasmine.createSpy("spec body")});
spec.addExpectationResult(true); spec.addExpectationResult(true);
expect(spec.status()).toBe('passed'); expect(spec.status()).toBe('passed');
}); });
it("#status returns failed if any expectations in the spec have failed", function() { it("#status returns failed if any expectations in the spec have failed", function() {
var spec = new jasmine.Spec({}); var spec = new jasmine.Spec({ fn: jasmine.createSpy("spec body") });
spec.addExpectationResult(true); spec.addExpectationResult(true);
spec.addExpectationResult(false); spec.addExpectationResult(false);
expect(spec.status()).toBe('failed'); expect(spec.status()).toBe('failed');
@@ -181,4 +215,22 @@ describe("Spec", function() {
expect(spec.getFullName()).toBe('expected val'); expect(spec.getFullName()).toBe('expected val');
}); });
describe("when a spec is marked pending during execution", function() {
it("should mark the spec as pending", function() {
var fakeQueueRunner = function(opts) {
opts.onException(new Error(jasmine.Spec.pendingSpecExceptionMessage));
},
spec = new jasmine.Spec({
description: 'my test',
id: 'some-id',
fn: function() { },
queueRunner: fakeQueueRunner
});
spec.execute();
expect(spec.status()).toEqual("pending");
});
});
}); });
+83 -21
View File
@@ -37,8 +37,7 @@ describe("New HtmlReporter", function() {
var env = new jasmine.Env(), var env = new jasmine.Env(),
container = document.createElement("div"), container = document.createElement("div"),
getContainer = function() { return container; }, getContainer = function() { return container; },
getContainer = function() { return container; }, reporter = new jasmine.HtmlReporter({
reporter = new jasmine.HtmlReporter({
env: env, env: env,
getContainer: getContainer, getContainer: getContainer,
createElement: function() { return document.createElement.apply(document, arguments); }, createElement: function() { return document.createElement.apply(document, arguments); },
@@ -54,12 +53,31 @@ describe("New HtmlReporter", function() {
expect(specEl.getAttribute("id")).toEqual("spec_789"); expect(specEl.getAttribute("id")).toEqual("spec_789");
}); });
it("reports the status symbol of a pending spec", function() {
var env = new jasmine.Env(),
container = document.createElement("div"),
getContainer = function() { return container; },
reporter = new jasmine.HtmlReporter({
env: env,
getContainer: getContainer,
createElement: function() { return document.createElement.apply(document, arguments); },
createTextNode: function() { return document.createTextNode.apply(document, arguments); }
});
reporter.initialize();
reporter.specDone({id: 789, status: "pending"});
var statuses = container.getElementsByClassName('symbol-summary')[0];
var specEl = statuses.getElementsByTagName('li')[0];
expect(specEl.getAttribute("class")).toEqual("pending");
expect(specEl.getAttribute("id")).toEqual("spec_789");
});
it("reports the status symbol of a passing spec", function() { it("reports the status symbol of a passing spec", function() {
var env = new jasmine.Env(), var env = new jasmine.Env(),
container = document.createElement("div"), container = document.createElement("div"),
getContainer = function() { return container; }, getContainer = function() { return container; },
getContainer = function() { return container; }, reporter = new jasmine.HtmlReporter({
reporter = new jasmine.HtmlReporter({
env: env, env: env,
getContainer: getContainer, getContainer: getContainer,
createElement: function() { return document.createElement.apply(document, arguments); }, createElement: function() { return document.createElement.apply(document, arguments); },
@@ -79,8 +97,7 @@ describe("New HtmlReporter", function() {
var env = new jasmine.Env(), var env = new jasmine.Env(),
container = document.createElement("div"), container = document.createElement("div"),
getContainer = function() { return container; }, getContainer = function() { return container; },
getContainer = function() { return container; }, reporter = new jasmine.HtmlReporter({
reporter = new jasmine.HtmlReporter({
env: env, env: env,
getContainer: getContainer, getContainer: getContainer,
createElement: function() { return document.createElement.apply(document, arguments); }, createElement: function() { return document.createElement.apply(document, arguments); },
@@ -108,7 +125,7 @@ describe("New HtmlReporter", function() {
fakeNow = jasmine.createSpy('fake Date.now'), fakeNow = jasmine.createSpy('fake Date.now'),
container = document.createElement("div"), container = document.createElement("div"),
getContainer = function() { return container; }, getContainer = function() { return container; },
reporter = new jasmine.HtmlReporter({ reporter = new jasmine.HtmlReporter({
env: env, env: env,
getContainer: getContainer, getContainer: getContainer,
now: fakeNow, now: fakeNow,
@@ -132,7 +149,7 @@ describe("New HtmlReporter", function() {
var env = new jasmine.Env(), var env = new jasmine.Env(),
container = document.createElement("div"), container = document.createElement("div"),
getContainer = function() { return container; }, getContainer = function() { return container; },
reporter = new jasmine.HtmlReporter({ reporter = new jasmine.HtmlReporter({
env: env, env: env,
getContainer: getContainer, getContainer: getContainer,
createElement: function() { return document.createElement.apply(document, arguments); }, createElement: function() { return document.createElement.apply(document, arguments); },
@@ -300,12 +317,12 @@ describe("New HtmlReporter", function() {
env = new jasmine.Env(); env = new jasmine.Env();
container = document.createElement("div"); container = document.createElement("div");
getContainer = function() { return container; }, getContainer = function() { return container; },
reporter = new jasmine.HtmlReporter({ reporter = new jasmine.HtmlReporter({
env: env, env: env,
getContainer: getContainer, getContainer: getContainer,
createElement: function() { return document.createElement.apply(document, arguments); }, createElement: function() { return document.createElement.apply(document, arguments); },
createTextNode: function() { return document.createTextNode.apply(document, arguments); } createTextNode: function() { return document.createTextNode.apply(document, arguments); }
}); });
reporter.initialize(); reporter.initialize();
reporter.jasmineStarted({}); reporter.jasmineStarted({});
@@ -338,6 +355,51 @@ describe("New HtmlReporter", function() {
expect(specFailure.childNodes.length).toEqual(0); expect(specFailure.childNodes.length).toEqual(0);
}); });
it("reports no pending specs", function() {
var alert = container.getElementsByClassName("alert")[0];
var alertBars = alert.getElementsByClassName("bar");
expect(alertBars[0].innerHTML).not.toMatch(/pending spec[s]/);
});
});
describe("and there are pending specs", function() {
var env, container, reporter;
beforeEach(function() {
env = new jasmine.Env();
container = document.createElement("div");
getContainer = function() { return container; },
reporter = new jasmine.HtmlReporter({
env: env,
getContainer: getContainer,
createElement: function() { return document.createElement.apply(document, arguments); },
createTextNode: function() { return document.createTextNode.apply(document, arguments); }
});
reporter.initialize();
reporter.jasmineStarted({});
reporter.specDone({
id: 123,
description: "with a spec",
fullName: "A Suite with a spec",
status: "pending"
});
reporter.jasmineDone();
});
it("reports the pending specs count", function() {
var alert = container.getElementsByClassName("alert")[0];
var alertBars = alert.getElementsByClassName("bar");
expect(alertBars[0].innerHTML).toMatch(/1 spec, 0 failures, 1 pending spec/);
});
it("reports no failure details", function() {
var specFailure = container.getElementsByClassName("failures")[0];
expect(specFailure.childNodes.length).toEqual(0);
});
}); });
describe("and some tests fail", function() { describe("and some tests fail", function() {
@@ -345,14 +407,14 @@ describe("New HtmlReporter", function() {
beforeEach(function() { beforeEach(function() {
env = new jasmine.Env(); env = new jasmine.Env();
container = document.createElement("div"); container = document.createElement("div"),
getContainer = function() { return container; }, getContainer = function() { return container; },
reporter = new jasmine.HtmlReporter({ reporter = new jasmine.HtmlReporter({
env: env, env: env,
getContainer: getContainer, getContainer: getContainer,
createElement: function() { return document.createElement.apply(document, arguments); }, createElement: function() { return document.createElement.apply(document, arguments); },
createTextNode: function() { return document.createTextNode.apply(document, arguments); } createTextNode: function() { return document.createTextNode.apply(document, arguments); }
}); });
reporter.initialize(); reporter.initialize();
reporter.jasmineStarted({}); reporter.jasmineStarted({});
+14 -1
View File
@@ -7,6 +7,7 @@ jasmine.ConsoleReporter = function(options) {
specCount, specCount,
failureCount, failureCount,
failedSpecs = [], failedSpecs = [],
pendingCount,
ansi = { ansi = {
green: '\033[32m', green: '\033[32m',
red: '\033[31m', red: '\033[31m',
@@ -18,6 +19,7 @@ jasmine.ConsoleReporter = function(options) {
startTime = now(); startTime = now();
specCount = 0; specCount = 0;
failureCount = 0; failureCount = 0;
pendingCount = 0;
print("Started"); print("Started");
printNewline(); printNewline();
}; };
@@ -33,6 +35,11 @@ jasmine.ConsoleReporter = function(options) {
printNewline(); printNewline();
var specCounts = specCount + " " + plural("spec", specCount) + ", " + var specCounts = specCount + " " + plural("spec", specCount) + ", " +
failureCount + " " + plural("failure", failureCount); failureCount + " " + plural("failure", failureCount);
if (pendingCount) {
specCounts += ", " + pendingCount + " pending " + plural("spec", pendingCount);
}
print(specCounts); print(specCounts);
printNewline(); printNewline();
@@ -47,6 +54,12 @@ jasmine.ConsoleReporter = function(options) {
this.specDone = function(result) { this.specDone = function(result) {
specCount++; specCount++;
if(result.status == "pending") {
pendingCount++;
print(colored("yellow", "*"));
return;
}
if (result.status == "passed") { if (result.status == "passed") {
print(colored("green", '.')); print(colored("green", '.'));
return; return;
@@ -97,7 +110,7 @@ jasmine.ConsoleReporter = function(options) {
for (var i = 0; i < result.failedExpectations.length; i++) { for (var i = 0; i < result.failedExpectations.length; i++) {
var failedExpectation = result.failedExpectations[i]; var failedExpectation = result.failedExpectations[i];
printNewline(); printNewline();
print(indent(failedExpectation.trace.stack, 2)); print(indent(failedExpectation.stack, 2));
} }
printNewline(); printNewline();
+11 -3
View File
@@ -97,6 +97,10 @@
return catchExceptions; return catchExceptions;
}; };
this.catchException = function(e){
return jasmine.Spec.isPendingSpecException(e) || catchExceptions;
};
var maximumSpecCallbackDepth = 100; var maximumSpecCallbackDepth = 100;
var currentSpecCallbackDepth = 0; var currentSpecCallbackDepth = 0;
@@ -111,13 +115,12 @@
} }
var queueRunnerFactory = function(options) { var queueRunnerFactory = function(options) {
options.catchingExceptions = self.catchingExceptions; options.catchException = self.catchException;
options.encourageGC = options.encourageGarbageCollection || encourageGarbageCollection; options.encourageGC = options.encourageGarbageCollection || encourageGarbageCollection;
new jasmine.QueueRunner(options).run(options.fns, 0); new jasmine.QueueRunner(options).run(options.fns, 0);
}; };
var totalSpecsDefined = 0; var totalSpecsDefined = 0;
this.specFactory = function(description, fn, suite) { this.specFactory = function(description, fn, suite) {
totalSpecsDefined++; totalSpecsDefined++;
@@ -322,7 +325,7 @@
// TODO: move this to closure // TODO: move this to closure
jasmine.Env.prototype.xit = function(description, fn) { jasmine.Env.prototype.xit = function(description, fn) {
var spec = this.it(description, fn); var spec = this.it(description, fn);
spec.disable(); spec.pend();
return spec; return spec;
}; };
@@ -336,6 +339,11 @@
this.currentSuite.afterEach(afterEachFunction); this.currentSuite.afterEach(afterEachFunction);
}; };
// TODO: move this to closure
jasmine.Env.prototype.pending = function() {
throw new Error(jasmine.Spec.pendingSpecExceptionMessage);
};
// TODO: Still needed? // TODO: Still needed?
jasmine.Env.prototype.currentRunner = function() { jasmine.Env.prototype.currentRunner = function() {
return this.topSuite; return this.topSuite;
+3 -3
View File
@@ -38,12 +38,12 @@ jasmine.JsApiReporter = function(jasmine) {
}; };
var specs = []; var specs = [];
this.specStarted = function(result) { this.specStarted = function(result) { };
this.specDone = function(result) {
specs.push(result); specs.push(result);
}; };
this.specDone = function(result) { };
this.specResults = function(index, length) { this.specResults = function(index, length) {
return specs.slice(index, index + length); return specs.slice(index, index + length);
}; };
+2 -2
View File
@@ -3,7 +3,7 @@ jasmine.QueueRunner = function(attrs) {
this.onComplete = attrs.onComplete || function() {}; this.onComplete = attrs.onComplete || function() {};
this.encourageGC = attrs.encourageGC || function(fn) {fn()}; this.encourageGC = attrs.encourageGC || function(fn) {fn()};
this.onException = attrs.onException || function() {}; this.onException = attrs.onException || function() {};
this.catchingExceptions = attrs.catchingExceptions || function() { return true; }; this.catchException = attrs.catchException || function() { return true; };
}; };
jasmine.QueueRunner.prototype.execute = function() { jasmine.QueueRunner.prototype.execute = function() {
@@ -30,7 +30,7 @@ jasmine.QueueRunner.prototype.run = function(fns, index) {
fn(); fn();
} catch (e) { } catch (e) {
self.onException(e); self.onException(e);
if (!self.catchingExceptions()) { if (!self.catchException(e)) {
//TODO: set a var when we catch an exception and //TODO: set a var when we catch an exception and
//use a finally block to close the loop in a nice way.. //use a finally block to close the loop in a nice way..
throw e; throw e;
+26 -6
View File
@@ -11,10 +11,14 @@ jasmine.Spec = function(attrs) {
this.onStart = attrs.onStart || function() {}; this.onStart = attrs.onStart || function() {};
this.exceptionFormatter = attrs.exceptionFormatter || function() {}; this.exceptionFormatter = attrs.exceptionFormatter || function() {};
this.getSpecName = attrs.getSpecName || function() { return ''; }; this.getSpecName = attrs.getSpecName || function() { return ''; };
this.expectationResultFactory = attrs.expectationResultFactory || function() {}; this.expectationResultFactory = attrs.expectationResultFactory || function() { };
this.queueRunner = attrs.queueRunner || { execute: function() {}}; this.queueRunner = attrs.queueRunner || function() {};
this.catchingExceptions = attrs.catchingExceptions || function() { return true; }; this.catchingExceptions = attrs.catchingExceptions || function() { return true; };
if (!this.fn) {
this.pend();
}
this.result = { this.result = {
id: this.id, id: this.id,
description: this.description, description: this.description,
@@ -39,7 +43,9 @@ jasmine.Spec.prototype.expect = function(actual) {
jasmine.Spec.prototype.execute = function(onComplete) { jasmine.Spec.prototype.execute = function(onComplete) {
var self = this; var self = this;
if (this.disabled) { this.onStart(this);
if (this.markedPending || this.disabled) {
complete(); complete();
return; return;
} }
@@ -48,10 +54,14 @@ jasmine.Spec.prototype.execute = function(onComplete) {
afters = this.afterFns() || []; afters = this.afterFns() || [];
var allFns = befores.concat(this.fn).concat(afters); var allFns = befores.concat(this.fn).concat(afters);
this.onStart(this);
this.queueRunner({ this.queueRunner({
fns: allFns, fns: allFns,
onException: function(e) { onException: function(e) {
if (jasmine.Spec.isPendingSpecException(e)) {
self.pend();
return;
}
self.addExpectationResult(false, { self.addExpectationResult(false, {
matcherName: "", matcherName: "",
passed: false, passed: false,
@@ -77,13 +87,17 @@ jasmine.Spec.prototype.disable = function() {
this.disabled = true; this.disabled = true;
}; };
jasmine.Spec.prototype.pend = function() {
this.markedPending = true;
};
jasmine.Spec.prototype.status = function() { jasmine.Spec.prototype.status = function() {
if (this.disabled) { if (this.disabled) {
return 'disabled'; return 'disabled';
} }
if (!this.encounteredExpectations) { if (this.markedPending || !this.encounteredExpectations) {
return null; return 'pending';
} }
if (this.result.failedExpectations.length > 0) { if (this.result.failedExpectations.length > 0) {
@@ -96,3 +110,9 @@ jasmine.Spec.prototype.status = function() {
jasmine.Spec.prototype.getFullName = function() { jasmine.Spec.prototype.getFullName = function() {
return this.getSpecName(this); return this.getSpecName(this);
}; };
jasmine.Spec.pendingSpecExceptionMessage = "=> marked Pending";
jasmine.Spec.isPendingSpecException = function(e) {
return e.message.indexOf(jasmine.Spec.pendingSpecExceptionMessage) === 0;
};
+9 -2
View File
@@ -8,6 +8,7 @@ jasmine.HtmlReporter = function(options) {
startTime, startTime,
specsExecuted = 0, specsExecuted = 0,
failureCount = 0, failureCount = 0,
pendingSpecCount = 0,
htmlReporterMain, htmlReporterMain,
symbols; symbols;
@@ -85,6 +86,10 @@ jasmine.HtmlReporter = function(options) {
failures.push(failure); failures.push(failure);
} }
if(result.status == "pending") {
pendingSpecCount++;
}
}; };
this.jasmineDone = function() { this.jasmineDone = function() {
@@ -116,8 +121,10 @@ jasmine.HtmlReporter = function(options) {
) )
); );
} }
var statusBarMessage = "" + pluralize("spec", specsExecuted) + ", " + pluralize("failure", failureCount), var statusBarMessage = "" + pluralize("spec", specsExecuted) + ", " + pluralize("failure", failureCount);
statusBarClassName = "bar " + ((failureCount > 0) ? "failed" : "passed"); if(pendingSpecCount) { statusBarMessage += ", " + pluralize("pending spec", pendingSpecCount); }
var statusBarClassName = "bar " + ((failureCount > 0) ? "failed" : "passed");
alert.appendChild(createDom("span", {className: statusBarClassName}, statusBarMessage)); alert.appendChild(createDom("span", {className: statusBarClassName}, statusBarMessage));
var results = find(".results")[0]; var results = find(".results")[0];
+14 -10
View File
@@ -14,6 +14,7 @@ $passing-color: #5e7d00;
$light-failing-color: #cf867e; $light-failing-color: #cf867e;
$failing-color: #b03911; $failing-color: #b03911;
$pending-color: #ba9d37;
$neutral-color: #bababa; $neutral-color: #bababa;
@@ -120,21 +121,20 @@ body {
} }
} }
&.disabled { &.disabled {
font-size: 14px; font-size: 14px;
&:before { &:before {
color: $neutral-color; color: $neutral-color;
content: "\02022"; content: "\02022";
}
} }
}
&.pending { &.pending {
line-height: ($line-height / 2) + 4; line-height: 17px;
&:before { &:before {
color: $faint-text-color; color: $pending-color;
content: "-"; content: "*";
} }
} }
} }
@@ -264,6 +264,10 @@ body {
&.failed a { &.failed a {
color: $failing-color; color: $failing-color;
} }
&.pending a {
color: $pending-color;
}
} }
} }
+3 -2
View File
@@ -18,8 +18,8 @@ body { background-color: #eeeeee; padding: 0; margin: 5px; overflow-y: scroll; }
.html-reporter .symbol-summary li.failed:before { color: #b03911; content: "x"; font-weight: bold; margin-left: -1px; } .html-reporter .symbol-summary li.failed:before { color: #b03911; content: "x"; font-weight: bold; margin-left: -1px; }
.html-reporter .symbol-summary li.disabled { font-size: 14px; } .html-reporter .symbol-summary li.disabled { font-size: 14px; }
.html-reporter .symbol-summary li.disabled:before { color: #bababa; content: "\02022"; } .html-reporter .symbol-summary li.disabled:before { color: #bababa; content: "\02022"; }
.html-reporter .symbol-summary li.pending { line-height: 11px; } .html-reporter .symbol-summary li.pending { line-height: 17px; }
.html-reporter .symbol-summary li.pending:before { color: #aaaaaa; content: "-"; } .html-reporter .symbol-summary li.pending:before { color: #ba9d37; content: "*"; }
.html-reporter .exceptions { color: #fff; float: right; margin-top: 5px; margin-right: 5px; } .html-reporter .exceptions { color: #fff; float: right; margin-top: 5px; margin-right: 5px; }
.html-reporter .bar { line-height: 28px; font-size: 14px; display: block; color: #eee; } .html-reporter .bar { line-height: 28px; font-size: 14px; display: block; color: #eee; }
.html-reporter .bar.failed { background-color: #b03911; } .html-reporter .bar.failed { background-color: #b03911; }
@@ -43,6 +43,7 @@ body { background-color: #eeeeee; padding: 0; margin: 5px; overflow-y: scroll; }
.html-reporter .summary ul.suite { margin-top: 7px; margin-bottom: 7px; } .html-reporter .summary ul.suite { margin-top: 7px; margin-bottom: 7px; }
.html-reporter .summary li.passed a { color: #5e7d00; } .html-reporter .summary li.passed a { color: #5e7d00; }
.html-reporter .summary li.failed a { color: #b03911; } .html-reporter .summary li.failed a { color: #b03911; }
.html-reporter .summary li.pending a { color: #ba9d37; }
.html-reporter .description + .suite { margin-top: 0; } .html-reporter .description + .suite { margin-top: 0; }
.html-reporter .suite { margin-top: 14px; } .html-reporter .suite { margin-top: 14px; }
.html-reporter .suite a { color: #333333; } .html-reporter .suite a { color: #333333; }