Skip to content

Commit

Permalink
Support pending specs with:
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
Dan Hansen and Davis W. Frank committed Mar 1, 2013
1 parent d6da13a commit b7af6ab
Show file tree
Hide file tree
Showing 20 changed files with 346 additions and 126 deletions.
2 changes: 1 addition & 1 deletion Gemfile
@@ -1,7 +1,7 @@
source :rubygems
gem "rake"
gem "jasmine", :git => 'https://github.com/pivotal/jasmine-gem.git', :branch => '2_0'

#gem "jasmine", path: "/Users/pivotal/workspace/jasmine-gem"
unless ENV["TRAVIS"]
group :debug do
gem 'debugger'
Expand Down
4 changes: 4 additions & 0 deletions lib/jasmine-core/boot/boot.js
Expand Up @@ -30,6 +30,10 @@
return env.expect(actual);
},

pending: function() {
return env.pending();
},

addMatchers: function(matchers) {
return env.addMatchers(matchers);
},
Expand Down
11 changes: 9 additions & 2 deletions lib/jasmine-core/jasmine-html.js
Expand Up @@ -8,6 +8,7 @@ jasmine.HtmlReporter = function(options) {
startTime,
specsExecuted = 0,
failureCount = 0,
pendingSpecCount = 0,
htmlReporterMain,
symbols;

Expand Down Expand Up @@ -85,6 +86,10 @@ jasmine.HtmlReporter = function(options) {

failures.push(failure);
}

if(result.status == "pending") {
pendingSpecCount++;
}
};

this.jasmineDone = function() {
Expand Down Expand Up @@ -116,8 +121,10 @@ jasmine.HtmlReporter = function(options) {
)
);
}
var statusBarMessage = "" + pluralize("spec", specsExecuted) + ", " + pluralize("failure", failureCount),
statusBarClassName = "bar " + ((failureCount > 0) ? "failed" : "passed");
var statusBarMessage = "" + pluralize("spec", specsExecuted) + ", " + pluralize("failure", failureCount);
if(pendingSpecCount) { statusBarMessage += ", " + pluralize("pending spec", pendingSpecCount); }

var statusBarClassName = "bar " + ((failureCount > 0) ? "failed" : "passed");
alert.appendChild(createDom("span", {className: statusBarClassName}, statusBarMessage));

var results = find(".results")[0];
Expand Down
5 changes: 3 additions & 2 deletions lib/jasmine-core/jasmine.css
Expand Up @@ -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.disabled { font-size: 14px; }
.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:before { color: #aaaaaa; content: "-"; }
.html-reporter .symbol-summary li.pending { line-height: 17px; }
.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 .bar { line-height: 28px; font-size: 14px; display: block; color: #eee; }
.html-reporter .bar.failed { background-color: #b03911; }
Expand All @@ -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 li.passed a { color: #5e7d00; }
.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 .suite { margin-top: 14px; }
.html-reporter .suite a { color: #333333; }
Expand Down
57 changes: 42 additions & 15 deletions lib/jasmine-core/jasmine.js
Expand Up @@ -599,6 +599,10 @@ jasmine.buildExpectationResult = function(options) {
return catchExceptions;
};

this.catchException = function(e){
return jasmine.Spec.isPendingSpecException(e) || catchExceptions;
};

var maximumSpecCallbackDepth = 100;
var currentSpecCallbackDepth = 0;

Expand All @@ -613,13 +617,12 @@ jasmine.buildExpectationResult = function(options) {
}

var queueRunnerFactory = function(options) {
options.catchingExceptions = self.catchingExceptions;
options.catchException = self.catchException;
options.encourageGC = options.encourageGarbageCollection || encourageGarbageCollection;

new jasmine.QueueRunner(options).run(options.fns, 0);
};


var totalSpecsDefined = 0;
this.specFactory = function(description, fn, suite) {
totalSpecsDefined++;
Expand Down Expand Up @@ -824,7 +827,7 @@ jasmine.buildExpectationResult = function(options) {
// TODO: move this to closure
jasmine.Env.prototype.xit = function(description, fn) {
var spec = this.it(description, fn);
spec.disable();
spec.pend();
return spec;
};

Expand All @@ -838,6 +841,11 @@ jasmine.buildExpectationResult = function(options) {
this.currentSuite.afterEach(afterEachFunction);
};

// TODO: move this to closure
jasmine.Env.prototype.pending = function() {
throw new Error(jasmine.Spec.pendingSpecExceptionMessage);
};

// TODO: Still needed?
jasmine.Env.prototype.currentRunner = function() {
return this.topSuite;
Expand Down Expand Up @@ -1014,12 +1022,12 @@ jasmine.JsApiReporter = function(jasmine) {
};

var specs = [];
this.specStarted = function(result) {
this.specStarted = function(result) { };

this.specDone = function(result) {
specs.push(result);
};

this.specDone = function(result) { };

this.specResults = function(index, length) {
return specs.slice(index, index + length);
};
Expand Down Expand Up @@ -1558,7 +1566,7 @@ jasmine.QueueRunner = function(attrs) {
this.onComplete = attrs.onComplete || function() {};
this.encourageGC = attrs.encourageGC || function(fn) {fn()};
this.onException = attrs.onException || function() {};
this.catchingExceptions = attrs.catchingExceptions || function() { return true; };
this.catchException = attrs.catchException || function() { return true; };
};

jasmine.QueueRunner.prototype.execute = function() {
Expand All @@ -1585,7 +1593,7 @@ jasmine.QueueRunner.prototype.run = function(fns, index) {
fn();
} catch (e) {
self.onException(e);
if (!self.catchingExceptions()) {
if (!self.catchException(e)) {
//TODO: set a var when we catch an exception and
//use a finally block to close the loop in a nice way..
throw e;
Expand All @@ -1606,10 +1614,14 @@ jasmine.Spec = function(attrs) {
this.onStart = attrs.onStart || function() {};
this.exceptionFormatter = attrs.exceptionFormatter || function() {};
this.getSpecName = attrs.getSpecName || function() { return ''; };
this.expectationResultFactory = attrs.expectationResultFactory || function() {};
this.queueRunner = attrs.queueRunner || { execute: function() {}};
this.expectationResultFactory = attrs.expectationResultFactory || function() { };
this.queueRunner = attrs.queueRunner || function() {};
this.catchingExceptions = attrs.catchingExceptions || function() { return true; };

if (!this.fn) {
this.pend();
}

this.result = {
id: this.id,
description: this.description,
Expand All @@ -1634,7 +1646,9 @@ jasmine.Spec.prototype.expect = function(actual) {
jasmine.Spec.prototype.execute = function(onComplete) {
var self = this;

if (this.disabled) {
this.onStart(this);

if (this.markedPending || this.disabled) {
complete();
return;
}
Expand All @@ -1643,10 +1657,14 @@ jasmine.Spec.prototype.execute = function(onComplete) {
afters = this.afterFns() || [];
var allFns = befores.concat(this.fn).concat(afters);

this.onStart(this);
this.queueRunner({
fns: allFns,
onException: function(e) {
if (jasmine.Spec.isPendingSpecException(e)) {
self.pend();
return;
}

self.addExpectationResult(false, {
matcherName: "",
passed: false,
Expand All @@ -1672,13 +1690,17 @@ jasmine.Spec.prototype.disable = function() {
this.disabled = true;
};

jasmine.Spec.prototype.pend = function() {
this.markedPending = true;
};

jasmine.Spec.prototype.status = function() {
if (this.disabled) {
return 'disabled';
}

if (!this.encounteredExpectations) {
return null;
if (this.markedPending || !this.encounteredExpectations) {
return 'pending';
}

if (this.result.failedExpectations.length > 0) {
Expand All @@ -1691,7 +1713,12 @@ jasmine.Spec.prototype.status = function() {
jasmine.Spec.prototype.getFullName = function() {
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.id = attrs.id;
this.parentSuite = attrs.parentSuite;
Expand Down
22 changes: 15 additions & 7 deletions spec/console/ConsoleReporterSpec.js
Expand Up @@ -58,6 +58,16 @@ describe("ConsoleReporter", function() {
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() {
var fakeNow = jasmine.createSpy('fake Date.now'),
reporter = new jasmine.ConsoleReporter({
Expand All @@ -75,6 +85,7 @@ describe("ConsoleReporter", function() {
reporter.jasmineDone();

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");
});

Expand All @@ -88,6 +99,7 @@ describe("ConsoleReporter", function() {
fakeNow.andReturn(500);
reporter.jasmineStarted();
reporter.specDone({status: "passed"});
reporter.specDone({status: "pending"});
reporter.specDone({
status: "failed",
description: "with a failing spec",
Expand All @@ -98,9 +110,7 @@ describe("ConsoleReporter", function() {
message: "Expected true to be false.",
expected: false,
actual: true,
trace: {
stack: "foo\nbar\nbaz"
}
stack: "foo\nbar\nbaz"
}
]
});
Expand All @@ -110,7 +120,7 @@ describe("ConsoleReporter", function() {
fakeNow.andReturn(600);
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");
});

Expand All @@ -131,9 +141,7 @@ describe("ConsoleReporter", function() {
message: "Expected true to be false.",
expected: false,
actual: true,
trace: {
stack: "foo bar baz"
}
stack: "foo bar baz"
}
]
});
Expand Down
25 changes: 24 additions & 1 deletion spec/core/EnvSpec.js
Expand Up @@ -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() {
Expand Down Expand Up @@ -294,7 +317,7 @@ describe("Env (integration)", function() {
env.expect(true).toBe(true);
});
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.it("with a spec", function() {
Expand Down
24 changes: 2 additions & 22 deletions spec/core/JsApiReporterSpec.js
Expand Up @@ -149,26 +149,6 @@ describe("JsApiReporter", function() {
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() {
var reporter, specResult1, specResult2;
beforeEach(function() {
Expand All @@ -182,8 +162,8 @@ describe("JsApiReporter", function() {
description: "Another spec"
};

reporter.specStarted(specResult1);
reporter.specStarted(specResult2);
reporter.specDone(specResult1);
reporter.specDone(specResult2);
});

it("should return a slice of results", function() {
Expand Down
2 changes: 1 addition & 1 deletion spec/core/QueueRunnerSpec.js
Expand Up @@ -96,7 +96,7 @@ describe("QueueRunner", function() {
},
queueRunner = new jasmine.QueueRunner({
fns: [fn],
catchingExceptions: function() { return false; }
catchException: function(e) { return false; }
});

expect(function() { queueRunner.execute(); }).toThrow();
Expand Down

0 comments on commit b7af6ab

Please sign in to comment.