Skip to content

Commit

Permalink
Print doc strings in pretty formatter output (close #81)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbpros committed Oct 6, 2012
1 parent b6a1702 commit 4ae4bec
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
10 changes: 10 additions & 0 deletions lib/cucumber/listener/pretty_formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
64 changes: 63 additions & 1 deletion spec/cucumber/listener/pretty_formatter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 4ae4bec

Please sign in to comment.