gherkin-yadda

0.1.12 • Public • Published

Introduction

This package translates Gherkin-Features to executable yadda-steps and saves them as a .js file. It is an modified extract of the generate function from an great bdd framework called mimik.

Installation

Global:

npm install -g gherkin-yadda

Local:

npm install --save-dev gherkin-yadda

Example

***From: *** Gherkin

Feature: Login
  In order to access the application
  As a registered user
  I need to be able to log in
  Scenario: Successful login

    Given I am a registered user named "Henk"
    When I enter my credentials and submit the login form
    Then I should see a welcome page

***To: *** yadda step library

'use strict';

module.exports = {
    yaddaStepLibrary: yaddaStepLibrary,
    featureBaseName: 'google.feature'
};

var expect = require('chai').expect;
var Yadda = require('yadda'),
    English = Yadda.localisation.English,
    dictionary = new Yadda.Dictionary()
        .define('number', /(d+)/),
    yaddaStepLibrary = English.library(dictionary);

// Given I am a registered user named "Henk"
yaddaStepLibrary.given(/I am a registered user named "$Henk"/, function(input1, done) {

});

// When I enter my credentials and submit the login form
yaddaStepLibrary.when(/I enter my credentials and submit the login form/, function(done) {

});

// Then I should see a welcome page
yaddaStepLibrary.then(/I should see a welcome page/, function(done) {

});

Special Aspects

1. Context Variables

If a word in a feature step is surrounded by double quotes it can be accessed as an parameter of the generated yadda step callback.
Example:

  • Feature Step:
Given I am a registered user named "Henk"
  • Yadda Step:
yaddaStepLibrary.given(/I am a registered user named "$Henk"/, function(input1, done) {
    ...
});

2. Identical Steps

Identical feature steps are going to be generated only one time.

3. Existing Target File

Ýou can choose between the following options if the target file already exists.

3.1 Abort

Gherkin-yadda will be terminated without generating.

3.2 Append

The generated steps will be appended to the existing file. They are not checked for identical steps.

3.3 Merge

Only the yadda step feature descriptions of the existing target file are going to be overwritten. Comments with identical feature descriptions are staying the same.

3.4 Overwrite

The existing target file will be overwritten completely.

How To Use

1. CLI

1.1 Path Specification:

  • Looks recursively for all .feature files in the current cli-path and creates a .js file of them:
gherkin-yadda

  • Does the same as example 1 but with a written folder cli-path:
gherkin-yadda /"yourFolder"

  • Creates a step.js file of the given .feature file:
gherkin-yadda /"yourFolder"/"yourFile.feature"

1.2 Options:

  • Pattern for defining regex variables of the yadda dictionary:
gherkin-yadda -d

  • Use of chai assert library:
gherkin-yadda -c

  • Add the feature basename:
gherkin-yadda -b

  • abort process if target file exists
gherkin-yadda -t

  • append yadda steps if target file exists
gherkin-yadda -a

  • merge yadda steps if target file exists
gherkin-yadda -m

  • overwrite target file completely if it exists
gherkin-yadda -o

2. Node Module

2.1 Include:

The required module will offer you a generate function. It's return value is the output path:

var gherkinYadda = require(gherkin-yadda),
    outputPath = gherkinYadda.generate();

2.2 Params:

All possible params are handed trough an parameter object. Here's an example of all params:

gherkinYadda.generate({
    featureFilePath: "./test",
    displayOutputPath: true,
    useChai : true,
    useDefine: true,
    generateFeatureBaseName: false,
    handleExistingFile: 'merge'
});

The default values are:

  • featureFilePath: current path
  • displayOutputPath: false
  • useChai : false
  • useDefine: false
  • generateFeatureBaseName: false
  • handleExistingFile: 'terminate'

The use of the param "handleExistingFile" prevents an dialog for already existing target files since it decides in advance how to handle existing target files. Possible values are:

  • 'terminate'
  • 'append'
  • 'merge'
  • 'overwrite'

File Location

All generated files are saved into a folder named "step_definitions". It will be created in those directories where the feature files are found.

Todo

  • Recognize language automatically
  • Add cli option for hooks (-h)
  • Include German Gherkin features
  • Offer a template.json for generating yadda steps

Maintainer

kaasbaardje

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i gherkin-yadda

Weekly Downloads

1

Version

0.1.12

License

MIT

Last publish

Collaborators

  • kaasbaardje