From dc16a2c3ad18958180c2ef23ed2d14ea47d7238b Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Tue, 9 Aug 2011 12:01:19 +0200 Subject: [PATCH] Refactor Cucumber.Parser to accept a hash of features instead of a single feature source string (wip #14) --- lib/cucumber/parser.js | 5 +++-- lib/cucumber/runtime.js | 2 +- spec/cucumber/parser_spec.js | 14 +++++++++----- spec/cucumber/runtime_spec.js | 4 ++-- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/cucumber/parser.js b/lib/cucumber/parser.js index 1fa81f18a..de8662027 100644 --- a/lib/cucumber/parser.js +++ b/lib/cucumber/parser.js @@ -1,4 +1,4 @@ -var Parser = function(featuresSource) { +var Parser = function(featureSources) { var Gherkin = require('gherkin'); var Cucumber = require('../cucumber'); @@ -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; }, diff --git a/lib/cucumber/runtime.js b/lib/cucumber/runtime.js index 6b0e467dc..db4c13841 100644 --- a/lib/cucumber/runtime.js +++ b/lib/cucumber/runtime.js @@ -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(); }, diff --git a/spec/cucumber/parser_spec.js b/spec/cucumber/parser_spec.js index 1d3d871de..27cc7fe27 100644 --- a/spec/cucumber/parser_spec.js +++ b/spec/cucumber/parser_spec.js @@ -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() { @@ -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() { diff --git a/spec/cucumber/runtime_spec.js b/spec/cucumber/runtime_spec.js index 90968b7de..979985437 100644 --- a/spec/cucumber/runtime_spec.js +++ b/spec/cucumber/runtime_spec.js @@ -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() {