JBehave
  1. JBehave
  2. JBEHAVE-883

Support synonyms of step-starting keywords

    Details

    • Type: Improvement Improvement
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 3.x
    • Fix Version/s: 3.8
    • Component/s: Core
    • Labels:
      None
    • Number of attachments :
      0

      Description

      It is generally acceptable that you can describe a business case just using Given/When/Then/And suite.

      However when the scenario you need to write is a long one (say 30 or more steps) I have to accept that the story starts sounding a bit to fade (say made up). It works but you would prefer it to sound more natural.

      I think this could be supported if we improve jBehave to allow defining "And" synonyms with exactly the same functionality as the actual "And"?

      So you can say something like this:

      Given our Payments system supports SWIFT messages
      When a FX transaction message arrives
      And the "from" currency is USD
      And the "to" currency is GBP
      And the exchange rate is 0.71002
      And the transaction date is the next business day
      And the transaction amount is $200.00
      And the payer account no is 1234567890
      ....
      And +30 others "when" steps describing the Foreigner Exchange message
      Then.....

      Someone would say (me included) that if I can say "With' and "Having" are synonyms of "And" and rewrite the story like below then it would sound more natural.

      Given our Payments system supports SWIFT messages
      When a FX transaction message arrives
      Having the "from" currency as USD
      And the "to" currency as GBP
      With an exchange rate of 0.71002
      ......

        Activity

        Hide
        Joachim Nilsson added a comment -

        It seems to me as most of the additional 'And' lines in your scenario are details to the first 'When' line. If I relate to Java code, this would be parameters to a factory method or a builder. Am I correct?
        In that case, treat the use of 'With' as an indication that the following line relates to a previous Given/When/Then statement.
        Disregarding the huge implications of changing the language, consider adding a 'With' statement that would allow us to pass parameters from that line to a builder created in the first Given/When/Then statement.

        When a FX transaction message arrives: A builder of type FxTransactionMessageBuilder is created, but the actual method is NOT called
        With the "from" currency as USD: builder.addFromCurrency(Currency currency)
        With the "to" currency as GBP: builder.addToCurrency(Currency currency)

        Then, when no more 'With' lines are found. The builder object will be created and passed as parameter to the 'When a FX transaction message arrives' method.

        Would this be something to consider?

        Show
        Joachim Nilsson added a comment - It seems to me as most of the additional 'And' lines in your scenario are details to the first 'When' line. If I relate to Java code, this would be parameters to a factory method or a builder. Am I correct? In that case, treat the use of 'With' as an indication that the following line relates to a previous Given/When/Then statement. Disregarding the huge implications of changing the language, consider adding a 'With' statement that would allow us to pass parameters from that line to a builder created in the first Given/When/Then statement. When a FX transaction message arrives: A builder of type FxTransactionMessageBuilder is created, but the actual method is NOT called With the "from" currency as USD: builder.addFromCurrency(Currency currency) With the "to" currency as GBP: builder.addToCurrency(Currency currency) Then, when no more 'With' lines are found. The builder object will be created and passed as parameter to the 'When a FX transaction message arrives' method. Would this be something to consider?
        Hide
        Julian Greculescu added a comment -

        >>If I relate to Java code, this would be parameters to a factory method or a builder. Am I correct?
        Kind of. In reality it is a story context attached to the thread local. The reason for the context exists is because we need to pass story data between different steps classes that are grouped based on what they do rather than on the story they are part of. We done it this way for steps reusability in different stories. Any steps could write/read stuff from that context regardless of how they are labelled (Given/When/Then/And).
        But yes you are right it would be a builder that would read that context and create the payment. We create the builder when we need it rather than at the start but this is implementation detail.

        >>Disregarding the huge implications of changing the language,
        I think huge is too much to say. Yes it would be a language change but for the better. Having the optional choice to define “And” synonyms it does not imply it must be used. You just have it as an extra feature for the purpose of making your story sound more natural.

        >>consider adding a 'With' statement that would allow us to pass parameters from that line to a builder created in the first Given/When/Then statement.
        In my example I used ‘With’ and ‘Having’ just for the purpose of making it clear what I was talking about. ‘With’ and ‘Having’ are just ‘And’ synonyms. Any word could be defined as an ‘And’ synonym (of course not Given/When/Then)

        Then, when no more 'With' lines are found. The builder object will be created and passed as parameter to the 'When a FX transaction message arrives' method.
        >>Would this be something to consider?
        No more ‘With’ lines should not be a trigger. It should be a certain steps to trigger the FX transaction arrival.

        So in short I see a change like this as being able to have multiple ‘And’ equivalents and its only purpose is to make the story more fluent for the case of very long scenarios.

        Show
        Julian Greculescu added a comment - >>If I relate to Java code, this would be parameters to a factory method or a builder. Am I correct? Kind of. In reality it is a story context attached to the thread local. The reason for the context exists is because we need to pass story data between different steps classes that are grouped based on what they do rather than on the story they are part of. We done it this way for steps reusability in different stories. Any steps could write/read stuff from that context regardless of how they are labelled (Given/When/Then/And). But yes you are right it would be a builder that would read that context and create the payment. We create the builder when we need it rather than at the start but this is implementation detail. >>Disregarding the huge implications of changing the language, I think huge is too much to say. Yes it would be a language change but for the better. Having the optional choice to define “And” synonyms it does not imply it must be used. You just have it as an extra feature for the purpose of making your story sound more natural. >>consider adding a 'With' statement that would allow us to pass parameters from that line to a builder created in the first Given/When/Then statement. In my example I used ‘With’ and ‘Having’ just for the purpose of making it clear what I was talking about. ‘With’ and ‘Having’ are just ‘And’ synonyms. Any word could be defined as an ‘And’ synonym (of course not Given/When/Then) Then, when no more 'With' lines are found. The builder object will be created and passed as parameter to the 'When a FX transaction message arrives' method. >>Would this be something to consider? No more ‘With’ lines should not be a trigger. It should be a certain steps to trigger the FX transaction arrival. So in short I see a change like this as being able to have multiple ‘And’ equivalents and its only purpose is to make the story more fluent for the case of very long scenarios.
        Mauro Talevi made changes -
        Field Original Value New Value
        Summary Add support for 'And' synonyms Support synonyms of step-starting keywords
        Mauro Talevi made changes -
        Assignee Mauro Talevi [ maurotalevi ]
        Fix Version/s 3.8 [ 19104 ]
        Fix Version/s 3.x [ 16979 ]
        Mauro Talevi made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        Hide
        Mauro Talevi added a comment -

        I've pushed a start of this new feature. The synonyms are actually supported for all step-starting keywords, as it looks like it should be just as simple. To configure the synonyms, just append them to the i18n keywords, using the '|' as separator, e.g.:

        Given=Given|Giveth
        When=When
        Then=Then
        And=And|With
        

        Note that the default value of keywords does not have any synonyms (it may do later on), so for now you need to define your own i18n keywords, as if defining a new locale:

        http://jbehave.org/reference/latest/stories-in-your-language.html

        In the unit tests, you'll find the keywords_sy.properties defined for this scope.

        I've pushed the latest snapshot to Nexus, please have a go and provide any feedback.

        Show
        Mauro Talevi added a comment - I've pushed a start of this new feature. The synonyms are actually supported for all step-starting keywords, as it looks like it should be just as simple. To configure the synonyms, just append them to the i18n keywords, using the '|' as separator, e.g.: Given=Given|Giveth When=When Then=Then And=And|With Note that the default value of keywords does not have any synonyms (it may do later on), so for now you need to define your own i18n keywords, as if defining a new locale: http://jbehave.org/reference/latest/stories-in-your-language.html In the unit tests, you'll find the keywords_sy.properties defined for this scope. I've pushed the latest snapshot to Nexus, please have a go and provide any feedback.
        Mauro Talevi made changes -
        Status In Progress [ 3 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]

          People

          • Assignee:
            Mauro Talevi
            Reporter:
            Julian Greculescu
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: