Skip to content
Browse files

Print doc strings in pretty formatter output (close #81)

  • Loading branch information...
1 parent b6a1702 commit 4ae4becf9ff989876a4d642cf0eceffc406e9534 @jbpros jbpros committed Oct 6, 2012
Showing with 73 additions and 1 deletion.
  1. +10 −0 lib/cucumber/listener/pretty_formatter.js
  2. +63 −1 spec/cucumber/listener/pretty_formatter_spec.js
View
10 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);
View
64 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;

0 comments on commit 4ae4bec

Please sign in to comment.
Something went wrong with that request. Please try again.