Skip to content

Commit 7e72bef

Browse files
committed
Merge branch 'missing-core-config-options' of https://github.com/coyoteecd/jasmine-npm
* Merges #157 from @coyoteecd * Fixes #156
2 parents af16759 + 4ecf63c commit 7e72bef

File tree

4 files changed

+123
-1
lines changed

4 files changed

+123
-1
lines changed

lib/jasmine.js

+4
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ Jasmine.prototype.loadConfig = function(config) {
120120

121121
var configuration = {};
122122

123+
if (config.failSpecWithNoExpectations !== undefined) {
124+
configuration.failSpecWithNoExpectations = config.failSpecWithNoExpectations;
125+
}
126+
123127
if (config.stopSpecOnExpectationFailure !== undefined) {
124128
configuration.oneFailurePerSpec = config.stopSpecOnExpectationFailure;
125129
}

lib/reporters/console_reporter.js

+15
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,21 @@ function ConsoleReporter() {
202202
printNewline();
203203
print(indent(stackFilter(failedExpectation.stack), 4));
204204
}
205+
206+
// When failSpecWithNoExpectations = true and a spec fails because of no expectations found,
207+
// jasmine-core reports it as a failure with no message.
208+
//
209+
// Therefore we assume that when there are no failed or passed expectations,
210+
// the failure was because of our failSpecWithNoExpectations setting.
211+
//
212+
// Same logic is used by jasmine.HtmlReporter, see https://github.com/jasmine/jasmine/blob/master/src/html/HtmlReporter.js
213+
if (result.failedExpectations.length === 0 &&
214+
(!result.passedExpectations || result.passedExpectations.length === 0)) {
215+
printNewline();
216+
print(indent('Message:', 2));
217+
printNewline();
218+
print(colored('red', indent('Spec has no expectations', 4)));
219+
}
205220

206221
printNewline();
207222
}

spec/jasmine_spec.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,13 @@ describe('Jasmine', function() {
179179
]);
180180
});
181181

182+
it('can tell jasmine-core to stop spec on no expectations', function() {
183+
this.configObject.failSpecWithNoExpectations = true;
184+
this.fixtureJasmine.loadConfig(this.configObject);
185+
186+
expect(this.fixtureJasmine.env.configure).toHaveBeenCalledWith({failSpecWithNoExpectations: true});
187+
});
188+
182189
it('can tell jasmine-core to stop spec on expectation failure', function() {
183190
this.configObject.stopSpecOnExpectationFailure = true;
184191
this.fixtureJasmine.loadConfig(this.configObject);
@@ -212,7 +219,7 @@ describe('Jasmine', function() {
212219
expect(this.fixtureJasmine.env.configure).toHaveBeenCalledWith({random: true});
213220
});
214221

215-
it('uses jasmine-core defaults if random is unspecified', function() {
222+
it('uses jasmine-core defaults if no config options specified', function() {
216223
this.fixtureJasmine.loadConfig(this.configObject);
217224

218225
expect(this.fixtureJasmine.env.configure).not.toHaveBeenCalled();

spec/reporters/console_reporter_spec.js

+96
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,102 @@ describe("ConsoleReporter", function() {
408408
expect(this.out.getOutput()).toContain("Incomplete: not all bars were frobnicated");
409409
});
410410

411+
it("reports a summary when done that shows info for a failed spec with no expectations", function() {
412+
var reporter = new ConsoleReporter();
413+
reporter.setOptions({
414+
print: this.out.print,
415+
jasmineCorePath: jasmineCorePath
416+
});
417+
418+
reporter.jasmineStarted();
419+
reporter.specDone({status: "passed"});
420+
reporter.specDone({
421+
status: "failed",
422+
description: "with a failing spec",
423+
fullName: "A suite with a failing spec that has no expectations",
424+
failedExpectations: []
425+
});
426+
427+
this.out.clear();
428+
429+
reporter.jasmineDone();
430+
431+
expect(this.out.getOutput()).toContain("Spec has no expectations");
432+
});
433+
434+
it('reports a summary without "no expectations" message for a spec having failed expectations', function () {
435+
var reporter = new ConsoleReporter();
436+
reporter.setOptions({
437+
print: this.out.print,
438+
jasmineCorePath: jasmineCorePath
439+
});
440+
441+
reporter.jasmineStarted();
442+
reporter.specDone({
443+
status: "failed",
444+
description: "with a failing spec",
445+
fullName: "A suite with a failing spec that has a failing expectation",
446+
failedExpectations: [{
447+
passed: false,
448+
message: "Expected true to be false.",
449+
expected: false,
450+
actual: true,
451+
stack: undefined
452+
}]
453+
});
454+
455+
this.out.clear();
456+
457+
reporter.jasmineDone();
458+
459+
expect(this.out.getOutput()).not.toContain("Spec has no expectations");
460+
});
461+
462+
it('reports a summary without a "no expectations" message for a spec having passed expectations', function () {
463+
var reporter = new ConsoleReporter();
464+
reporter.setOptions({
465+
print: this.out.print,
466+
jasmineCorePath: jasmineCorePath
467+
});
468+
469+
reporter.jasmineStarted();
470+
reporter.specDone({
471+
status: "passed",
472+
description: "with a passed spec",
473+
fullName: "A suite with a passed spec",
474+
passedExpectations: [{
475+
passed: true,
476+
message: "Expected true to be true.",
477+
expected: true,
478+
actual: true
479+
}]
480+
});
481+
reporter.specDone({
482+
status: "failed",
483+
description: "with a failing spec",
484+
fullName: "A suite with a failing spec that has both passed and failing expectations",
485+
failedExpectations: [{
486+
passed: false,
487+
message: "Expected true to be false.",
488+
expected: false,
489+
actual: true,
490+
stack: undefined
491+
}],
492+
passedExpectations: [{
493+
passed: true,
494+
message: "Expected true to be true.",
495+
expected: true,
496+
actual: true
497+
}]
498+
});
499+
500+
this.out.clear();
501+
502+
reporter.jasmineDone();
503+
504+
expect(this.out.getOutput()).not.toContain("Spec has no expectations");
505+
});
506+
411507
it("displays all afterAll exceptions", function() {
412508
var reporter = new ConsoleReporter();
413509
reporter.setOptions({

0 commit comments

Comments
 (0)