Skip to content

Commit

Permalink
Bump Gherkin (close #78)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbpros committed Oct 8, 2012
1 parent 2224626 commit b94b07b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 25 deletions.
37 changes: 24 additions & 13 deletions lib/cucumber/parser.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
var Parser = function(featureSources, astFilter) {
var Gherkin = require('gherkin');
var Cucumber = require('../cucumber');
var Gherkin = require('gherkin');
var GherkinLexer = require('gherkin/lib/gherkin/lexer/en');
var Cucumber = require('../cucumber');

var features = Cucumber.Ast.Features();
var astAssembler = Cucumber.Ast.Assembler(features, astFilter);
var currentSourceUri;

var self = {
parse: function parse() {
var Lexer = Gherkin.Lexer('en');
var lexer = new Lexer(self.getEventHandlers());
var eventHandler = self.getEventHandlers();
var lexer = new GherkinLexer(self.getEventHandlers());
for (i in featureSources) {
var currentSourceUri = featureSources[i][Parser.FEATURE_NAME_SOURCE_PAIR_URI_INDEX];
var featureSource = featureSources[i][Parser.FEATURE_NAME_SOURCE_PAIR_SOURCE_INDEX];
Expand All @@ -29,15 +30,17 @@ var Parser = function(featureSources, astFilter) {

getEventHandlers: function getEventHandlers() {
return {
background: self.handleBackground,
comment: self.handleComment,
doc_string: self.handleDocString,
eof: self.handleEof,
feature: self.handleFeature,
row: self.handleDataTableRow,
scenario: self.handleScenario,
step: self.handleStep,
tag: self.handleTag
background: self.handleBackground,
comment: self.handleComment,
doc_string: self.handleDocString,
eof: self.handleEof,
feature: self.handleFeature,
row: self.handleDataTableRow,
scenario: self.handleScenario,
step: self.handleStep,
tag: self.handleTag,
scenario_outline: self.handleScenarioOutline,
examples: self.handleExamples
};
},

Expand Down Expand Up @@ -87,6 +90,14 @@ var Parser = function(featureSources, astFilter) {
var uri = self.getCurrentSourceUri();
var tag = Cucumber.Ast.Tag(tag, uri, line);
astAssembler.insertTag(tag);
},

handleScenarioOutline: function handleScenarioOutline(keyword, name, description, line) {
throw new Error("Scenario outlines are not supported yet. See https://github.com/cucumber/cucumber-js/issues/10");
},

handleExamples: function handleExamples(keyword, name, description, line) {
throw new Error("Examples are not supported yet. See https://github.com/cucumber/cucumber-js/issues/10");
}
};
return self;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"node": "0.6 || 0.7 || 0.8"
},
"dependencies": {
"gherkin": "2.11.1",
"gherkin": "2.11.3",
"jasmine-node": "1.0.26",
"connect": "2.3.2",
"browserify": "1.15.5",
Expand Down
42 changes: 31 additions & 11 deletions spec/cucumber/parser_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ require('../support/spec_helper');

describe("Cucumber.Parser", function () {
var Cucumber = requireLib('cucumber');
var gherkinLexerConstructor;
var parser, featureSources;
var features, astFilter, astAssembler;

beforeEach(function () {
gherkinLexerConstructor = spyOnModule("gherkin/lib/gherkin/lexer/en");
features = createSpy("Root 'features' AST element");
astFilter = createSpy("AST filter");
featureSources = [
Expand All @@ -30,29 +32,23 @@ describe("Cucumber.Parser", function () {

describe("parse()", function () {
var Gherkin = require('gherkin');
var gherkinLexerConstructor, gherkinLexer;
var gherkinLexer;
var eventHandlers;

beforeEach(function () {
gherkinLexer = createSpyWithStubs("Gherkin lexer instance", {scan: null});
gherkinLexerConstructor = createSpy("Gherkin lexer module").andReturn(gherkinLexer);
eventHandlers = createSpy("Parser event handlers");
spyOn(Gherkin, 'Lexer').andReturn(gherkinLexerConstructor);
gherkinLexer = createSpyWithStubs("English gherkin lexer instance", {scan: null});
gherkinLexerConstructor.andReturn(gherkinLexer);
eventHandlers = createSpy("Parser event handlers");
spyOn(parser, 'getEventHandlers').andReturn(eventHandlers);
spyOn(parser, 'setCurrentSourceUri');
});

it("loads the gherkin lexer module for English", function () {
parser.parse();
expect(Gherkin.Lexer).toHaveBeenCalledWith('en');
});

it("gets the parse event handlers", function () {
parser.parse();
expect(parser.getEventHandlers).toHaveBeenCalled();
});

it("creates a gherkin lexer", function () {
it("creates a gherkin lexer for the English language", function () {
parser.parse();
expect(gherkinLexerConstructor).toHaveBeenCalledWith(eventHandlers);
});
Expand Down Expand Up @@ -143,6 +139,18 @@ describe("Cucumber.Parser", function () {
eventHandlers = parser.getEventHandlers();
expect(eventHandlers['tag']).toBe(parser.handleTag);
});

it("provides a 'scenario_outline' handler", function () {
spyOn(parser, 'handleScenarioOutline');
eventHandlers = parser.getEventHandlers();
expect(eventHandlers['scenario_outline']).toBe(parser.handleScenarioOutline);
});

it("provides an 'examples' handler", function () {
spyOn(parser, 'handleExamples');
eventHandlers = parser.getEventHandlers();
expect(eventHandlers['examples']).toBe(parser.handleExamples);
});
});

describe("handleBackground()", function () {
Expand Down Expand Up @@ -378,4 +386,16 @@ describe("Cucumber.Parser", function () {
expect(astAssembler.insertTag).toHaveBeenCalledWith(tag);
});
});

describe("handleScenarioOutline()", function () {
it("throws an error", function () {
expect(parser.handleScenarioOutline).toThrow();
});
});

describe("handleExamples()", function () {
it("throws an error", function () {
expect(parser.handleExamples).toThrow();
});
});
});

0 comments on commit b94b07b

Please sign in to comment.