Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow scenario expansion for docstrings #172

Closed
rogertorres opened this issue Dec 1, 2021 · 3 comments · Fixed by #178
Closed

Allow scenario expansion for docstrings #172

rogertorres opened this issue Dec 1, 2021 · 3 comments · Fixed by #178
Assignees
Labels
enhancement Improvement of existing features or bugfix
Milestone

Comments

@rogertorres
Copy link
Contributor

The scenario expansion currently replaces templates from both the step and its table.

cucumber/src/feature.rs

Lines 158 to 162 in e7387d4

let to_replace = iter::once(&mut s.value).chain(
s.table.iter_mut().flat_map(|t| {
t.rows.iter_mut().flat_map(|r| r.iter_mut())
}),
);

Do you think it is possible to add the step docstring into the mix? This would allow us to validate docstrings that are slightly different from one another in a single scenario.

@tyranron
Copy link
Member

tyranron commented Dec 2, 2021

@rogertorres could you provide a little bit wider example of such scenario and the code you do want in a step matching function?

@tyranron tyranron added the enhancement Improvement of existing features or bugfix label Dec 2, 2021
@rogertorres
Copy link
Contributor Author

hey @tyranron, please consider the simplified example below:

Feature: Doc String expansion
    Scenario Outline: Counting Song
        Given I have a file with the "Ants Go Marching" song
        When I read the <nth> paragraph
        Then I should sing:
        """
        The ants go marching <number> by <number>
        The little one stops to <action>
        """
        
        Examples:
            | nth     | number | action         |
            | first   | one    | suck his thumb |
            | second  | two    | tie his shoe   |
            | third   | three  | climb a three  |
            | fourth  | four   | shut the door  |

The example's idea is to be able to replace <number> and <action>. In Rust, I would read the actual file and check if its paragraphs match the docstring expanded with the examples.

IRL, such feature would allow us to validate contents that are not structured, such as human-readable logs generated by other tools, making the docstring usage a bit more flexible. The alternative I have today is to use the Examples/Data-Table variables to build this docstring inside Rust, but then my Gherkin file becomes less expressive.

@tyranron
Copy link
Member

tyranron commented Dec 3, 2021

@rogertorres thanks! Seems quite reasonable.

cc @ilslv

Let's add it to upcoming 0.11 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement of existing features or bugfix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants