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

Support for example values - or better examples #64

Closed
jonasrichard opened this issue Sep 11, 2020 · 12 comments
Closed

Support for example values - or better examples #64

jonasrichard opened this issue Sep 11, 2020 · 12 comments
Labels
enhancement Improvement of existing features or bugfix k::documentation Related to project documentation
Milestone

Comments

@jonasrichard
Copy link

I expected to access the values in example table easier, like scenario outline can be execute for each row of the example table and in those scenarios we can access the values easier, like:

builder.given_example("a number <num>", |mut world, step, vars| {
  let string_num = vars.value("num");
  world.num_param = string_num::parse::<i32>::parse().unwrap();
  world
})
...

Or do we need to collect all examples in the World, but how? The example test is not implement for that.

@bbqsrc bbqsrc added enhancement Improvement of existing features or bugfix k::documentation Related to project documentation labels Sep 11, 2020
@bbqsrc
Copy link
Member

bbqsrc commented Sep 11, 2020

Hey, thanks for the feedback!

Documentation does need to improve. I'm a little busy right now so I can't help right away.

I'll consider your suggestion of syntax as well and get back to you. 🙂

@stefanpieck
Copy link
Contributor

Hi,

I would expect examples to be handled using regex steps.

And during the execution the example values can be automatically inserted, and the Scenarios be executed one for each example.

With the example given in test.features the scenario

Scenario Outline: scenario with examples
    Given a number <num>
    Then twice that number should be <double>

    Examples:
      | num | double |
      |   2 |      4 |
      |   3 |      6 |

could be implemented as:

.given_regex(r"a number (\d+)", |mut world, matches, _step| {
    world.foo = matches[1].to_owned();
    world
})
.then_regex(
    r"twice that number should be (\d+)",
    |world, matches, _step| {
        let to_check = world.foo.parse::<i32>().unwrap();
        let expected = matches[1].parse::<i32>().unwrap();
        assert_eq!(to_check * 2, expected);
        world
    },
)

And would generate a result like:

Scenario: scenario with examples
 Using example: <num> = 2, <double> = 4 
  ✔ Given a number 2                                      
  ✔ Then twice that number should be 4        
 Scenario: scenario with examples
 Using example: <num> = 3, <double> = 6       
  ✔ Given a number 3                                   
  ✔ Then twice that number should be 6 

I created a small example for that in this branch

@bbqsrc
Copy link
Member

bbqsrc commented Sep 20, 2020

@stefanpieck looks neat. 😄 I had come to the conclusion to do it the same way, though hadn't found the time. Instead, I had focused on splitting "Scenario" into an enum of "Scenario Outline" and "Example", as per the Cucumber reference.

I'd be happy to accept your implementation here via a PR, and then add my stuff on top later.

@bbqsrc
Copy link
Member

bbqsrc commented Sep 21, 2020

The first half of this has been merged now. I'll work on the splitting of scenario into two items when I have time. 😄

@wucke13
Copy link

wucke13 commented Nov 9, 2020

What does it take to get the second half done as well?

@bbqsrc
Copy link
Member

bbqsrc commented Nov 9, 2020

It doesn't seem that you need the second half to achieve what you want. Change your cucumber dependency to point to:

cucumber = { package = "cucumber_rust", git = "https://github.com/bbqsrc/cucumber-rust", branch = "main" }

and see if it behaves how you would expect. 😄

@wucke13
Copy link

wucke13 commented Nov 9, 2020

@bbqsrc Doing so does not seem to change the problem at all 🤔, even though it seems to build of the newest commit:

Cargo.lock snippet:

[[package]]
name = "cucumber_rust"
version = "0.7.3"
source = "git+https://github.com/bbqsrc/cucumber-rust?branch=main#7140ba0d7314cd8863d7c290e8e31c2aa0b4cc59"
dependencies = [
 "async-stream",
 "async-trait",
 "clap",
 "cute_custom_default",
 "futures",
 "futures-timer",
 "gherkin_rust",
 "globwalk",
 "pathdiff",
 "regex",
 "shh",
 "termcolor",
 "textwrap 0.12.1",
 "thiserror",
]

@bbqsrc
Copy link
Member

bbqsrc commented Nov 9, 2020

As per #64 (comment), to match the step you'll need to use regular expressions for the replacement positions for now.

@wucke13
Copy link

wucke13 commented Nov 9, 2020

That is what I'm doing. I'm not able to spot what I'm doing wrong, please have a careful look at #86 again. AFAICT I'm doing the equivalent to the comment you linked, still with master the behavior is the exact same as described in the issue (it's not working).

@tyranron
Copy link
Member

After #128 is possible by using regexes.

@ilslv would you be so kind provide a meaningful example of this? It's even better to provide the one in the book as a separate PR and reffer here.

@ilslv
Copy link
Member

ilslv commented Sep 27, 2021

@tyranron I'll dedicate separate chapter with concrete examples of usage

@tyranron tyranron added this to the 0.10 milestone Sep 29, 2021
tyranron added a commit that referenced this issue Sep 30, 2021
, #64, #102, #103, #123, #132)

Additionally:
- fix outputing English in writer::Basic instead of parsed keywords

Co-authored-by: Kai Ren <[email protected]>
@tyranron
Copy link
Member

Described in "Features" chapter fo the Book.

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 k::documentation Related to project documentation
Projects
None yet
Development

No branches or pull requests

6 participants