Skip to content

Commit

Permalink
Feature/7/step groups (#25)
Browse files Browse the repository at this point in the history
* stepGroup test
  • Loading branch information
judit-nahaj committed Jan 31, 2018
1 parent 67faa8f commit 9649bb1
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Added predefined precompiler: removeDuplicates ([#10](https://github.com/judit-nahaj/gherkin-precompiler/issues/10))
- Added predefined precompiler: scenarioNumbering ([#6](https://github.com/judit-nahaj/gherkin-precompiler/issues/6))
- Added predefined precompiler: stepGroups ([#7](https://github.com/judit-nahaj/gherkin-precompiler/issues/7))

### Fixed

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ compiler.save('./features/dist/login.feature', ast, {
* [Replacer](lib/builtIn/Replacer.md) - Replaces keywords in the feature files.
* [ScenarioNumbering](lib/builtIn/ScenarioNumbering.md) - Adds an index to all scenario and scenario outline's name.
* [ScenarioOutlineNumbering](lib/builtIn/ScenarioOutlineNumbering.md) - Makes all scenario, generated from scenario outlines unique.
* [SteoGroups](lib/builtIn/StepGroups.md) - Corrects the gherkin keywords of steps to make the tests more readable.

## CLI

Expand Down
24 changes: 24 additions & 0 deletions lib/builtIn/StepGroups.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';

/**
* The StepGroups precompiler is responsible
* for setting the correct keywords for steps to make scenarios readable
* @class
* @extends DefaultConfig
*/

class StepGroups {
onScenario(scenario) {
scenario.useReadableStepKeywords();
}

onScenarioOutline(scenarioOutline) {
scenarioOutline.useReadableStepKeywords();
}

onBackground(background) {
background.useReadableStepKeywords();
}
}

module.exports = StepGroups;
24 changes: 24 additions & 0 deletions lib/builtIn/StepGroups.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# StepGroups for Gherkin precompiler

The StepGroups precompiler is responsible for correcting the gherkin keywords of steps to make the tests more readable.

Example:
```gherkin
Given the page is opened
Given the settings are deleted
When the settings menu item is clicked
When the advanced settings link is clicked
Then the advanced settings should be loaded
Then the basic settings link should be visible
```
It will be modified to:

```gherkin
Given the page is opened
And the settings are deleted
When the settings menu item is clicked
And the advanced settings link is clicked
Then the advanced settings should be loaded
And the basic settings link should be visible
```

1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@ API.builtIn.RemoveDuplicates = require('./builtIn/RemoveDuplicates');
API.builtIn.Replacer = require('./builtIn/Replacer');
API.builtIn.ScenarioNumbering = require('./builtIn/ScenarioNumbering');
API.builtIn.ScenarioOutlineNumbering = require('./builtIn/ScenarioOutlineNumbering');
API.builtIn.StepGroups = require('./builtIn/StepGroups');

module.exports = API;
20 changes: 20 additions & 0 deletions test/builtIn/StepGroups.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';
const path = require('path');
const StepGroups = require(path.resolve('lib/builtIn/StepGroups.js'));
const expect = require('chai').expect;
const API = require(path.resolve('lib'));

describe('builtIn.StepGroups', () => {
it('should be available through API', () => {
expect(API.builtIn.StepGroups).to.equal(StepGroups);
});

it('should process feature files with default config', () => {
const baseAst = API.load('test/data/input/stepGroups.feature');
const expectedAst = API.load('test/data/output/stepGroups.feature');
const resultAst = API.process(baseAst, new StepGroups());

expect(resultAst).to.eql(expectedAst);
});

});
35 changes: 35 additions & 0 deletions test/data/input/stepGroups.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Feature: Test for stepGroups

Background:
Given step
Given step
When step
And step
When step
Then step
Then step
And step

Scenario: Test
Given step
Given step
When step
And step
When step
Then step
Then step
And step

Scenario Outline: Test (<test>)
Given step
Given step
When step
And step
When step
Then step
Then step
And step

Examples:
| test |
| test |
35 changes: 35 additions & 0 deletions test/data/output/stepGroups.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Feature: Test for stepGroups

Background:
Given step
And step
When step
And step
And step
Then step
And step
And step

Scenario: Test
Given step
And step
When step
And step
And step
Then step
And step
And step

Scenario Outline: Test (<test>)
Given step
And step
When step
And step
And step
Then step
And step
And step

Examples:
| test |
| test |

0 comments on commit 9649bb1

Please sign in to comment.