erikedin / Behavior.jl

Tool for Behavior Driven Development in Julia
Other
25 stars 3 forks source link

Gherkin: support out of order and interleaving steps #47

Closed tk3369 closed 3 years ago

tk3369 commented 3 years ago

I'm unsure if it's common practice but other Gherkin implementations such as Python's behave supports interleaving steps.

Here's an example from Grakn project:

  Scenario: Relation with role players can be created and role players can be retrieved
    When $m = relation(marriage) create new instance with key(license): m
    Then relation $m is null: false
    Then relation $m has type: marriage
    Then relation(marriage) get instances contain: $m
    When $a = entity(person) create new instance with key(username): alice
    When $b = entity(person) create new instance with key(username): bob
    When relation $m add player for role(wife): $a
    When relation $m add player for role(husband): $b
    Then relation $m is null: false
    Then relation $m has type: marriage

Currently, the parser fails with the following error:

julia> r = ExecutableSpecifications.Gherkin.parsefeature("""
       Feature: test

         Scenario: interleaving steps
           When connection is opened
           Then sending message should be successful
           When connection is closed
           Then sending message should return an error
       """)
ExecutableSpecifications.Gherkin.BadParseResult{ExecutableSpecifications.Gherkin.Feature}(:bad_step_order, :NotWhen, :When)

This enhancement is required to support Grakn client. See master issue #44.

tk3369 commented 3 years ago

Just want to note that the order is important. In the example above, the first When statement must be executed before the second one. I can think of two use cases:

  1. The When statement may have a side effect in the context object
  2. The When statement may have a side effect in an external system (e.g. inserting data into a database)

For the same reason, the first Then statement in the above example must be executed BEFORE the When statement that immediately follows it.

Hence this implementation would have to preserve the execution order of all statements - Given, When, and Then's.

erikedin commented 3 years ago

I don't think the execution order will be a problem, but we ought to make a test for it to make sure, and to make sure it doesn't fail in the future.

erikedin commented 3 years ago

I'm going to close this. Interleaving step types is supported by the old parser with an option, and by the new parser by default, so it's all done.