Skip to content

Commit

Permalink
Refactor Cucumber.Parser to accept a hash of features instead of a si…
Browse files Browse the repository at this point in the history
…ngle feature source string (wip #14)
  • Loading branch information
jbpros committed Aug 9, 2011
1 parent 291e5cb commit dc16a2c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
5 changes: 3 additions & 2 deletions lib/cucumber/parser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var Parser = function(featuresSource) {
var Parser = function(featureSources) {
var Gherkin = require('gherkin');
var Cucumber = require('../cucumber');

Expand All @@ -8,7 +8,8 @@ var Parser = function(featuresSource) {
parse: function parse() {
var Lexer = Gherkin.Lexer('en');
var lexer = new Lexer(self.getEventHandlers());
lexer.scan(featuresSource);
for (i in featureSources)
lexer.scan(featureSources[i]);
return features;
},

Expand Down
2 changes: 1 addition & 1 deletion lib/cucumber/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var Runtime = function(featuresSource, supportCodeDefinition) {
},

parseFeaturesSource: function parseFeaturesSource(featuresSource) {
var parser = Cucumber.Parser(featuresSource);
var parser = Cucumber.Parser({feature: featuresSource});
return parser.parse();
},

Expand Down
14 changes: 9 additions & 5 deletions spec/cucumber/parser_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ require('../support/spec_helper');

describe("Cucumber.Parser", function() {
var Cucumber = require('cucumber');
var parser, featuresSource;
var parser, featureSources;
var features;

beforeEach(function() {
features = createSpy("Root 'features' AST element");
featureSources = {
first_feature : createSpy('first feature source'),
second_feature : createSpy('second feature source')
}
spyOn(Cucumber.Ast, 'Features').andReturn(features);
featuresSource = createSpy('features source string');
parser = Cucumber.Parser(featuresSource);
parser = Cucumber.Parser(featureSources);
});

describe("constructor", function() {
Expand Down Expand Up @@ -46,9 +49,10 @@ describe("Cucumber.Parser", function() {
expect(gherkinLexerConstructor).toHaveBeenCalledWith(eventHandlers);
});

it("asks the lexer to scan the features source", function() {
it("asks the lexer to scan each feature source", function() {
parser.parse();
expect(gherkinLexer.scan).toHaveBeenCalledWith(featuresSource);
expect(gherkinLexer.scan).toHaveBeenCalledWith(featureSources['first_feature']);
expect(gherkinLexer.scan).toHaveBeenCalledWith(featureSources['second_feature']);
});

it("returns the features root element", function() {
Expand Down
4 changes: 2 additions & 2 deletions spec/cucumber/runtime_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ describe("Cucumber.Runtime", function() {

it("creates a new parser", function() {
runtime.parseFeaturesSource(featuresSource);
expect(Cucumber.Parser).toHaveBeenCalledWith(featuresSource);
expect(Cucumber.Parser).toHaveBeenCalledWith({feature: featuresSource});
});

it("asks the parser to parse", function() {
runtime.parseFeaturesSource(featuresSource);
expect(Cucumber.Parser).toHaveBeenCalled();
expect(parser.parse).toHaveBeenCalled();
});

it("it returns the parsed features", function() {
Expand Down

0 comments on commit dc16a2c

Please sign in to comment.