Skip to content

Commit

Permalink
Rename PyString to DocString (close #15)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbpros committed Jun 3, 2011
1 parent 2de46ba commit d7b251c
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 125 deletions.
62 changes: 31 additions & 31 deletions lib/cucumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var Cucumber = function(featuresSource, supportCodeDefinition) {
attachListener: function attachListener(listener) {
listeners.add(listener);
},

parseFeaturesSource: function parseFeaturesSource(featuresSource) {
var parser = Cucumber.Parser(featuresSource);
return parser.parse();
Expand All @@ -27,7 +27,7 @@ var Cucumber = function(featuresSource, supportCodeDefinition) {
var supportCodeLibrary = Cucumber.SupportCode.Library(supportCodeDefinition);
return supportCodeLibrary;
},

executeFeaturesAgainstSupportCodeLibrary: function executeFeaturesAgainstSupportCodeLibrary(features, supportCodeLibrary, callback) {
var treeWalker = Cucumber.Ast.TreeWalker(features, supportCodeLibrary, listeners);
treeWalker.walk(callback);
Expand All @@ -47,13 +47,13 @@ Cucumber.Parser = function(featuresSource) {
lexer.scan(featuresSource);
return features;
},

getEventHandlers: function getEventHandlers() {
return {
feature: self.handleFeature,
scenario: self.handleScenario,
step: self.handleStep,
py_string: self.handlePyString,
py_string: self.handleDocString,
eof: self.handleEof
};
},
Expand All @@ -71,7 +71,7 @@ Cucumber.Parser = function(featuresSource) {
var currentScenario = self.getCurrentScenario();
return currentScenario.getLastStep();
},

handleFeature: function handleFeature(keyword, name, description, line) {
var feature = Cucumber.Ast.Feature(keyword, name, description, line);
features.addFeature(feature);
Expand All @@ -89,10 +89,10 @@ Cucumber.Parser = function(featuresSource) {
currentScenario.addStep(step);
},

handlePyString: function handlePyString(string, line) {
var pyString = Cucumber.Ast.PyString(string, line);
handleDocString: function handleDocString(string, line) {
var docString = Cucumber.Ast.DocString(string, line);
var currentStep = self.getCurrentStep();
currentStep.attachPyString(pyString);
currentStep.attachDocString(docString);
},

handleEof: function handleEof() {}
Expand All @@ -104,7 +104,7 @@ Cucumber.Ast = {};

Cucumber.Ast.Features = function() {
var features = Cucumber.Types.Collection();

var self = {
addFeature: function addFeature(feature) {
features.add(feature);
Expand Down Expand Up @@ -158,7 +158,7 @@ Cucumber.Ast.Feature = function(keyword, name, description, line) {

Cucumber.Ast.Scenario = function(keyword, name) {
var steps = Cucumber.Types.Collection();

var self = {
getKeyword: function getKeyword() {
return keyword;
Expand Down Expand Up @@ -186,7 +186,7 @@ Cucumber.Ast.Scenario = function(keyword, name) {
};

Cucumber.Ast.Step = function(keyword, name, line) {
var pyString;
var docString;

var self = {
getKeyword: function getKeyword() {
Expand All @@ -197,13 +197,13 @@ Cucumber.Ast.Step = function(keyword, name, line) {
return name;
},

hasPyString: function hasPyString() {
return !!pyString;
hasDocString: function hasDocString() {
return !!docString;
},

getPyString: function getPyString() { return pyString; },

attachPyString: function attachPyString(_pyString) { pyString = _pyString; },
getDocString: function getDocString() { return docString; },

attachDocString: function attachDocString(_docString) { docString = _docString; },

acceptVisitor: function acceptVisitor(visitor, callback) {
self.execute(visitor, function(stepResult) {
Expand All @@ -213,13 +213,13 @@ Cucumber.Ast.Step = function(keyword, name, line) {

execute: function execute(visitor, callback) {
var stepDefinition = visitor.lookupStepDefinitionByName(name);
stepDefinition.invoke(name, pyString, callback);
stepDefinition.invoke(name, docString, callback);
}
};
return self;
};

Cucumber.Ast.PyString = function(string, line) {
Cucumber.Ast.DocString = function(string, line) {
var self = {
getString: function getString() {
return string;
Expand All @@ -231,7 +231,7 @@ Cucumber.Ast.PyString = function(string, line) {
Cucumber.Ast.TreeWalker = function(features, supportCodeLibrary, listeners) {
var listeners;

var self = {
var self = {
walk: function walk(callback) {
self.visitFeatures(features, callback);
},
Expand Down Expand Up @@ -278,7 +278,7 @@ Cucumber.Ast.TreeWalker = function(features, supportCodeLibrary, listeners) {
var afterMessage = Cucumber.Ast.TreeWalker.AFTER_MESSAGE_PREFIX + message;
var beforeParameters = [beforeMessage].concat(parameters);
var afterParameters = [afterMessage].concat(parameters);

self.broadcastMessage.apply(this, beforeParameters);
userFunction();
self.broadcastMessage.apply(this, [afterMessage].concat(parameters));
Expand Down Expand Up @@ -375,19 +375,19 @@ Cucumber.SupportCode.StepDefinition = function(regexp, code) {
return regexp.test(stepName);
},

invoke: function invoke(stepName, pyString, callback) {
var parameters = self.buildInvocationParameters(stepName, pyString, function() {
invoke: function invoke(stepName, docString, callback) {
var parameters = self.buildInvocationParameters(stepName, docString, function() {
var stepResult = Cucumber.Runtime.StepResult(true);
callback(stepResult);
});
code.apply(undefined, parameters);
},

buildInvocationParameters: function buildInvocationParameters(stepName, pyString, callback) {
buildInvocationParameters: function buildInvocationParameters(stepName, docString, callback) {
var parameters = regexp.exec(stepName);
parameters.shift();
if (pyString) {
var string = pyString.getString();
if (docString) {
var string = docString.getString();
parameters.push(string);
}
parameters.push(callback);
Expand Down Expand Up @@ -446,10 +446,10 @@ Cucumber.Debug.SimpleAstListener = function(options) {
var failed = false;
var beforeEachScenarioCallbacks = [];
var currentStep;

if (!options)
var options = {};

var self = {
hearBeforeFeatures: function hearBeforeFeatures() { },

Expand All @@ -473,16 +473,16 @@ Cucumber.Debug.SimpleAstListener = function(options) {
},

hearAfterScenario: function hearAfterScenario() { },

hearBeforeStep: function hearBeforeStep(step) {
currentStep = step;
},

hearStepResult: function hearStepResult(stepResult) {
log(currentStep.getKeyword() + currentStep.getName(), 2);
if (currentStep.hasPyString()) {
if (currentStep.hasDocString()) {
log('"""', 3);
log(currentStep.getPyString().getString(), 3);
log(currentStep.getDocString().getString(), 3);
log('"""', 3);
};
},
Expand Down Expand Up @@ -549,7 +549,7 @@ Cucumber.Debug.SgmlAstListener = function() {
hearAfterScenario: function hearAfterScenario() {
console.log(" </scenario>");
},

hearBeforeStep: function hearBeforeStep() {
console.log(" <step>");
},
Expand Down
18 changes: 18 additions & 0 deletions spec/cucumber/ast/doc_string_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require('../../support/spec_helper');

describe("Cucumber.Ast.DocString", function() {
var Cucumber = require('cucumber');
var docString, string, line;

beforeEach(function() {
string = createSpy("DocString string");
line = createSpy("DocString line number");
docString = Cucumber.Ast.DocString(string, line);
});

describe("getString()", function() {
it("returns the string of the DocString", function() {
expect(docString.getString()).toBe(string);
});
});
});
18 changes: 0 additions & 18 deletions spec/cucumber/ast/py_string_spec.js

This file was deleted.

48 changes: 24 additions & 24 deletions spec/cucumber/ast/step_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ require('../../support/spec_helper');
describe("Cucumber.Ast.Step", function() {
var Cucumber = require('cucumber');
var step, keyword, name, stepLine;

beforeEach(function() {
name = createSpy("Step name");
keyword = createSpy("Step keyword");
stepLine = createSpy("Step line");
pyString = createSpy("PY string AST element");
step = Cucumber.Ast.Step(keyword, name, stepLine);
name = createSpy("Step name");
keyword = createSpy("Step keyword");
stepLine = createSpy("Step line");
docString = createSpy("DocString AST element");
step = Cucumber.Ast.Step(keyword, name, stepLine);
});

describe("getKeyword()", function() {
it("returns the keyword of the step", function() {
expect(step.getKeyword()).toBe(keyword);
Expand All @@ -24,27 +24,27 @@ describe("Cucumber.Ast.Step", function() {
});
});

describe("hasPyString()", function() {
it("returns true when a PY string was attached to the step", function() {
step.attachPyString(pyString);
expect(step.hasPyString()).toBeTruthy();
describe("hasDocString()", function() {
it("returns true when a DocString was attached to the step", function() {
step.attachDocString(docString);
expect(step.hasDocString()).toBeTruthy();
});

it("returns false when no PY string was attached to the step", function() {
expect(step.hasPyString()).toBeFalsy();
it("returns false when no DocString was attached to the step", function() {
expect(step.hasDocString()).toBeFalsy();
});
});

describe("getPyString()", function() {
it("returns the PY string that was attached to the step through attachPyString()", function() {
step.attachPyString(pyString);
expect(step.getPyString()).toBe(pyString);
describe("getDocString()", function() {
it("returns the DocString that was attached to the step through attachDocString()", function() {
step.attachDocString(docString);
expect(step.getDocString()).toBe(docString);
});
});

describe("acceptVisitor()", function() {
var visitor, callback;

beforeEach(function() {
visitor = createSpyWithStubs("Visitor", {visitStepResult: null});
callback = createSpy("Callback");
Expand Down Expand Up @@ -78,25 +78,25 @@ describe("Cucumber.Ast.Step", function() {
describe("execute()", function() {
var stepDefinition;
var visitor, callback;

beforeEach(function() {
stepDefinition = createSpy("Step definition");
visitor = createSpy("Visitor");
callback = createSpy("Callback received by execute()");
spyOnStub(stepDefinition, 'invoke');
spyOnStub(visitor, 'lookupStepDefinitionByName').andReturn(stepDefinition);
});

it("looks up the step definition based on the step string", function() {
step.execute(visitor, callback);
expect(visitor.lookupStepDefinitionByName).toHaveBeenCalledWith(name);
});

it("invokes the step definition with the step name, PY string and the callback", function() {
var pyString = createSpy("PY string");
step.attachPyString(pyString);
it("invokes the step definition with the step name, DocString and the callback", function() {
var docString = createSpy("DocString");
step.attachDocString(docString);
step.execute(visitor, callback);
expect(stepDefinition.invoke).toHaveBeenCalledWith(name, pyString, callback);
expect(stepDefinition.invoke).toHaveBeenCalledWith(name, docString, callback);
});
});
});
Loading

0 comments on commit d7b251c

Please sign in to comment.