forked from cucumber/cucumber-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstep_definition_snippets_custom_syntax.feature
63 lines (58 loc) · 2.54 KB
/
step_definition_snippets_custom_syntax.feature
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
Feature: step definition snippets custom syntax
As a developer writing my step definitions in another JS dialect
I want to be able to see step definition snippets in the language I perfer
Background:
Given a file named "features/undefined.feature" with:
"""
Feature: a feature
Scenario: a scenario
Given an undefined step
"""
And a file named "coffeescript_syntax.js" with:
"""
function CoffeeScriptSyntax(snippetInterface) {
return {
build: function build (opts) {
var implementation;
if (snippetInterface === 'callback') {
implementation = "done null, 'pending'";
} else {
implementation = "'pending'";
}
var definitionChoices = opts.generatedExpressions.map(
function (generatedExpression, index) {
var prefix = index === 0 ? '' : '# ';
var allParameterNames = generatedExpression.parameterNames.concat(opts.stepParameterNames);
if (snippetInterface === 'callback') {
allParameterNames.push('done');
}
var parametersStr = allParameterNames.length > 0 ? '(' + allParameterNames.join(', ') + ') ' : '';
return prefix + '@' + opts.functionName + " '" + generatedExpression.source.replace(/'/g, '\\\'') + "', " + parametersStr + '-> \n';
}
)
return (
definitionChoices.join('') +
' # ' + opts.comment + '\n' +
' ' + implementation
);
}
};
}
module.exports = CoffeeScriptSyntax;
"""
Scenario Outline:
When I run cucumber-js with `--format-options '{"snippetInterface": "<INTERFACE>", "snippetSyntax": "coffeescript_syntax.js"}'`
Then it fails
And the output contains the text:
"""
@Given 'an undefined step', <SNIPPET_PARAMETERS_AND_ARROW>
# Write code here that turns the phrase above into concrete actions
<SNIPPET_IMPLEMENTATION>
"""
Examples:
| INTERFACE | SNIPPET_PARAMETERS_AND_ARROW | SNIPPET_IMPLEMENTATION |
| callback | (done) -> | done null, 'pending' |
| generator | -> | 'pending' |
| promise | -> | 'pending' |
| async-await | -> | 'pending' |
| synchronous | -> | 'pending' |