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

Generify World in Hook Class #73

Open
sashokbg opened this issue Apr 3, 2024 · 1 comment
Open

Generify World in Hook Class #73

sashokbg opened this issue Apr 3, 2024 · 1 comment

Comments

@sashokbg
Copy link

sashokbg commented Apr 3, 2024

I propose to generify the methods that use the World objects in the Hook class such as:

  Future<void> onAfterScenarioWorldCreated(
    World world,
    String scenario,
    Iterable<Tag> tags,
  ) =>

And use something like:

class Hook<T extends World> {
  Future<void> onAfterScenarioWorldCreated(
      T world,
      String scenario,
      Iterable<Tag> tags,
      ) async {
    // Your implementation here
  }
}

This way we can use our own instances of World

// Define the subclass that overrides the method
class MyHook extends Hook<MyWorld> {
  @override
  Future<void> onAfterScenarioWorldCreated(
      MyWorld world,
      String scenario,
      Iterable<Tag> tags,
      ) async {
    // Your implementation here
  }
}

@youssef-t
Copy link
Contributor

Hello,

As of today (with gherkin 3.1.0), one way to use a custom World instance is to cast it inside the method onAfterScenarioWorldCreated. This solution is still a workaround and your suggestion would be the cleanest way to do it.

Future<void> onAfterScenarioWorldCreated(
  World world,
  String scenario,
  Iterable<Tag> tags,
) async {
  assert(world is MyWorld, "world is not an instance of MyWorld");
  MyWorld myWorld = world as MyWorld;
  ...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants