Skip to content

Commit

Permalink
macro step (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
judit-nahaj committed Jan 31, 2018
1 parent 9649bb1 commit b58594b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,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))
- Added method to create macro step ([#18](https://github.com/judit-nahaj/gherkin-precompiler/issues/18))

### Fixed

Expand Down
11 changes: 11 additions & 0 deletions lib/builtIn/Macro.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const DefaultConfig = require('../DefaultConfig');
const MACROSTEP = /^macro (.*) ?is executed$/;
const {Step} = require('gherkin-assembler').AST;

/**
* Macro to create a Cucumber step by combining a block of steps, simplifying often recurring steps.
Expand Down Expand Up @@ -65,6 +66,16 @@ class Macro extends DefaultConfig {
return this.macros[name].steps;
}
}

/**
* Creates macro step
* @static
* @param {String} macro
* @returns {Step}
*/
static createStep(macro) {
return new Step('When', `macro ${macro} is executed`);
}
}

module.exports = Macro;
11 changes: 10 additions & 1 deletion lib/builtIn/Macro.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,13 @@ Usage:

Throws error when no ${macroName} is provided in the step, or when no macro is defined by name provided.

See examples for the input files and an output in the test/data folder.
See examples for the input files and an output in the test/data folder.

## API

### `Macro.createStep(name)`

**Params**:
- `{String} name` - The name of the macro

**Returns**: `{Step}` - A macro step for the given macro.
6 changes: 6 additions & 0 deletions test/builtIn/Macro.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,10 @@ describe('builtIn.Macro', () => {
expect(resultAst).to.eql(expectedAst);
});

it('should have a method to create a macro step', () => {
const step = Macro.createStep("TestMacro");
expect(step).to.be.instanceOf(assembler.AST.Step);
expect(step.toString()).to.equal("When macro TestMacro is executed");
})

});

0 comments on commit b58594b

Please sign in to comment.