0.0.6 • Published 8 years ago

karma-gherkin_yadda-preprocessor v0.0.6

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

Introduction

This preprocessor translates Gherkin-Features to executable yadda-steps and saves them into one or more files. Actually this package is a wrapper of the module gherkin-yadda for making it runnable in karma.

Installation

npm install --save-dev karma-gherkin_yadda-preprocessor

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 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.3 Overwrite

The existing target file will be overwritten completely.

Configuration:

All mentioned sections are members of karma's config object.

How to include:

Add the name of this package to the plugins section.

plugins: [
    'karma-gherkin_yadda-preprocessor'
]
How to assign:

Assign the value gherkin_yadda to your file match pattern key at the preprocessors section.

preprocessors: {
    'test/features/*.feature': 'gherkin_yadda'
}
How to adjust:

Just append the object gherkin_yaddaPreprocessor as own section. All possible parameters are shown in the example below.

gherkin_yaddaPreprocessor: {
    displayOutputPath: false,
    useChai : true,
    useDefine: true,
    generateFeatureBaseName: true,
    handleExistingFile: 'merge'
}

The default values are:

  • 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'

  • '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

  • add parameter for hooks

Maintainer

kaasbaardje

License

MIT