Skip to content

Multiple .after's only run the last hook #366

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

Open
jparris opened this issue Apr 1, 2025 · 3 comments · May be fixed by #368
Open

Multiple .after's only run the last hook #366

jparris opened this issue Apr 1, 2025 · 3 comments · May be fixed by #368
Assignees
Labels
k::api Related to API (application interface) k::documentation Related to project documentation question Further information is requested
Milestone

Comments

@jparris
Copy link

jparris commented Apr 1, 2025

Problem

Modifying the readme example to have multiple afters will only run the last after.

Example afters

    World::cucumber()
        .init_tracing()
        .after(|_, _, _, _, _| async { tracing::info!("After 1") }.boxed_local())
        .after(|_, _, _, _, _| async { tracing::info!("After 2") }.boxed_local())
        .run("readme.feature").await;

Example output

Feature: Eating too much cucumbers may not be good for you
  Scenario: Eating a few isn't a problem
   ✔  Given Alice is hungry
   ✔  When she eats 3 cucumbers
   ✔  Then she is full
2025-04-01T22:26:48.283264Z  INFO scenario:after hook: double_after: After 2
[Summary]
1 feature
1 scenario (1 passed)
3 steps (3 passed)

Possible Solutions

  • Add a warning that multiple afters have been set and only the last one will be run.
  • Add support for multiple afters.
@tyranron tyranron self-assigned this Apr 2, 2025
@tyranron tyranron added question Further information is requested k::documentation Related to project documentation k::api Related to API (application interface) labels Apr 2, 2025
@tyranron tyranron added this to the 0.22.0 milestone Apr 2, 2025
@tyranron
Copy link
Member

tyranron commented Apr 2, 2025

@jparris yup, it wasn't intended to set multiple callbacks. We can call it multiple time to be able to overwrite the one set before. I think additional warning in the documentation and Book would be a good solution as for now. Adding ability to set multiple different hooks needs a thoughtful design, and I'd like no to hurry with such feature, as the demand for it is not high enough.

@tyranron
Copy link
Member

tyranron commented Apr 2, 2025

Would love to see a PR, anyway.

jparris added a commit to jparris/cucumber that referenced this issue Apr 17, 2025
@jparris
Copy link
Author

jparris commented Apr 17, 2025

Would love to see a PR, anyway.

Thanks. I've opened a PR feel free to tweak my wording.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
k::api Related to API (application interface) k::documentation Related to project documentation question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants