Skip to content
Browse files

Bump Gherkin (close #78)

  • Loading branch information...
1 parent 2224626 commit b94b07bf44eaa27147493914423a0d2fe29034c3 @jbpros jbpros committed
Showing with 56 additions and 25 deletions.
  1. +24 −13 lib/cucumber/parser.js
  2. +1 −1 package.json
  3. +31 −11 spec/cucumber/parser_spec.js
View
37 lib/cucumber/parser.js
@@ -1,6 +1,7 @@
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);
@@ -8,8 +9,8 @@ var Parser = function(featureSources, astFilter) {
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];
@@ -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
};
},
@@ -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;
View
2 package.json
@@ -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",
View
42 spec/cucumber/parser_spec.js
@@ -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 = [
@@ -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);
});
@@ -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 () {
@@ -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.
Something went wrong with that request. Please try again.