From b94b07bf44eaa27147493914423a0d2fe29034c3 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Mon, 8 Oct 2012 16:35:27 +0200 Subject: [PATCH] Bump Gherkin (close #78) --- lib/cucumber/parser.js | 37 ++++++++++++++++++++----------- package.json | 2 +- spec/cucumber/parser_spec.js | 42 ++++++++++++++++++++++++++---------- 3 files changed, 56 insertions(+), 25 deletions(-) diff --git a/lib/cucumber/parser.js b/lib/cucumber/parser.js index 58d4c623f..9423cec61 100644 --- a/lib/cucumber/parser.js +++ b/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; diff --git a/package.json b/package.json index b8b3d1239..f133dddab 100644 --- a/package.json +++ b/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", diff --git a/spec/cucumber/parser_spec.js b/spec/cucumber/parser_spec.js index c6f270d07..655287e62 100644 --- a/spec/cucumber/parser_spec.js +++ b/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(); + }); + }); });