JBehave
  1. JBehave
  2. JBEHAVE-753

Allow GivenStories to be parametrised by examples in a scenario context

    Details

    • Type: Improvement Improvement
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 3.6
    • Fix Version/s: 3.6.2, 3.7
    • Component/s: Core
    • Labels:
      None
    • Number of attachments :
      0

      Description

      Introduction

      JBehave supports parameterizing scenarios to allow repeating tests. e.g. As shown in the documentation:-

      Given a stock of <symbol> and a <threshold>
      When the stock is traded at <price>
      Then the alert status should be <status>
       
      Examples:    
      |symbol|threshold|price|status|
      |STK1|10.0|5.0|OFF|
      |STK1|10.0|11.0|ON
      

      It would be desirable if this convention could be extended to be used in combination with a Given Story.
      To demonstrate by means of an extension to the documentation example:-
      Suppose there is a requirement to select a specific "Stock Exchange" before executing each of the tests above.
      Rather than building this into the story, we might opt, for reuse purposes, to use a Given Story to first select the "Stock Exchange".

      Now the first example would be 'Nasdaq' and the second 'FTSE'.

      The hypothetical configuration might then be:-

      GivenStories: acme/givenstories/SelectAStockExchange.story
      Given a stock of <symbol> and a <threshold>
      When the stock is traded at <price>
      Then the alert status should be <status>
       
      Examples:    
      |stockExchange|symbol|threshold|price|status|
      |NASDAQ|STK1|10.0|5.0|OFF|
      |FTSE|STK1|10.0|11.0|ON
      

      Current Behaviour

      Unfortunately the example above will not work as desired
      The 'GivenStory', SelectAStockExchange.story, does not inherit the parameterized variables as night be expected.
      Nor does the obvious supporting feature, anchor tags, help because only a specific row number can be specified in the anchor tag.
      e.g.

      GivenStories: acme/givenstories/SelectAStockExchange.story{0}
      

      Suggested Behaviour

      The Given Story should be considered part of the be parametrised scenario context and inherit the parameters of the row currently being executed.

      Referencing previous response from Mauro on the dev mail thread

      "As I understand it, you'd like the GivenStories to be considered as part of the parametrised scenario context and be passed the row of parameters that is being processed as part of a parametrised scenario. I guess, we could make that the default behaviour, and any parameters passed to the given stories could be overridden by the execution of the given story"

        Activity

        Mauro Talevi made changes -
        Field Original Value New Value
        Assignee Mauro Talevi [ maurotalevi ]
        Fix Version/s 3.6.1 [ 18391 ]
        Mauro Talevi made changes -
        Fix Version/s 3.6.2 [ 18398 ]
        Fix Version/s 3.6.1 [ 18391 ]
        Mauro Talevi made changes -
        Summary Enable GivenStories to be considered as part a parametrised scenario context - allowing better reuse of Given Stories Allow GivenStories to be parametrised by examples in a scenario context
        Affects Version/s 3.5.4 [ 18081 ]
        Mauro Talevi made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        Hide
        Mauro Talevi added a comment -

        Hi Dave,

        implemented given_stories_parametrised_by_examples.story in trader example, based on your suggested use case.

        Please check latest snapshot to see if it satisfy your requirements.

        Cheers

        Show
        Mauro Talevi added a comment - Hi Dave, implemented given_stories_parametrised_by_examples.story in trader example, based on your suggested use case. Please check latest snapshot to see if it satisfy your requirements. Cheers
        Hide
        Dave Carey added a comment -

        Hi Mauro
        It looks to be exactly as requested - Thanks very much - it certainly will be a big assistance to the way we plan to organise our acceptance tests.

        However I was trying to test with the latest 3.7 snapshot from the nexus repository and it didn't seem to be working.
        I then noticed though that this is dated from the 4th April and that pre-dates your changes which I think are all from the 8th.

        How often are the latest snapshots generated on Nexus? (Apologies if I'm missing some obvious part of the build procedure)

        Thanks
        Dave

        Show
        Dave Carey added a comment - Hi Mauro It looks to be exactly as requested - Thanks very much - it certainly will be a big assistance to the way we plan to organise our acceptance tests. However I was trying to test with the latest 3.7 snapshot from the nexus repository and it didn't seem to be working. I then noticed though that this is dated from the 4th April and that pre-dates your changes which I think are all from the 8th. How often are the latest snapshots generated on Nexus? (Apologies if I'm missing some obvious part of the build procedure) Thanks Dave
        Hide
        Mauro Talevi added a comment -

        A new snapshot has been deployed. ATM, snapshots are published manually. I'll look into setting it up automatically in Bamboo.

        Show
        Mauro Talevi added a comment - A new snapshot has been deployed. ATM, snapshots are published manually. I'll look into setting it up automatically in Bamboo.
        Mauro Talevi made changes -
        Status In Progress [ 3 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Hide
        Dave Carey added a comment -

        Hi Mauro

        Tried out with the latest snapshot and can confirm that it works a treat!

        Cheers
        Dave

        Show
        Dave Carey added a comment - Hi Mauro Tried out with the latest snapshot and can confirm that it works a treat! Cheers Dave
        Mauro Talevi made changes -
        Fix Version/s 3.7 [ 18390 ]

          People

          • Assignee:
            Mauro Talevi
            Reporter:
            Dave Carey
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: