Skip to content

Commit

Permalink
feat: Support Multiline Step Arguments
Browse files Browse the repository at this point in the history
Add the functionality that the preprocessor also translates/replaces arguments in `DocString`.

This is a Documented Cucumber Feature:
https://github.com/yuyijq/cucumber/wiki/Multiline-Step-Arguments#substitution-in-scenario-outlines
Improvements
linter sucks
Adjust feature file
Add Step Definitions
remove type
Add colon

Co-authored-by: Enrico126 @Enrico126
  • Loading branch information
Lukasz Gandecki authored and lgandecki committed Apr 22, 2021
1 parent 3db704b commit ab500fd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cypress/integration/DocString.feature
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,17 @@ Feature: Being a plugin handling DocString scenario
</div>
"""
Then I can interpret it as a string

Scenario Outline: DocString
When I use DocString with argument like this:
"""
Hey,
You have been granted <Role> rights.
-The Admins
"""
Then I should have a string with argument "<Role>"

Examples:
| Role |
| Manager |
| Admin |
9 changes: 9 additions & 0 deletions cypress/support/step_definitions/docString.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* global Then, When */

let code = "";
let argString = "";
// eslint-disable-next-line prefer-const
let variableToVerify = ""; // we are assigning this through eval

Expand All @@ -10,6 +11,10 @@ When("I use DocString for code like this:", (dataString) => {
code = dataString;
});

When("I use DocString with argument like this:", (dataString) => {
argString = dataString;
});

Then("I ran it and verify that it executes it", () => {
// eslint-disable-next-line no-eval
eval(code);
Expand All @@ -24,3 +29,7 @@ When("I use DocString for freemarker code like this", (dataString) => {
Then("I can interpret it as a string", () => {
expect(freemarkerSnippet).to.be.a("string");
});

Then(/^I should have a string with argument "([^"]*)"$/, function (argument) {
expect(argString).to.contain(argument);
});
4 changes: 4 additions & 0 deletions lib/resolveStepDefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,12 @@ function resolveStepArgument(argument, exampleRowData, replaceParameterTags) {
return new DataTable(argumentWithAppliedExampleData);
}
if (argument.type === "DocString") {
if (exampleRowData) {
return replaceParameterTags(exampleRowData, argument.content);
}
return argument.content;
}

return argument;
}

Expand Down

0 comments on commit ab500fd

Please sign in to comment.