Skip to content

Commit

Permalink
Refactor "summarizer" listener to summary formatter (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbpros committed Jul 10, 2012
1 parent 951f3cb commit 28b74ef
Show file tree
Hide file tree
Showing 8 changed files with 260 additions and 307 deletions.
2 changes: 1 addition & 1 deletion lib/cucumber/listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ Listener.Formatter = require('./listener/formatter');
Listener.PrettyFormatter = require('./listener/pretty_formatter');
Listener.ProgressFormatter = require('./listener/progress_formatter');
Listener.StatsJournal = require('./listener/stats_journal');
Listener.Summarizer = require('./listener/summarizer');
Listener.SummaryFormatter = require('./listener/summary_formatter');
module.exports = Listener;
8 changes: 4 additions & 4 deletions lib/cucumber/listener/pretty_formatter.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
var PrettyFormatter = function(options) {
var Cucumber = require('../../cucumber');

var self = Cucumber.Listener.Formatter(options);
var summarizer = Cucumber.Listener.Summarizer();
var self = Cucumber.Listener.Formatter(options);
var summaryFormatter = Cucumber.Listener.SummaryFormatter({logToConsole: false});

var parentHear = self.hear;
self.hear = function hear(event, callback) {
summarizer.hear(event, function () {
summaryFormatter.hear(event, function () {
parentHear(event, callback);
});
};
Expand Down Expand Up @@ -46,7 +46,7 @@ var PrettyFormatter = function(options) {
};

self.handleAfterFeaturesEvent = function handleAfterFeaturesEvent(event, callback) {
var summaryLogs = summarizer.getLogs();
var summaryLogs = summaryFormatter.getLogs();
self.log(summaryLogs);
callback();
};
Expand Down
8 changes: 4 additions & 4 deletions lib/cucumber/listener/progress_formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ var ProgressFormatter = function(options) {
if (!options)
options = {};

var self = Cucumber.Listener.Formatter(options);
var summaryLogger = Cucumber.Listener.Summarizer();
var self = Cucumber.Listener.Formatter(options);
var summaryFormatter = Cucumber.Listener.SummaryFormatter({logToConsole: false});

var parentHear = self.hear;
self.hear = function hear(event, callback) {
summaryLogger.hear(event, function () {
summaryFormatter.hear(event, function () {
parentHear(event, callback);
});
};
Expand Down Expand Up @@ -50,7 +50,7 @@ var ProgressFormatter = function(options) {
};

self.handleAfterFeaturesEvent = function handleAfterFeaturesEvent(event, callback) {
var summaryLogs = summaryLogger.getLogs();
var summaryLogs = summaryFormatter.getLogs();
self.log(summaryLogs);
callback();
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
var Summarizer = function () {
var SummaryFormatter = function (options) {
var Cucumber = require('../../cucumber');

var logs = "";
var failedScenarioLogBuffer = "";
var undefinedStepLogBuffer = "";
var failedStepResults = Cucumber.Type.Collection();
var statsJournal = Cucumber.Listener.StatsJournal();

var self = Cucumber.Listener();
var self = Cucumber.Listener.Formatter(options);

var parentHear = self.hear;
self.hear = function hear(event, callback) {
Expand All @@ -16,14 +15,6 @@ var Summarizer = function () {
});
};

self.log = function log(string) {
logs += string;
};

self.getLogs = function getLogs() {
return logs;
};

self.handleStepResultEvent = function handleStepResult(event, callback) {
var stepResult = event.getPayloadItem('stepResult');
if (stepResult.isUndefined()) {
Expand Down Expand Up @@ -174,4 +165,4 @@ var Summarizer = function () {

return self;
};
module.exports = Summarizer;
module.exports = SummaryFormatter;
6 changes: 4 additions & 2 deletions spec/cucumber/cli/configuration_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ describe("Cucumber.Cli.Configuration", function () {
describe("getFormatter()", function () {
beforeEach(function () {
spyOnStub(argumentParser, 'getFormat').andReturn("progress");
spyOn(Cucumber.Listener, 'ProgressFormatter');
spyOn(Cucumber.Listener, 'PrettyFormatter');
});

it("gets the formatter name from the argument parser", function () {
Expand All @@ -44,7 +46,7 @@ describe("Cucumber.Cli.Configuration", function () {
beforeEach(function () {
argumentParser.getFormat.andReturn("progress");
formatter = createSpy("formatter");
spyOn(Cucumber.Listener, 'ProgressFormatter').andReturn(formatter);
Cucumber.Listener.ProgressFormatter.andReturn(formatter);
});

it("creates a new progress formatter", function () {
Expand All @@ -63,7 +65,7 @@ describe("Cucumber.Cli.Configuration", function () {
beforeEach(function () {
argumentParser.getFormat.andReturn("pretty");
formatter = createSpy("formatter");
spyOn(Cucumber.Listener, 'PrettyFormatter').andReturn(formatter);
Cucumber.Listener.PrettyFormatter.andReturn(formatter);
});

it("creates a new pretty formatter", function () {
Expand Down
36 changes: 18 additions & 18 deletions spec/cucumber/listener/pretty_formatter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ require('../../support/spec_helper');

describe("Cucumber.Listener.PrettyFormatter", function () {
var Cucumber = requireLib('cucumber');
var formatter, formatterHearMethod, summarizer, prettyFormatter, options;
var formatter, formatterHearMethod, summaryFormatter, prettyFormatter, options;

beforeEach(function () {
options = createSpy(options);
options = createSpy("options");
formatter = createSpyWithStubs("formatter", {log: null});
formatterHearMethod = spyOnStub(formatter, 'hear');
summarizer = createSpy("summarizer");
summaryFormatter = createSpy("summary formatter");
spyOn(Cucumber.Listener, 'Formatter').andReturn(formatter);
spyOn(Cucumber.Listener, 'Summarizer').andReturn(summarizer);
spyOn(Cucumber.Listener, 'SummaryFormatter').andReturn(summaryFormatter);
prettyFormatter = Cucumber.Listener.PrettyFormatter(options);
});

Expand All @@ -23,8 +23,8 @@ describe("Cucumber.Listener.PrettyFormatter", function () {
expect(prettyFormatter).toBe(formatter);
});

it("creates a summarizer", function () {
expect(Cucumber.Listener.Summarizer).toHaveBeenCalled();
it("creates a summaryFormatter", function () {
expect(Cucumber.Listener.SummaryFormatter).toHaveBeenCalledWith({logToConsole: false});
});
});

Expand All @@ -34,26 +34,26 @@ describe("Cucumber.Listener.PrettyFormatter", function () {
beforeEach(function () {
event = createSpy("event");
callback = createSpy("callback");
spyOnStub(summarizer, 'hear');
spyOnStub(summaryFormatter, 'hear');
});

it("tells the summarizer to listen to the event", function () {
it("tells the summary formatter to listen to the event", function () {
prettyFormatter.hear(event, callback);
expect(summarizer.hear).toHaveBeenCalled();
expect(summarizer.hear).toHaveBeenCalledWithValueAsNthParameter(event, 1);
expect(summarizer.hear).toHaveBeenCalledWithAFunctionAsNthParameter(2);
expect(summaryFormatter.hear).toHaveBeenCalled();
expect(summaryFormatter.hear).toHaveBeenCalledWithValueAsNthParameter(event, 1);
expect(summaryFormatter.hear).toHaveBeenCalledWithAFunctionAsNthParameter(2);
});

describe("summarizer callback", function () {
var summarizerCallback;
describe("summary formatter callback", function () {
var summaryFormatterCallback;

beforeEach(function () {
prettyFormatter.hear(event, callback);
summarizerCallback = summarizer.hear.mostRecentCall.args[1];
summaryFormatterCallback = summaryFormatter.hear.mostRecentCall.args[1];
});

it("tells the formatter to listen to the event", function () {
summarizerCallback();
summaryFormatterCallback();
expect(formatterHearMethod).toHaveBeenCalledWith(event, callback);
});
});
Expand Down Expand Up @@ -243,12 +243,12 @@ describe("Cucumber.Listener.PrettyFormatter", function () {
event = createSpy("event");
callback = createSpy("callback");
summary = createSpy("summary logs");
spyOnStub(summarizer, 'getLogs').andReturn(summary);
spyOnStub(summaryFormatter, 'getLogs').andReturn(summary);
});

it("gets the summary from the summarizer", function () {
it("gets the summary from the summaryFormatter", function () {
prettyFormatter.handleAfterFeaturesEvent(event, callback);
expect(summarizer.getLogs).toHaveBeenCalled();
expect(summaryFormatter.getLogs).toHaveBeenCalled();
});

it("logs the summary", function () {
Expand Down
34 changes: 17 additions & 17 deletions spec/cucumber/listener/progress_formatter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ require('../../support/spec_helper');

describe("Cucumber.Listener.ProgressFormatter", function () {
var Cucumber = requireLib('cucumber');
var formatter, formatterHearMethod, summarizer, progressFormatter, options;
var formatter, formatterHearMethod, summaryFormatter, progressFormatter, options;

beforeEach(function () {
options = createSpy(options);
options = createSpy("options");
formatter = createSpyWithStubs("formatter", {log: null});
formatterHearMethod = spyOnStub(formatter, 'hear');
summarizer = createSpy("summarizer");
summaryFormatter = createSpy("summaryFormatter");
spyOn(Cucumber.Listener, 'Formatter').andReturn(formatter);
spyOn(Cucumber.Listener, 'Summarizer').andReturn(summarizer);
spyOn(Cucumber.Listener, 'SummaryFormatter').andReturn(summaryFormatter);
progressFormatter = Cucumber.Listener.ProgressFormatter(options);
});

Expand All @@ -23,8 +23,8 @@ describe("Cucumber.Listener.ProgressFormatter", function () {
expect(progressFormatter).toBe(formatter);
});

it("creates a summarizer", function () {
expect(Cucumber.Listener.Summarizer).toHaveBeenCalled();
it("creates a summary formatter", function () {
expect(Cucumber.Listener.SummaryFormatter).toHaveBeenCalledWith({logToConsole: false});
});
});

Expand All @@ -34,26 +34,26 @@ describe("Cucumber.Listener.ProgressFormatter", function () {
beforeEach(function () {
event = createSpy("event");
callback = createSpy("callback");
spyOnStub(summarizer, 'hear');
spyOnStub(summaryFormatter, 'hear');
});

it("tells the summarizer to listen to the event", function () {
it("tells the summary formatter to listen to the event", function () {
progressFormatter.hear(event, callback);
expect(summarizer.hear).toHaveBeenCalled();
expect(summarizer.hear).toHaveBeenCalledWithValueAsNthParameter(event, 1);
expect(summarizer.hear).toHaveBeenCalledWithAFunctionAsNthParameter(2);
expect(summaryFormatter.hear).toHaveBeenCalled();
expect(summaryFormatter.hear).toHaveBeenCalledWithValueAsNthParameter(event, 1);
expect(summaryFormatter.hear).toHaveBeenCalledWithAFunctionAsNthParameter(2);
});

describe("summarizer callback", function () {
var summarizerCallback;
describe("summary formatter callback", function () {
var summaryFormatterCallback;

beforeEach(function () {
progressFormatter.hear(event, callback);
summarizerCallback = summarizer.hear.mostRecentCall.args[1];
summaryFormatterCallback = summaryFormatter.hear.mostRecentCall.args[1];
});

it("tells the formatter to listen to the event", function () {
summarizerCallback();
summaryFormatterCallback();
expect(formatterHearMethod).toHaveBeenCalledWith(event, callback);
});
});
Expand Down Expand Up @@ -261,12 +261,12 @@ describe("Cucumber.Listener.ProgressFormatter", function () {
event = createSpy("event");
callback = createSpy("callback");
summaryLogs = createSpy("summary logs");
spyOnStub(summarizer, 'getLogs').andReturn(summaryLogs);
spyOnStub(summaryFormatter, 'getLogs').andReturn(summaryLogs);
});

it("gets the summary", function () {
progressFormatter.handleAfterFeaturesEvent(event, callback);
expect(summarizer.getLogs).toHaveBeenCalled();
expect(summaryFormatter.getLogs).toHaveBeenCalled();
});

it("logs the summary", function () {
Expand Down
Loading

0 comments on commit 28b74ef

Please sign in to comment.