diff --git a/lib/cucumber/listener/pretty_formatter.js b/lib/cucumber/listener/pretty_formatter.js index daff3ba33..3ffa25293 100644 --- a/lib/cucumber/listener/pretty_formatter.js +++ b/lib/cucumber/listener/pretty_formatter.js @@ -41,6 +41,11 @@ var PrettyFormatter = function(options) { self.logDataTable(dataTable); } + if (step.hasDocString()) { + var docString = step.getDocString(); + self.logDocString(docString); + } + stepResult.isFailed(); if (stepResult.isFailed()) { var failure = stepResult.getFailureException(); @@ -76,6 +81,11 @@ var PrettyFormatter = function(options) { } }; + self.logDocString = function logDocString(docString) { + var contents = docString.getContents(); + self.logIndented('"""\n' + contents + '\n"""\n' , 3); + }; + self.logIndented = function logIndented(text, level) { var indented = self.indent(text, level); self.log(indented); diff --git a/spec/cucumber/listener/pretty_formatter_spec.js b/spec/cucumber/listener/pretty_formatter_spec.js index 382af19bc..340e6f090 100644 --- a/spec/cucumber/listener/pretty_formatter_spec.js +++ b/spec/cucumber/listener/pretty_formatter_spec.js @@ -161,10 +161,11 @@ describe("Cucumber.Listener.PrettyFormatter", function () { beforeEach(function () { keyword = "step-keyword "; name = "step-name"; - step = createSpyWithStubs("step", { getKeyword: keyword, hasDataTable: null, getDataTable: null, getName: name }); + step = createSpyWithStubs("step", { getKeyword: keyword, hasDataTable: null, getDataTable: null, hasDocString: null, getDocString: null, getName: name }); stepResult = createSpyWithStubs("step result", { getStep: step, isFailed: null }); event = createSpyWithStubs("event", { getPayloadItem: stepResult }); spyOn(prettyFormatter, 'logDataTable'); + spyOn(prettyFormatter, 'logDocString'); spyOn(prettyFormatter, 'logIndented'); callback = createSpy("callback"); }); @@ -236,6 +237,47 @@ describe("Cucumber.Listener.PrettyFormatter", function () { }); }); + it("checks whether the step result has a doc string or not", function () { + prettyFormatter.handleStepResultEvent(event, callback); + expect(step.hasDocString).toHaveBeenCalled(); + }); + + describe("when the step has a doc string", function () { + var docString; + + beforeEach(function () { + docString = createSpy("doc string"); + step.hasDocString.andReturn(true); + step.getDocString.andReturn(docString); + }); + + it("gets the doc string", function () { + prettyFormatter.handleStepResultEvent(event, callback); + expect(step.getDocString).toHaveBeenCalled(); + }); + + it("logs the doc string", function () { + prettyFormatter.handleStepResultEvent(event, callback); + expect(prettyFormatter.logDocString).toHaveBeenCalledWith(docString); + }); + }); + + describe("when the step has no doc string", function () { + beforeEach(function () { + step.hasDocString.andReturn(false); + }); + + it("does not get the doc string", function () { + prettyFormatter.handleStepResultEvent(event, callback); + expect(step.getDocString).not.toHaveBeenCalled(); + }); + + it("logs the doc string", function () { + prettyFormatter.handleStepResultEvent(event, callback); + expect(prettyFormatter.logDocString).not.toHaveBeenCalled(); + }); + }); + it("checks whether the step result is failed or not", function () { prettyFormatter.handleStepResultEvent(event, callback); expect(stepResult.isFailed).toHaveBeenCalled(); @@ -335,6 +377,26 @@ describe("Cucumber.Listener.PrettyFormatter", function () { }); }); + describe("logDocString()", function () { + var docString, contents; + + beforeEach(function () { + contents = "this is a multiline\ndoc string\n\n:-)"; + docString = createSpyWithStubs("doc string", {getContents: contents}); + spyOn(prettyFormatter, "logIndented"); + }); + + it("gets the contents of the doc string", function () { + prettyFormatter.logDocString(docString); + expect(docString.getContents).toHaveBeenCalled(); + }); + + it("logs the contents of the doc string, with a 3-level indentation", function () { + prettyFormatter.logDocString(docString); + expect(prettyFormatter.logIndented).toHaveBeenCalledWith('"""\n' + contents + '\n"""\n', 3); + }); + }); + describe("logIndented()", function () { var text, level, indented;