Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Style

  • Loading branch information...
commit d4b2392d72d9fad25ef1ff9902f0f55f411a6220 1 parent c2a9916
Julien Biezemans jbpros authored
4 features/step_definitions/cucumber_steps.js
View
@@ -1,5 +1,5 @@
var cucumberSteps = function() {
- var Given = When = Then = this.defineStep;
+ var Given = When = Then = this.defineStep;
var World = require('./cucumber_world').World;
this.World = World;
@@ -134,7 +134,6 @@ setTimeout(callback.pending, 10);\
When(/^Cucumber runs the feature$/, function(callback) {
this.runFeature({}, callback);
- //callback.pending();
});
When(/^Cucumber runs the features$/, function(callback) {
@@ -278,4 +277,5 @@ callback();\
callback();
});
};
+
module.exports = cucumberSteps;
3  features/step_definitions/cucumber_world.js
View
@@ -292,7 +292,7 @@ proto.assertScenarioNotReportedAsFailing = function assertScenarioNotReportedAsF
};
proto.assertPassedStep = function assertPassedStep(stepName) {
- if (!this.isStepTouched(stepName))
+ if (!this.isStepTouched(stepName))
throw(new Error("Expected step \"" + stepName + "\" to have passed."));
};
@@ -401,4 +401,3 @@ proto.indentCode = function indentCode(code, levels) {
proto.color = require('../../lib/cucumber/util/colors');
exports.World = World;
-
4 features/step_definitions/scenario_execution_steps.js
View
@@ -1,4 +1,4 @@
- var scenario_exection_steps = function() {
+var scenarioExectionSteps = function() {
var Given = When = Then = this.defineStep;
var World = require('./cucumber_world').World;
this.World = World;
@@ -24,4 +24,4 @@
callback();
});
};
-module.exports = scenario_exection_steps;
+module.exports = scenarioExectionSteps;
16 features/step_definitions/scenario_outline_steps.js
View
@@ -1,17 +1,17 @@
-var scenario_outline_steps = function() {
+var scenarioOutlineSteps = function() {
var Given = When = Then = this.defineStep;
var World = require('./cucumber_world').World;
this.World = World;
this.When(/^a (.*) step$/, function (some, callback) {
- this.assertTrue(some === "passing" || some === "failing");
- callback();
- });
-
+ this.assertTrue(some === "passing" || some === "failing");
+ callback();
+ });
+
this.Then(/^i get (.*)$/, function (result, callback) {
this.assertTrue(result === "passed" || result === "skipped");
- callback();
- });
+ callback();
+ });
}
-module.exports = scenario_outline_steps;
+module.exports = scenarioOutlineSteps;
9 features/step_definitions/tag_steps.js
View
@@ -1,4 +1,4 @@
- var tag_steps = function() {
+var tagSteps = function() {
var Given = When = Then = this.defineStep;
var World = require('./cucumber_world').World;
this.World = World;
@@ -79,8 +79,7 @@
When(/^Cucumber executes scenarios tagged with "([^"]*)" but not with both "([^"]*)" and "([^"]*)"$/, function(tag1, tag2, tag3, callback) {
this.runFeature({tags: [tag1, '~' + tag2, '~' + tag3]}, callback);
-});
-
-
+ });
};
-module.exports = tag_steps
+
+module.exports = tagSteps;
28 lib/cucumber/ast.js
View
@@ -1,15 +1,15 @@
-var Ast = {};
-Ast.Assembler = require('./ast/assembler');
-Ast.Background = require('./ast/background');
-Ast.DataTable = require('./ast/data_table');
-Ast.DocString = require('./ast/doc_string');
-Ast.Feature = require('./ast/feature');
-Ast.Features = require('./ast/features');
-Ast.Filter = require('./ast/filter');
-Ast.Scenario = require('./ast/scenario');
+var Ast = {};
+Ast.Assembler = require('./ast/assembler');
+Ast.Background = require('./ast/background');
+Ast.DataTable = require('./ast/data_table');
+Ast.DocString = require('./ast/doc_string');
+Ast.Feature = require('./ast/feature');
+Ast.Features = require('./ast/features');
+Ast.Filter = require('./ast/filter');
+Ast.Scenario = require('./ast/scenario');
Ast.ScenarioOutline = require('./ast/scenario_outline');
-Ast.OutlineStep = require('./ast/outline_step');
-Ast.Examples = require('./ast/examples');
-Ast.Step = require('./ast/step');
-Ast.Tag = require('./ast/tag');
-module.exports = Ast;
+Ast.OutlineStep = require('./ast/outline_step');
+Ast.Examples = require('./ast/examples');
+Ast.Step = require('./ast/step');
+Ast.Tag = require('./ast/tag');
+module.exports = Ast;
9 lib/cucumber/ast/assembler.js
View
@@ -82,14 +82,13 @@ var Assembler = function (features, filter) {
currentFeature.addFeatureElement(scenario);
}
},
+
insertExamples: function insertExamples(examples) {
var currentScenarioOrBackground = self.getCurrentScenarioOrBackground();
- if(currentScenarioOrBackground.payloadType == 'scenarioOutline'){
+ if (currentScenarioOrBackground.payloadType == 'scenarioOutline')
currentScenarioOrBackground.setExamples(examples);
- }
- else{
- throw new Error("You must only use examples inside of a scenario outline");
- }
+ else
+ throw new Error("Examples are allowed inside scenario outlines only");
self.setCurrentStep(examples);
},
4 lib/cucumber/ast/data_table/row.js
View
@@ -5,10 +5,10 @@ var Row = function(cells, uri, line) {
raw: function raw() {
return cells;
},
+
getLine: function getLine(){
- return line;
+ return line;
}
-
};
return self;
}
90 lib/cucumber/ast/examples.js
View
@@ -1,49 +1,51 @@
var Examples = function (keyword, name, description, line) {
- var Cucumber = require('../../cucumber'),
- dataTable,
- self;
- return self = {
- getKeyword: function getKeyword() {
- return keyword;
- },
-
- getName: function getName() {
- return name;
- },
-
- getDescription: function getDescription() {
- return description;
- },
-
- getLine: function getLine() {
- return line;
- },
-
- getDataTable: function getDataTable() {
- return dataTable;
- },
-
- hasDataTable: function hasDataTable() {
- return !!dataTable;
- },
-
- attachDataTable: function attachDataTable(_dataTable) {
- dataTable = _dataTable;
- },
-
- attachDataTableRow: function attachDataTableRow(row) {
- self.ensureDataTableIsAttached();
- var dataTable = self.getDataTable();
- dataTable.attachRow(row);
- },
-
- ensureDataTableIsAttached: function ensureDataTableIsAttached() {
- var dataTable = self.getDataTable();
- if (!dataTable) {
- dataTable = Cucumber.Ast.DataTable();
- self.attachDataTable(dataTable);
- }
+ var Cucumber = require('../../cucumber');
+ var dataTable;
+
+ var self = {
+ getKeyword: function getKeyword() {
+ return keyword;
+ },
+
+ getName: function getName() {
+ return name;
+ },
+
+ getDescription: function getDescription() {
+ return description;
+ },
+
+ getLine: function getLine() {
+ return line;
+ },
+
+ getDataTable: function getDataTable() {
+ return dataTable;
+ },
+
+ hasDataTable: function hasDataTable() {
+ return !!dataTable;
+ },
+
+ attachDataTable: function attachDataTable(_dataTable) {
+ dataTable = _dataTable;
+ },
+
+ attachDataTableRow: function attachDataTableRow(row) {
+ self.ensureDataTableIsAttached();
+ var dataTable = self.getDataTable();
+ dataTable.attachRow(row);
+ },
+
+ ensureDataTableIsAttached: function ensureDataTableIsAttached() {
+ var dataTable = self.getDataTable();
+ if (!dataTable) {
+ dataTable = Cucumber.Ast.DataTable();
+ self.attachDataTable(dataTable);
}
}
+ };
+
+ return self;
};
module.exports = Examples;
14 lib/cucumber/ast/outline_step.js
View
@@ -1,19 +1,19 @@
var OutlineStep = function(keyword, name, uri, line) {
var Cucumber = require('../../cucumber');
var self = Cucumber.Ast.Step(keyword, name, uri, line);
-
+
self.setOriginalStep = function setOriginalStep(originalStep){
- self.originalStep = originalStep;
+ self.originalStep = originalStep;
};
-
+
self.getOriginalStep = function getOriginalStep(originalStep){
- return self.originalStep;
+ return self.originalStep;
};
-
+
self.isOutlineStep = function isOutlineStep(){
return true;
};
-
+
return self;
};
-module.exports = OutlineStep;
+module.exports = OutlineStep;
9 lib/cucumber/ast/scenario.js
View
@@ -8,6 +8,7 @@ var Scenario = function(keyword, name, description, uri, line) {
var self = {
payloadType: 'scenario',
+
setBackground: function setBackground(newBackground) {
background = newBackground;
},
@@ -58,16 +59,16 @@ var Scenario = function(keyword, name, description, uri, line) {
});
return max;
},
-
+
setSteps: function setSteps(newSteps){
steps = newSteps;
},
-
+
getSteps: function getSteps(){
return steps;
},
- addTags: function setTags(newTags) {
+ addTags: function addTags(newTags) {
tags = tags.concat(newTags);
},
@@ -104,7 +105,7 @@ var Scenario = function(keyword, name, description, uri, line) {
},
instructVisitorToVisitSteps: function instructVisitorToVisitSteps(visitor, steps, callback) {
- steps.forEach(function(step, iterate) {
+ steps.forEach(function(step, iterate) {
visitor.visitStep(step, iterate);
}, callback);
}
205 lib/cucumber/ast/scenario_outline.js
View
@@ -1,108 +1,107 @@
var ScenarioOutline = function (keyword, name, description, uri, line) {
- var Cucumber = require('../../cucumber');
- var self = Cucumber.Ast.Scenario(keyword, name, description, uri, line);
- var examples = [];
-
- self.payloadType = 'scenarioOutline';
-
- self.setExamples = function (newExamples) {
- examples = newExamples;
- };
-
- function buildScenario(row) {
- var newSteps = self.applyExampleRow(row.example, self.getSteps());
- var subScenario = Cucumber.Ast.Scenario(keyword, name, description, uri, line);
- subScenario.setSteps(newSteps);
- return subScenario;
- }
-
- self.buildScenarios = function () {
- var rows = examples.getDataTable().getRows(),
- firstRow = rows.shift().raw();
-
- rows.syncForEach(function (row, index) {
- row.example = {};
- row.id = index;
- for (var i = 0, ii = firstRow.length; i < ii; i++) {
- row.example[firstRow[i]] = row.raw()[i];
- }
+ var Cucumber = require('../../cucumber');
+ var self = Cucumber.Ast.Scenario(keyword, name, description, uri, line);
+ var examples = [];
+
+ self.payloadType = 'scenarioOutline';
+
+ self.setExamples = function (newExamples) {
+ examples = newExamples;
+ };
+
+ function buildScenario(row) {
+ var newSteps = self.applyExampleRow(row.example, self.getSteps());
+ var subScenario = Cucumber.Ast.Scenario(keyword, name, description, uri, line);
+ subScenario.setSteps(newSteps);
+ return subScenario;
+ }
+
+ self.buildScenarios = function () {
+ var rows = examples.getDataTable().getRows();
+ var firstRow = rows.shift().raw();
+
+ rows.syncForEach(function (row, index) {
+ row.example = {};
+ row.id = index;
+ for (var i = 0, ii = firstRow.length; i < ii; i++) {
+ row.example[firstRow[i]] = row.raw()[i];
+ }
+ });
+
+ var scenarios = Cucumber.Type.Collection();
+ rows.syncForEach(function (row) {
+ scenarios.add(buildScenario(row));
+ });
+ return scenarios;
+ };
+
+ self.getExamples = function () {
+ return examples;
+ };
+
+ self.applyExampleRow = function (example, steps) {
+ return steps.syncMap(function (step) {
+ var name = step.getName();
+ var table = Cucumber.Ast.DataTable();
+ var rows = [];
+ var hasDocString = step.hasDocString();
+ var hasDataTable = step.hasDataTable();
+ var oldDocString = hasDocString ? step.getDocString() : null;
+ var docString = hasDocString ? oldDocString.getContents() : null;
+
+ if (hasDataTable) {
+ step.getDataTable().getRows().syncForEach(function (row) {
+ var newRow = {
+ line: row.getLine(),
+ cells: JSON.stringify(row.raw())
+ };
+ rows.push(newRow);
});
-
- var scenarios = Cucumber.Type.Collection();
- rows.syncForEach(function (row) {
- scenarios.add(buildScenario(row));
- });
- return scenarios;
- };
-
- self.getExamples = function () {
- return examples;
- };
-
- self.applyExampleRow = function (example, steps) {
- return steps.syncMap(function (step) {
- var name = step.getName(),
- table = Cucumber.Ast.DataTable(),
- rows = [],
- hasDocString = step.hasDocString(),
- hasDataTable = step.hasDataTable(),
- oldDocString = hasDocString ? step.getDocString() : null,
- docString = hasDocString ? oldDocString.getContents() : null;
-
- if (hasDataTable) {
- step.getDataTable().getRows().syncForEach(function (row) {
- var newRow = {
- line: row.getLine(),
- cells: JSON.stringify(row.raw())
- };
- rows.push(newRow);
- });
- }
-
- for (var hashKey in example) {
- if (Object.prototype.hasOwnProperty.call(example, hashKey)) {
- var findText = '<' + hashKey + '>';
- var exampleData = example[hashKey];
-
- name = name.replace(findText, exampleData);
-
- if (hasDataTable) {
- rows = rows.map(function (row) {
- return {
- line: row.line,
- cells: row.cells.replace(findText, exampleData)
- };
- });
- }
-
- if (hasDocString) {
- docString = docString.replace(findText, exampleData);
- }
- }
- }
-
-
- var newStep = Cucumber.Ast.OutlineStep(step.getKeyword(), name, uri, step.getLine());
- newStep.setOriginalStep(Cucumber.Ast.Step(step.getKeyword(), step.getName(), step.getUri(), step.getLine()));
-
- if (hasDataTable) {
- rows.forEach(function (row) {
- table.attachRow(Cucumber.Ast.DataTable.Row(JSON.parse(row.cells), row.line));
- });
- newStep.attachDataTable(table);
- }
-
- if (hasDocString) {
- newStep.attachDocString(Cucumber.Ast.DocString(oldDocString.getContentType(), docString, oldDocString.getLine()));
- }
- return newStep;
+ }
+
+ for (var hashKey in example) {
+ if (Object.prototype.hasOwnProperty.call(example, hashKey)) {
+ var findText = '<' + hashKey + '>';
+ var exampleData = example[hashKey];
+
+ name = name.replace(findText, exampleData);
+
+ if (hasDataTable) {
+ rows = rows.map(function (row) {
+ return {
+ line: row.line,
+ cells: row.cells.replace(findText, exampleData)
+ };
+ });
+ }
+
+ if (hasDocString) {
+ docString = docString.replace(findText, exampleData);
+ }
+ }
+ }
+
+ var newStep = Cucumber.Ast.OutlineStep(step.getKeyword(), name, uri, step.getLine());
+ newStep.setOriginalStep(Cucumber.Ast.Step(step.getKeyword(), step.getName(), step.getUri(), step.getLine()));
+
+ if (hasDataTable) {
+ rows.forEach(function (row) {
+ table.attachRow(Cucumber.Ast.DataTable.Row(JSON.parse(row.cells), row.line));
});
- };
+ newStep.attachDataTable(table);
+ }
+
+ if (hasDocString) {
+ newStep.attachDocString(Cucumber.Ast.DocString(oldDocString.getContentType(), docString, oldDocString.getLine()));
+ }
+ return newStep;
+ });
+ };
+
+ self.acceptVisitor = function (visitor, callback) {
+ callback();
+ };
- self.acceptVisitor = function (visitor, callback) {
- callback();
- };
-
- return self;
+ return self;
};
-module.exports = ScenarioOutline;
+module.exports = ScenarioOutline;
18 lib/cucumber/ast/step.js
View
@@ -8,9 +8,9 @@ var Step = function(keyword, name, uri, line) {
},
isOutlineStep: function isOutlineStep(){
- return false;
+ return false;
},
-
+
getKeyword: function getKeyword() {
return keyword;
},
@@ -89,43 +89,43 @@ var Step = function(keyword, name, uri, line) {
isOutcomeStep: function isOutcomeStep() {
var isOutcomeStep =
- self.hasOutcomeStepKeyword() || self.isRepeatingOutcomeStep();
+ self.hasOutcomeStepKeyword() || self.isRepeatingOutcomeStep();
return isOutcomeStep;
},
isEventStep: function isEventStep() {
var isEventStep =
- self.hasEventStepKeyword() || self.isRepeatingEventStep();
+ self.hasEventStepKeyword() || self.isRepeatingEventStep();
return isEventStep;
},
hasOutcomeStepKeyword: function hasOutcomeStepKeyword() {
var hasOutcomeStepKeyword =
- keyword == Step.OUTCOME_STEP_KEYWORD;
+ keyword == Step.OUTCOME_STEP_KEYWORD;
return hasOutcomeStepKeyword;
},
hasEventStepKeyword: function hasEventStepKeyword() {
var hasEventStepKeyword =
- keyword == Step.EVENT_STEP_KEYWORD;
+ keyword == Step.EVENT_STEP_KEYWORD;
return hasEventStepKeyword;
},
isRepeatingOutcomeStep: function isRepeatingOutcomeStep() {
var isRepeatingOutcomeStep =
- self.hasRepeatStepKeyword() && self.isPrecededByOutcomeStep();
+ self.hasRepeatStepKeyword() && self.isPrecededByOutcomeStep();
return isRepeatingOutcomeStep;
},
isRepeatingEventStep: function isRepeatingEventStep() {
var isRepeatingEventStep =
- self.hasRepeatStepKeyword() && self.isPrecededByEventStep();
+ self.hasRepeatStepKeyword() && self.isPrecededByEventStep();
return isRepeatingEventStep;
},
hasRepeatStepKeyword: function hasRepeatStepKeyword() {
var hasRepeatStepKeyword =
- keyword == Step.AND_STEP_KEYWORD || keyword == Step.BUT_STEP_KEYWORD || keyword == Step.STAR_STEP_KEYWORD;
+ keyword == Step.AND_STEP_KEYWORD || keyword == Step.BUT_STEP_KEYWORD || keyword == Step.STAR_STEP_KEYWORD;
return hasRepeatStepKeyword;
},
5 lib/cucumber/parser.js
View
@@ -41,7 +41,6 @@ var Parser = function(featureSources, astFilter) {
tag: self.handleTag,
scenario_outline: self.handleScenarioOutline,
examples: self.handleExamples
-
};
},
@@ -80,21 +79,25 @@ var Parser = function(featureSources, astFilter) {
var scenario = Cucumber.Ast.Scenario(keyword, name, description, uri, line);
astAssembler.insertScenario(scenario);
},
+
handleStep: function handleStep(keyword, name, line) {
var uri = self.getCurrentSourceUri();
var step = Cucumber.Ast.Step(keyword, name, uri, line);
astAssembler.insertStep(step);
},
+
handleTag: function handleTag(tag, line) {
var uri = self.getCurrentSourceUri();
var tag = Cucumber.Ast.Tag(tag, uri, line);
astAssembler.insertTag(tag);
},
+
handleScenarioOutline: function handleScenarioOutline(keyword, name, description, line) {
var uri = self.getCurrentSourceUri();
var outline = Cucumber.Ast.ScenarioOutline(keyword, name, description, uri, line);
astAssembler.insertScenario(outline);
},
+
handleExamples: function handleExamples(keyword, name, description, line) {
var examples = Cucumber.Ast.Examples(keyword, name, description, line);
astAssembler.insertExamples(examples);
14 lib/cucumber/runtime/ast_tree_walker.js
View
@@ -42,9 +42,9 @@ var AstTreeWalker = function(features, supportCodeLibrary, listeners) {
supportCodeLibrary.instantiateNewWorld(function(world) {
self.setWorld(world);
self.witnessNewScenario();
- var payload = { };
- payload[scenario.payloadType] = scenario;
- var event = AstTreeWalker.Event(AstTreeWalker[scenario.payloadType.toUpperCase() + '_EVENT_NAME'], payload);
+ var payload = {};
+ payload[scenario.payloadType] = scenario;
+ var event = AstTreeWalker.Event(AstTreeWalker[scenario.payloadType.toUpperCase() + '_EVENT_NAME'], payload);
var hookedUpScenarioVisit = supportCodeLibrary.hookUpFunction(
function(callback) { scenario.acceptVisitor(self, callback); },
scenario,
@@ -57,9 +57,10 @@ var AstTreeWalker = function(features, supportCodeLibrary, listeners) {
);
});
},
+
visitRow: function visitRow(row, scenario,callback){
- var payload = {exampleRow:row},
- event = AstTreeWalker.Event(AstTreeWalker.ROW_EVENT_NAME, payload);
+ var payload = {exampleRow:row};
+ var event = AstTreeWalker.Event(AstTreeWalker.ROW_EVENT_NAME, payload);
self.witnessNewScenario();
self.broadcastEventAroundUserFunction(
event,
@@ -69,6 +70,7 @@ var AstTreeWalker = function(features, supportCodeLibrary, listeners) {
callback
);
},
+
visitStep: function visitStep(step, callback) {
var payload = { step: step };
var event = AstTreeWalker.Event(AstTreeWalker.STEP_EVENT_NAME, payload);
@@ -210,7 +212,7 @@ AstTreeWalker.FEATURES_EVENT_NAME = 'Features';
AstTreeWalker.FEATURE_EVENT_NAME = 'Feature';
AstTreeWalker.BACKGROUND_EVENT_NAME = 'Background';
AstTreeWalker.SCENARIO_EVENT_NAME = 'Scenario';
-AstTreeWalker.SCENARIOOUTLINE_EVENT_NAME = 'ScenarioOutline';
+AstTreeWalker.SCENARIO_OUTLINE_EVENT_NAME = 'ScenarioOutline';
AstTreeWalker.STEP_EVENT_NAME = 'Step';
AstTreeWalker.STEP_RESULT_EVENT_NAME = 'StepResult';
AstTreeWalker.ROW_EVENT_NAME = 'ExampleRow';
3  lib/cucumber/support_code/library.js
View
@@ -66,8 +66,7 @@ var Library = function(supportCodeDefinition) {
},
instantiateNewWorld: function instantiateNewWorld(callback) {
- var world;
- world = new worldConstructor(function (explicitWorld) {
+ var world = new worldConstructor(function (explicitWorld) {
process.nextTick(function () { // release the constructor
callback(explicitWorld || world);
});
70 lib/cucumber/support_code/step_definition_snippet_builder.js
View
@@ -1,24 +1,23 @@
-var _ = require('underscore'),
- stepDefinitionSnippetBuilderSyntax = require ('./step_definition_snippet_builder_syntax');
- _.str = require('underscore.string');
+var _ = require('underscore');
+var stepDefinitionSnippetBuilderSyntax = require('./step_definition_snippet_builder_syntax');
+_.str = require('underscore.string');
-var StepDefinitionSnippetBuilder = function(step, syntax) {
+var StepDefinitionSnippetBuilder = function (step, syntax) {
var Cucumber = require('../../cucumber');
-
var self = {
buildSnippet: function buildSnippet() {
var functionName = self.buildStepDefinitionFunctionName();
var pattern = self.buildStepDefinitionPattern();
var parameters = self.buildStepDefinitionParameters();
var snippet =
- syntax.getStepDefinitionStart() +
- functionName +
- syntax.getStepDefinitionInner1() +
- pattern +
- syntax.getStepDefinitionInner2() +
- parameters +
- syntax.getStepDefinitionEnd();
+ syntax.getStepDefinitionStart() +
+ functionName +
+ syntax.getStepDefinitionInner1() +
+ pattern +
+ syntax.getStepDefinitionInner2() +
+ parameters +
+ syntax.getStepDefinitionEnd();
return snippet;
},
@@ -33,27 +32,24 @@ var StepDefinitionSnippetBuilder = function(step, syntax) {
return functionName;
},
- buildStepDefinitionPattern: function buildStepDefinitionPattern() {
+ buildStepDefinitionPattern: function buildStepDefinitionPattern() {
var stepName = step.isOutlineStep() ? step.getOriginalStep().getName() : step.getName();
- //var stepName = step.getName();
var escapedStepName = Cucumber.Util.RegExp.escapeString(stepName);
var parameterizedStepName = self.parameterizeStepName(escapedStepName);
var pattern =
- syntax.getPatternStart() +
- parameterizedStepName +
- syntax.getPatternEnd();
+ syntax.getPatternStart() +
+ parameterizedStepName +
+ syntax.getPatternEnd();
return pattern;
},
buildStepDefinitionParameters: function buildStepDefinitionParameters() {
var parameters = self.getStepDefinitionPatternMatchingGroupParameters();
-
if (step.hasDocString())
parameters = parameters.concat([syntax.getStepDefinitionDocString()]);
else if (step.hasDataTable())
parameters = parameters.concat([syntax.getStepDefinitionDataTable()]);
- var parametersAndCallback =
- parameters.concat([syntax.getStepDefinitionCallback()]);
+ var parametersAndCallback = parameters.concat([syntax.getStepDefinitionCallback()]);
var parameterString = parametersAndCallback.join(syntax.getFunctionParameterSeparator());
return parameterString;
},
@@ -61,45 +57,41 @@ var StepDefinitionSnippetBuilder = function(step, syntax) {
getStepDefinitionPatternMatchingGroupParameters: function getStepDefinitionPatternMatchingGroupParameters() {
var parameterCount = self.countStepDefinitionPatternMatchingGroups();
var parameters = [];
- _(parameterCount).times(function(n) {
- var offset = n + 1;
+ _(parameterCount).times(function (n) {
+ var offset = n + 1;
parameters.push('arg' + offset);
});
-
var stepName = step.isOutlineStep() ? step.getOriginalStep().getName() : step.getName();
var outlineParams = stepName.match(StepDefinitionSnippetBuilder.OUTLINE_STRING_PATTERN);
- function cleanParam(param){
- return _.str.camelize(param.substr(1,param.length - 2));
+ function cleanParam(param){
+ return _.str.camelize(param.substr(1,param.length - 2));
}
var cleaned = _.map(outlineParams, cleanParam);
-
-
return parameters.concat(cleaned);
- },
+ },
countStepDefinitionPatternMatchingGroups: function countStepDefinitionPatternMatchingGroups() {
var stepDefinitionPattern = self.buildStepDefinitionPattern();
- var numberMatchingGroupCount =
- Cucumber.Util.String.count(stepDefinitionPattern, syntax.getNumberMatchingGroup());
- var quotedStringMatchingGroupCount =
- Cucumber.Util.String.count(stepDefinitionPattern, syntax.getQuotedStringMatchingGroup());
+ var numberMatchingGroupCount = Cucumber.Util.String.count(stepDefinitionPattern, syntax.getNumberMatchingGroup());
+ var quotedStringMatchingGroupCount = Cucumber.Util.String.count(stepDefinitionPattern, syntax.getQuotedStringMatchingGroup());
var count = numberMatchingGroupCount + quotedStringMatchingGroupCount;
return count;
},
parameterizeStepName: function parameterizeStepName(stepName) {
var parameterizedStepName =
- stepName
- .replace(StepDefinitionSnippetBuilder.NUMBER_PATTERN, syntax.getNumberMatchingGroup())
- .replace(StepDefinitionSnippetBuilder.QUOTED_STRING_PATTERN, syntax.getQuotedStringMatchingGroup())
- .replace(StepDefinitionSnippetBuilder.OUTLINE_STRING_PATTERN, syntax.getOutlineExampleMatchingGroup());
+ stepName
+ .replace(StepDefinitionSnippetBuilder.NUMBER_PATTERN, syntax.getNumberMatchingGroup())
+ .replace(StepDefinitionSnippetBuilder.QUOTED_STRING_PATTERN, syntax.getQuotedStringMatchingGroup())
+ .replace(StepDefinitionSnippetBuilder.OUTLINE_STRING_PATTERN, syntax.getOutlineExampleMatchingGroup());
return parameterizedStepName;
}
};
return self;
};
-StepDefinitionSnippetBuilder.NUMBER_PATTERN = /\d+/gi;
-StepDefinitionSnippetBuilder.QUOTED_STRING_PATTERN = /"[^"]*"/gi;
-StepDefinitionSnippetBuilder.OUTLINE_STRING_PATTERN = /<[^>]*>/gi;
+StepDefinitionSnippetBuilder.NUMBER_PATTERN = /\d+/gi;
+StepDefinitionSnippetBuilder.QUOTED_STRING_PATTERN = /"[^"]*"/gi;
+StepDefinitionSnippetBuilder.OUTLINE_STRING_PATTERN = /<[^>]*>/gi;
+
module.exports = StepDefinitionSnippetBuilder;
105 lib/cucumber/type/collection.js
View
@@ -1,51 +1,58 @@
var Collection = function () {
- var items = new Array();
- var self = {
- add: function add(item) {
- items.push(item);
- },
- unshift: function unshift(item) {
- items.unshift(item);
- },
- shift: function shift() {
- return items.shift();
- },
- getLast: function getLast() {
- return items[items.length - 1];
- },
- syncForEach: function syncForEach(userFunction) {
- items.forEach(userFunction);
- },
- forEach: function forEach(userFunction, callback) {
- var itemsCopy = items.slice(0);
-
- function iterate() {
- if (itemsCopy.length > 0) {
- processItem();
- } else {
- callback();
- };
- }
-
- function processItem() {
- var item = itemsCopy.shift();
- userFunction(item, function () {
- iterate();
- });
- };
- iterate();
- },
- syncMap: function map(userFunction) {
- var newCollection = Collection();
- items.map(function (item) {
- newCollection.add(userFunction(item));
- });
- return newCollection;
- },
- length: function length() {
- return items.length;
- }
- };
- return self;
+ var items = new Array();
+ var self = {
+ add: function add(item) {
+ items.push(item);
+ },
+
+ unshift: function unshift(item) {
+ items.unshift(item);
+ },
+
+ shift: function shift() {
+ return items.shift();
+ },
+
+ getLast: function getLast() {
+ return items[items.length - 1];
+ },
+
+ syncForEach: function syncForEach(userFunction) {
+ items.forEach(userFunction);
+ },
+
+ forEach: function forEach(userFunction, callback) {
+ var itemsCopy = items.slice(0);
+
+ function iterate() {
+ if (itemsCopy.length > 0) {
+ processItem();
+ } else {
+ callback();
+ };
+ }
+
+ function processItem() {
+ var item = itemsCopy.shift();
+ userFunction(item, function () {
+ iterate();
+ });
+ };
+ iterate();
+ },
+
+ syncMap: function map(userFunction) {
+ var newCollection = Collection();
+ items.map(function (item) {
+ newCollection.add(userFunction(item));
+ });
+ return newCollection;
+ },
+
+ length: function length() {
+ return items.length;
+ }
+ };
+ return self;
};
-module.exports = Collection;
+module.exports = Collection;
Please sign in to comment.
Something went wrong with that request. Please try again.