diff --git a/lib/cucumber.js b/lib/cucumber.js index ed135f5a2..17559a670 100644 --- a/lib/cucumber.js +++ b/lib/cucumber.js @@ -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(); @@ -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); @@ -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 }; }, @@ -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); @@ -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() {} @@ -104,7 +104,7 @@ Cucumber.Ast = {}; Cucumber.Ast.Features = function() { var features = Cucumber.Types.Collection(); - + var self = { addFeature: function addFeature(feature) { features.add(feature); @@ -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; @@ -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() { @@ -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) { @@ -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; @@ -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); }, @@ -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)); @@ -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); @@ -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() { }, @@ -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); }; }, @@ -549,7 +549,7 @@ Cucumber.Debug.SgmlAstListener = function() { hearAfterScenario: function hearAfterScenario() { console.log(" "); }, - + hearBeforeStep: function hearBeforeStep() { console.log(" "); }, diff --git a/spec/cucumber/ast/doc_string_spec.js b/spec/cucumber/ast/doc_string_spec.js new file mode 100644 index 000000000..fa56d4ab3 --- /dev/null +++ b/spec/cucumber/ast/doc_string_spec.js @@ -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); + }); + }); +}); diff --git a/spec/cucumber/ast/py_string_spec.js b/spec/cucumber/ast/py_string_spec.js deleted file mode 100644 index d8380cacb..000000000 --- a/spec/cucumber/ast/py_string_spec.js +++ /dev/null @@ -1,18 +0,0 @@ -require('../../support/spec_helper'); - -describe("Cucumber.Ast.PyString", function() { - var Cucumber = require('cucumber'); - var pyString, string, line; - - beforeEach(function() { - string = createSpy("PY string string"); - line = createSpy("PY string line number"); - pyString = Cucumber.Ast.PyString(string, line); - }); - - describe("getString()", function() { - it("returns the string of the PY string", function() { - expect(pyString.getString()).toBe(string); - }); - }); -}); diff --git a/spec/cucumber/ast/step_spec.js b/spec/cucumber/ast/step_spec.js index c20e628dc..45186467b 100644 --- a/spec/cucumber/ast/step_spec.js +++ b/spec/cucumber/ast/step_spec.js @@ -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); @@ -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"); @@ -78,7 +78,7 @@ describe("Cucumber.Ast.Step", function() { describe("execute()", function() { var stepDefinition; var visitor, callback; - + beforeEach(function() { stepDefinition = createSpy("Step definition"); visitor = createSpy("Visitor"); @@ -86,17 +86,17 @@ describe("Cucumber.Ast.Step", function() { 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); }); }); }); diff --git a/spec/cucumber/parser_spec.js b/spec/cucumber/parser_spec.js index 95ad8c4b7..82adf2a86 100644 --- a/spec/cucumber/parser_spec.js +++ b/spec/cucumber/parser_spec.js @@ -4,7 +4,7 @@ describe("Cucumber.Parser", function() { var Cucumber = require('cucumber'); var parser, featuresSource; var features; - + beforeEach(function() { features = createSpy("Root 'features' AST element"); spyOn(Cucumber.Ast, 'Features').andReturn(features); @@ -17,7 +17,7 @@ describe("Cucumber.Parser", function() { expect(Cucumber.Ast.Features).toHaveBeenCalled(); }); }); - + describe("parse()", function() { var Gherkin = require('gherkin'); var gherkinLexerConstructor, gherkinLexer; @@ -30,7 +30,7 @@ describe("Cucumber.Parser", function() { spyOn(Gherkin, 'Lexer').andReturn(gherkinLexerConstructor); spyOn(parser, 'getEventHandlers').andReturn(eventHandlers); }); - + it("loads the gherkin lexer module for English", function() { parser.parse(); expect(Gherkin.Lexer).toHaveBeenCalledWith('en'); @@ -40,7 +40,7 @@ describe("Cucumber.Parser", function() { parser.parse(); expect(parser.getEventHandlers).toHaveBeenCalled(); }); - + it("creates a gherkin lexer", function() { parser.parse(); expect(gherkinLexerConstructor).toHaveBeenCalledWith(eventHandlers); @@ -58,7 +58,7 @@ describe("Cucumber.Parser", function() { describe("getEventHandlers()", function() { var eventHandlers; - + it("tells to bind 'feature' to handleFeature()", function() { spyOn(parser, 'handleFeature'); eventHandlers = parser.getEventHandlers(); @@ -77,10 +77,10 @@ describe("Cucumber.Parser", function() { expect(eventHandlers['step']).toBe(parser.handleStep); }); - it("tells to bind 'py_string' to handlePyString()", function() { - spyOn(parser, 'handlePyString'); + it("tells to bind 'py_string' to handleDocString()", function() { + spyOn(parser, 'handleDocString'); eventHandlers = parser.getEventHandlers(); - expect(eventHandlers['py_string']).toBe(parser.handlePyString); + expect(eventHandlers['py_string']).toBe(parser.handleDocString); }); it("tells to bind 'eof' to handleEof()", function() { @@ -159,7 +159,7 @@ describe("Cucumber.Parser", function() { describe("handleFeature()", function() { var keyword, name, description, line; var feature; - + beforeEach(function() { keyword = createSpy("'feature' keyword"); name = createSpy("Name of the feature"); @@ -180,11 +180,11 @@ describe("Cucumber.Parser", function() { expect(features.addFeature).toHaveBeenCalledWith(feature); }); }); - + describe("handleScenario()", function() { var keyword, name, description, line; var scenario, currentFeature; - + beforeEach(function() { keyword = createSpy("'scenario' keyword"); name = createSpy("Name of the scenario"); @@ -222,7 +222,7 @@ describe("Cucumber.Parser", function() { line = createSpy("Line number"); step = createSpy("Step AST element"); currentScenario = createSpyWithStubs("Current scenario AST element", {addStep: null}); - spyOn(Cucumber.Ast, 'Step').andReturn(step); + spyOn(Cucumber.Ast, 'Step').andReturn(step); spyOn(parser, 'getCurrentScenario').andReturn(currentScenario); }); @@ -242,32 +242,32 @@ describe("Cucumber.Parser", function() { }); }); - describe("handlePyString()", function() { + describe("handleDocString()", function() { var string, line; var currentStep; beforeEach(function() { - string = createSpy("PY string's actual string"); + string = createSpy("DocString's actual string"); line = createSpy("Line number"); - pyString = createSpy("PY string AST element"); - currentStep = createSpyWithStubs("Current step", {attachPyString: null}); - spyOn(Cucumber.Ast, 'PyString').andReturn(pyString); + docString = createSpy("DocString AST element"); + currentStep = createSpyWithStubs("Current step", {attachDocString: null}); + spyOn(Cucumber.Ast, 'DocString').andReturn(docString); spyOn(parser, 'getCurrentStep').andReturn(currentStep); }); - it("creates a new PY string AST element", function() { - parser.handlePyString(string, line); - expect(Cucumber.Ast.PyString).toHaveBeenCalledWith(string, line); + it("creates a new DocString AST element", function() { + parser.handleDocString(string, line); + expect(Cucumber.Ast.DocString).toHaveBeenCalledWith(string, line); }); it("gets the current step AST element", function() { - parser.handlePyString(string, line); + parser.handleDocString(string, line); expect(parser.getCurrentStep).toHaveBeenCalled(); }); - it("attaches the PY string element to the current step", function() { - parser.handlePyString(string, line); - expect(currentStep.attachPyString).toHaveBeenCalledWith(pyString); + it("attaches the DocString element to the current step", function() { + parser.handleDocString(string, line); + expect(currentStep.attachDocString).toHaveBeenCalledWith(docString); }); }); diff --git a/spec/cucumber/support_code/step_definition_spec.js b/spec/cucumber/support_code/step_definition_spec.js index 1f7dab4f7..def9556d0 100644 --- a/spec/cucumber/support_code/step_definition_spec.js +++ b/spec/cucumber/support_code/step_definition_spec.js @@ -3,7 +3,7 @@ require('../../support/spec_helper'); describe("Cucumber.SupportCode.StepDefinition", function() { var Cucumber = require('cucumber'); var stepDefinition, stepRegexp, stepCode; - + beforeEach(function() { stepRegexp = createSpyWithStubs("Step regexp", {test:null}); stepCode = createSpy("Step code"); @@ -16,7 +16,7 @@ describe("Cucumber.SupportCode.StepDefinition", function() { beforeEach(function() { stepName = createSpy("Step name to match"); }); - + it("tests the string against the step name", function() { stepDefinition.matchesStepName(stepName); expect(stepRegexp.test).toHaveBeenCalledWith(stepName); @@ -34,12 +34,12 @@ describe("Cucumber.SupportCode.StepDefinition", function() { }); describe("invoke()", function() { - var stepName, pyString, callback; + var stepName, docString, callback; var parameters; - + beforeEach(function() { stepName = createSpy("Step name to match"); - pyString = createSpy("Step PY string"); + docString = createSpy("Step DocString"); callback = createSpy("Callback"); parameters = createSpy("Code execution parameters"); spyOn(stepDefinition, 'buildInvocationParameters').andReturn(parameters); @@ -47,15 +47,15 @@ describe("Cucumber.SupportCode.StepDefinition", function() { }); it("builds the step invocation parameters", function() { - stepDefinition.invoke(stepName, pyString, callback); + stepDefinition.invoke(stepName, docString, callback); expect(stepDefinition.buildInvocationParameters).toHaveBeenCalled(); expect(stepDefinition.buildInvocationParameters).toHaveBeenCalledWithValueAsNthParameter(stepName, 1); - expect(stepDefinition.buildInvocationParameters).toHaveBeenCalledWithValueAsNthParameter(pyString, 2); + expect(stepDefinition.buildInvocationParameters).toHaveBeenCalledWithValueAsNthParameter(docString, 2); expect(stepDefinition.buildInvocationParameters).toHaveBeenCalledWithAFunctionAsNthParameter(3); }); it("calls the step code with the parameters", function() { - stepDefinition.invoke(stepName, pyString, callback); + stepDefinition.invoke(stepName, docString, callback); expect(stepCode.apply).toHaveBeenCalledWith(undefined, parameters); }); @@ -64,7 +64,7 @@ describe("Cucumber.SupportCode.StepDefinition", function() { var stepResult; beforeEach(function() { - stepDefinition.invoke(stepName, pyString, callback); + stepDefinition.invoke(stepName, docString, callback); codeExecutionCallback = stepDefinition.buildInvocationParameters.mostRecentCall.args[2]; stepResult = createSpy("Step result"); spyOn(Cucumber.Runtime, 'StepResult').andReturn(stepResult); @@ -83,55 +83,55 @@ describe("Cucumber.SupportCode.StepDefinition", function() { }); describe("buildInvocationParameters()", function() { - var stepName, pyString, pyStringString; + var stepName, docString, docStringString; var matches, callback; beforeEach(function() { - stepName = createSpy("Step name to match"); - pyStringString = createSpy("PY string string"); - pyString = createSpyWithStubs("Step PY string", {getString:pyStringString}); - matches = createSpyWithStubs("Matches", {shift:null, push:null}); - callback = createSpy("Callback"); + stepName = createSpy("Step name to match"); + docStringString = createSpy("DocString string"); + docString = createSpyWithStubs("Step DocString", {getString:docStringString}); + matches = createSpyWithStubs("Matches", {shift:null, push:null}); + callback = createSpy("Callback"); spyOnStub(stepRegexp, 'exec').andReturn(matches); }); it("executes the step regexp against the step name", function() { - stepDefinition.buildInvocationParameters(stepName, pyString, callback); + stepDefinition.buildInvocationParameters(stepName, docString, callback); expect(stepRegexp.exec).toHaveBeenCalledWith(stepName); }); it("removes the whole matched string of the regexp result array (to only keep matching groups)", function() { - stepDefinition.buildInvocationParameters(stepName, pyString, callback); + stepDefinition.buildInvocationParameters(stepName, docString, callback); expect(matches.shift).toHaveBeenCalled(); }); - describe("when a pyString is present", function() { - it("gets the PY string's string", function() { - stepDefinition.buildInvocationParameters(stepName, pyString, callback); - expect(pyString.getString).toHaveBeenCalled(); + describe("when a DocString is present", function() { + it("gets the DocString's string", function() { + stepDefinition.buildInvocationParameters(stepName, docString, callback); + expect(docString.getString).toHaveBeenCalled(); }); it("adds the string to the parameter array", function() { - stepDefinition.buildInvocationParameters(stepName, pyString, callback); - expect(matches.push).toHaveBeenCalledWith(pyStringString); + stepDefinition.buildInvocationParameters(stepName, docString, callback); + expect(matches.push).toHaveBeenCalledWith(docStringString); }); }); - describe("when no pyString is present", function() { + describe("when no DocString is present", function() { it("does not add the string to the parameter array", function() { - pyString = undefined; - stepDefinition.buildInvocationParameters(stepName, pyString, callback); + docString = undefined; + stepDefinition.buildInvocationParameters(stepName, docString, callback); expect(matches.push).not.toHaveBeenCalledWith(undefined); }); }); it("adds the callback to the parameter array", function() { - stepDefinition.buildInvocationParameters(stepName, pyString, callback); + stepDefinition.buildInvocationParameters(stepName, docString, callback); expect(matches.push).toHaveBeenCalledWith(callback); }); it("returns the parameters", function() { - expect(stepDefinition.buildInvocationParameters(stepName, pyString, callback)).toBe(matches); + expect(stepDefinition.buildInvocationParameters(stepName, docString, callback)).toBe(matches); }); }); });