Skip to content

Commit d6ca062

Browse files
author
charlierudolph
committed
Use Array instead of Type.Collection for summary formatter
1 parent 6ed851c commit d6ca062

File tree

2 files changed

+48
-87
lines changed

2 files changed

+48
-87
lines changed

lib/cucumber/listener/summary_formatter.js

+15-13
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ function SummaryFormatter(options) {
55
var _ = require('underscore');
66

77
var failedScenarioLogBuffer = '';
8-
var undefinedStepLogBuffer = '';
9-
var failedStepResults = Cucumber.Type.Collection();
8+
var failedStepResultLogBuffer = '';
9+
var undefinedStepLogBuffer = '';
1010
var statsJournal = Cucumber.Listener.StatsJournal();
1111
var colors = Cucumber.Util.Colors(options.useColors);
1212
var statusReportOrder = [
@@ -60,7 +60,9 @@ function SummaryFormatter(options) {
6060
};
6161

6262
self.storeFailedStepResult = function storeFailedStepResult(failedStepResult) {
63-
failedStepResults.add(failedStepResult);
63+
var failureException = failedStepResult.getFailureException();
64+
var failureMessage = failureException.stack || failureException;
65+
self.appendStringToFailedStepResultLogBuffer(failureMessage);
6466
};
6567

6668
self.storeFailedScenario = function storeFailedScenario(failedScenario) {
@@ -80,6 +82,10 @@ function SummaryFormatter(options) {
8082
failedScenarioLogBuffer += string + '\n';
8183
};
8284

85+
self.appendStringToFailedStepResultLogBuffer = function appendStringToFailedScenarioLogBuffer(string) {
86+
failedStepResultLogBuffer += string + '\n\n';
87+
};
88+
8389
self.appendStringToUndefinedStepLogBuffer = function appendStringToUndefinedStepLogBuffer(string) {
8490
if (undefinedStepLogBuffer.indexOf(string) === -1)
8591
undefinedStepLogBuffer += string + '\n';
@@ -89,6 +95,10 @@ function SummaryFormatter(options) {
8995
return failedScenarioLogBuffer;
9096
};
9197

98+
self.getFailedStepResultLogBuffer = function getFailedStepResultLogBuffer() {
99+
return failedStepResultLogBuffer;
100+
};
101+
92102
self.getUndefinedStepLogBuffer = function getUndefinedStepLogBuffer() {
93103
return undefinedStepLogBuffer;
94104
};
@@ -109,9 +119,8 @@ function SummaryFormatter(options) {
109119

110120
self.logFailedStepResults = function logFailedStepResults() {
111121
self.log('(::) failed steps (::)\n\n');
112-
failedStepResults.forEach(function (stepResult) {
113-
self.logFailedStepResult(stepResult);
114-
});
122+
var failedStepResults = self.getFailedStepResultLogBuffer();
123+
self.log(failedStepResults);
115124
};
116125

117126
self.logFailedScenarios = function logFailedScenarios() {
@@ -121,13 +130,6 @@ function SummaryFormatter(options) {
121130
self.log('\n');
122131
};
123132

124-
self.logFailedStepResult = function logFailedStepResult(stepResult) {
125-
var failureMessage = stepResult.getFailureException();
126-
if (failureMessage)
127-
self.log(failureMessage.stack || failureMessage);
128-
self.log('\n\n');
129-
};
130-
131133
self.logScenariosSummary = function logScenariosSummary() {
132134
self.logCountSummary('scenario', statsJournal.getScenarioCounts());
133135
};

spec/cucumber/listener/summary_formatter_spec.js

+33-74
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@ describe("Cucumber.Listener.SummaryFormatter", function () {
44
var Cucumber = requireLib('cucumber');
55
var colors = require('colors/safe');
66
colors.enabled = true;
7-
var formatter, formatterHearMethod, summaryFormatter, statsJournal, failedStepResults, options;
7+
var formatter, formatterHearMethod, summaryFormatter, statsJournal, options;
88

99
beforeEach(function () {
1010
options = {useColors: true};
1111
formatter = createSpyWithStubs("formatter", {finish: null, log: null});
1212
formatterHearMethod = spyOnStub(formatter, 'hear');
1313
statsJournal = createSpy("stats journal");
14-
failedStepResults = createSpyObj("failed steps", ["length"]);
15-
failedStepResults.length.and.returnValue(0);
16-
spyOn(Cucumber.Type, 'Collection').and.returnValue(failedStepResults);
1714
spyOn(Cucumber.Listener, 'Formatter').and.returnValue(formatter);
1815
spyOn(Cucumber.Listener, 'StatsJournal').and.returnValue(statsJournal);
1916
summaryFormatter = Cucumber.Listener.SummaryFormatter(options);
@@ -28,10 +25,6 @@ describe("Cucumber.Listener.SummaryFormatter", function () {
2825
expect(summaryFormatter).toBe(formatter);
2926
});
3027

31-
it("creates a collection to store the failed steps", function () {
32-
expect(Cucumber.Type.Collection).toHaveBeenCalled();
33-
});
34-
3528
it("creates a stats journal", function () {
3629
expect(Cucumber.Listener.StatsJournal).toHaveBeenCalled();
3730
});
@@ -227,16 +220,34 @@ describe("Cucumber.Listener.SummaryFormatter", function () {
227220

228221

229222
describe("storeFailedStepResult()", function () {
230-
var failedStepResult;
223+
var failureException, stepResult;
231224

232225
beforeEach(function () {
233-
failedStepResult = createSpy("failed step result");
234-
spyOnStub(failedStepResults, 'add');
226+
spyOn(summaryFormatter, 'appendStringToFailedStepResultLogBuffer');
235227
});
236228

237-
it("adds the result to the failed step result collection", function () {
238-
summaryFormatter.storeFailedStepResult(failedStepResult);
239-
expect(failedStepResults.add).toHaveBeenCalledWith(failedStepResult);
229+
describe("when the failure exception has a stack", function () {
230+
beforeEach(function () {
231+
failureException = {stack: 'failure exception stack'};
232+
stepResult = createSpyWithStubs("failed step result", { getFailureException: failureException });
233+
});
234+
235+
it("appends the stack to the failed step results log buffer", function () {
236+
summaryFormatter.storeFailedStepResult(stepResult);
237+
expect(summaryFormatter.appendStringToFailedStepResultLogBuffer).toHaveBeenCalledWith('failure exception stack');
238+
});
239+
});
240+
241+
describe("when the failure exception has no stack", function () {
242+
beforeEach(function () {
243+
failureException = 'failure exception';
244+
stepResult = createSpyWithStubs("failed step result", { getFailureException: failureException });
245+
});
246+
247+
it("appends the expception to the failed step results log buffer", function () {
248+
summaryFormatter.storeFailedStepResult(stepResult);
249+
expect(summaryFormatter.appendStringToFailedStepResultLogBuffer).toHaveBeenCalledWith('failure exception');
250+
});
240251
});
241252
});
242253

@@ -428,72 +439,20 @@ describe("Cucumber.Listener.SummaryFormatter", function () {
428439
});
429440

430441
describe("logFailedStepResults()", function () {
431-
beforeEach(function () {
432-
spyOnStub(failedStepResults, 'forEach');
433-
});
434-
435-
it("logs a failed steps header", function () {
436-
summaryFormatter.logFailedStepResults();
437-
expect(summaryFormatter.log).toHaveBeenCalledWith("(::) failed steps (::)\n\n");
438-
});
439-
440-
it("iterates synchronously over the failed step results", function () {
441-
summaryFormatter.logFailedStepResults();
442-
expect(failedStepResults.forEach).toHaveBeenCalled();
443-
expect(failedStepResults.forEach).toHaveBeenCalledWithAFunctionAsNthParameter(1);
444-
});
445-
446-
describe("for each failed step result", function () {
447-
var userFunction, failedStepResult;
448-
449-
beforeEach(function () {
450-
summaryFormatter.logFailedStepResults();
451-
userFunction = failedStepResults.forEach.calls.mostRecent().args[0];
452-
failedStepResult = createSpy("failed step result");
453-
spyOn(summaryFormatter, 'logFailedStepResult');
454-
});
455-
456-
it("tells the visitor to visit the feature and call back when finished", function () {
457-
userFunction (failedStepResult);
458-
expect(summaryFormatter.logFailedStepResult).toHaveBeenCalledWith(failedStepResult);
459-
});
460-
});
461-
});
462-
463-
describe("logFailedStepResult()", function () {
464-
var stepResult, failureException;
442+
var failedStepResultLogBuffer;
465443

466444
beforeEach(function () {
467-
failureException = createSpy('caught exception');
468-
stepResult = createSpyWithStubs("failed step result", { getFailureException: failureException });
469-
});
470-
471-
it("gets the failure exception from the step result", function () {
472-
summaryFormatter.logFailedStepResult(stepResult);
473-
expect(stepResult.getFailureException).toHaveBeenCalled();
474-
});
475-
476-
describe("when the failure exception has a stack", function () {
477-
beforeEach(function () {
478-
failureException.stack = createSpy('failure exception stack');
479-
});
480-
481-
it("logs the stack", function () {
482-
summaryFormatter.logFailedStepResult(stepResult);
483-
expect(summaryFormatter.log).toHaveBeenCalledWith(failureException.stack);
484-
});
445+
failedStepResultLogBuffer = "failed step result log buffer";
446+
spyOn(summaryFormatter, 'getFailedStepResultLogBuffer').and.returnValue(failedStepResultLogBuffer);
447+
summaryFormatter.logFailedStepResults();
485448
});
486449

487-
describe("when the failure exception has no stack", function () {
488-
it("logs the exception itself", function () {
489-
summaryFormatter.logFailedStepResult(stepResult);
490-
expect(summaryFormatter.log).toHaveBeenCalledWith(failureException);
491-
});
450+
it("logs a failed step results header", function () {
451+
expect(summaryFormatter.log).toHaveBeenCalledWith('(::) failed steps (::)\n\n');
492452
});
493453

494-
it("logs two line breaks", function () {
495-
summaryFormatter.logFailedStepResult(stepResult);
496-
expect(summaryFormatter.log).toHaveBeenCalledWith("\n\n");
454+
it("logs the failed step results details", function () {
455+
expect(summaryFormatter.log).toHaveBeenCalledWith(failedStepResultLogBuffer);
497456
});
498457
});
499458

0 commit comments

Comments
 (0)