Skip to content

Commit

Permalink
Rename Expectation to Step and do some internal refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
BonsaiDen committed Jun 12, 2015
1 parent 70118f4 commit f23a3f9
Show file tree
Hide file tree
Showing 56 changed files with 658 additions and 557 deletions.
4 changes: 2 additions & 2 deletions lib/feature/node/Background.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Background Node ------------------------------------------------------------
function BackgroundNode(given) {
this.type = 'BACKGROUND';
this.given = given;
this._type = 'BACKGROUND';
this._given = given;
}


Expand Down
34 changes: 17 additions & 17 deletions lib/feature/node/Feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,55 @@ var util = require('../../util');

// Feature Node ---------------------------------------------------------------
function FeatureNode(tags, title, description, scenarios, background, loc) {
this.type = 'FEATURE';
this.tags = tags;
this.title = title;
this.description = description;
this.scenarios = scenarios;
this.background = background;
this.loc = loc;
this._type = 'FEATURE';
this._tags = tags;
this._title = title;
this._description = description;
this._scenarios = scenarios;
this._background = background;
this._loc = loc;
}

FeatureNode.prototype = {

getRawTitle: function() {
return this.title;
return this._title;
},

getTitle: function() {
return this.title;
return this._title;
},

getDescription: function() {
return util.extractDescription(this.description);
return util.extractDescription(this._description);
},

getScenarios: function() {
return this.scenarios;
return this._scenarios;
},

getLocation: function() {
return this.loc;
return this._loc;
},

getTags: function() {
return this.tags;
return this._tags;
},

filter: function(ignores, path, options) {
this.scenarios = this.scenarios.filter(function(scenario) {
this._scenarios = this._scenarios.filter(function(scenario) {
return ignores(scenario, path, options) !== true;
});
},

toJSON: function() {
return {
type: this.type,
tags: this.tags,
type: this._type,
tags: this.getTags(),
title: this.getTitle(),
description: this.getDescription(),
location: this.getLocation(),
scenarios: this.scenarios.map(function(scenario) {
scenarios: this.getScenarios().map(function(scenario) {
return scenario.toJSON();
})
};
Expand Down
16 changes: 10 additions & 6 deletions lib/feature/node/File.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
// File Node ------------------------------------------------------------------
function FileNode(filename, features) {
this.type = 'FILE';
this.filename = filename;
this.features = features;
this._type = 'FILE';
this._filename = filename;
this._features = features;
}

// Methods --------------------------------------------------------------------
FileNode.prototype = {

getFeatures: function() {
return this._features;
},

toJSON: function() {
return {
type: this.type,
filename: this.filename,
features: this.features.map(function(feature) {
type: this._type,
filename: this._filename,
features: this._features.map(function(feature) {
return feature.toJSON();
})
};
Expand Down
52 changes: 28 additions & 24 deletions lib/feature/node/Scenario.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,63 @@
// Scenario Node --------------------------------------------------------------
function ScenarioNode(tags, title, steps, examples, loc) {
this.type = 'SCENARIO';
this.tags = tags;
this.title = title.trim();
this.given = steps.given;
this.when = steps.when;
this.then = steps.then;
this.examples = examples;
this.loc = loc;
this._type = 'SCENARIO';
this._tags = tags;
this._title = title.trim();
this._given = steps.given;
this._when = steps.when;
this._then = steps.then;
this._examples = examples;
this._loc = loc;
}


// Methods --------------------------------------------------------------------
ScenarioNode.prototype = {

getRawTitle: function() {
return this.title;
return this._title;
},

getTitle: function() {
return this.title;
return this._title;
},

getExpectations: function() {
var expectations = [];
expectations.push.apply(expectations, this.given);
expectations.push.apply(expectations, this.when);
expectations.push.apply(expectations, this.then);
return expectations;
getSteps: function() {
var steps = [];
steps.push.apply(steps, this._given);
steps.push.apply(steps, this._when);
steps.push.apply(steps, this._then);
return steps;
},

getLocation: function() {
return this.loc;
return this._loc;
},

getTags: function() {
return this.tags;
return this._tags;
},

getExamples: function() {
return this._examples;
},

toJSON: function() {
return {
type: this.type,
tags: this.tags,
type: this._type,
tags: this.getTags(),
title: this.getTitle(),
location: this.getLocation(),
given: this.given.map(function(given) {
given: this._given.map(function(given) {
return given.toJSON();
}),
when: this.when.map(function(when) {
when: this._when.map(function(when) {
return when.toJSON();
}),
then: this.then.map(function(then) {
then: this._then.map(function(then) {
return then.toJSON();
}),
examples: this.examples
examples: this.getExamples()
};
}

Expand Down
48 changes: 24 additions & 24 deletions lib/feature/node/Step.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,64 +5,64 @@ var util = require('../../util');

// Step Node ------------------------------------------------------------------
function StepNode(type, keywords, title, data, and, but, loc, index) {
this._type = type;
this.type = type.toUpperCase();
this.keywords = keywords;
this.title = dedupeTitlePrefix(title.trim(), this.keywords[this._type]);
this.data = data;
this.and = and;
this.but = but;
this.loc = loc;
this.index = index;
this._stepType = type;
this._type = type.toUpperCase();
this._keywords = keywords;
this._title = dedupeTitlePrefix(title.trim(), this._keywords[this._stepType]);
this._data = data;
this._and = and;
this._but = but;
this._loc = loc;
this._index = index;
}

StepNode.prototype = {

getRawTitle: function() {
return this.title;
return this._title;
},

getTitle: function() {
if (this.and) {
return this.keywords['And' + this._type] + ' ' + this.title;
if (this._and) {
return this._keywords['And' + this._stepType] + ' ' + this._title;

} else if (this.but) {
return this.keywords['But' + this._type] + ' ' + this.title;
} else if (this._but) {
return this._keywords['But' + this._stepType] + ' ' + this._title;

} else {
return this.keywords[this._type] + ' ' + this.title;
return this._keywords[this._stepType] + ' ' + this._title;
}
},

getLocation: function() {
return this.loc;
return this._loc;
},

getIndex: function() {
return this.index;
return this._index;
},

getData: function() {
return this.data;
return this._data;
},

clone: function() {
return new StepNode(
this._type,
this.keywords, this.title, this.data,
this.and, this.but,
this.loc, this.index
this._stepType,
this._keywords, this._title, this._data,
this._and, this._but,
this._loc, this._index
);
},

replaceTitle: function(headers, map, cols) {
this.title = util.interpolateStep(this.title, headers, map, cols);
this._title = util.interpolateStep(this._title, headers, map, cols);
return this;
},

toJSON: function() {
return {
type: this.type,
type: this._type,
title: this.getTitle(),
data: this.getData(),
location: this.getLocation()
Expand Down
2 changes: 1 addition & 1 deletion lib/spec/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Parser.prototype = {
files.features.forEach(function(path) {

// Parse Features From File and
featureParser(path.fullpath, true, false).features.forEach(function(feature) {
featureParser(path.fullpath, true, false).getFeatures().forEach(function(feature) {

// Unique Spec ID, by default this is the name of the feature
var sid = matcher(feature, path, options),
Expand Down
10 changes: 5 additions & 5 deletions lib/test/Scenario.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
function Scenario(titleNode, tags, loc) {
this._title = titleNode;
this._tags = tags;
this._expectations = [];
this._steps = [];
this._location = loc;
}

Expand All @@ -18,12 +18,12 @@ Scenario.prototype = {
return this._tags;
},

addExpectation: function(expectation) {
this._expectations.push(expectation);
addStep: function(step) {
this._steps.push(step);
},

getExpectations: function() {
return this._expectations;
getSteps: function() {
return this._steps;
},

getLocation: function() {
Expand Down
36 changes: 36 additions & 0 deletions lib/test/Step.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Scenario -------------------------------------------------------------------
function Step(titleNode, expressionNode, commentPrefix, loc, index) {
this._title = titleNode;
this._expression = expressionNode;
this._commentPrefix = commentPrefix;
this._location = loc;
this._index = index;
}


// Methods --------------------------------------------------------------------
Step.prototype = {

getTitle: function() {
return this._title ? this._title.value.trim().substring(this._commentPrefix.length).trim() : null;
},

hasExpression: function() {
return this._expression !== null;
},

getLocation: function() {
return this._location;
},

getIndex: function() {
return this._index;
}

};


// Exports --------------------------------------------------------------------
// ----------------------------------------------------------------------------
module.exports = Step;

0 comments on commit f23a3f9

Please sign in to comment.