0
votes

I have a strange situation where I have two examples. and I have this one step fill the mandatory fields of user form which i only need to execute for one example ("scope_self"). for other it should not run.

Is there a way to achieve this

Examples:
        |    action     |
        |  "scope_self" |
        |   "scope_new" |
1

1 Answers

1
votes

It would be an easier option to create a separate scenario with the mandatory step. Would be a cleaner implementation.

Anyways, there is a way to get this to work in the same scenario outline.

  1. Split the examples table into two. Give the first table a @Mandatory tag which has the one example ("scope_self").
 Scenario Outline:
      Given ............
      When .............
      Then .............

      @Mandatory
      Examples:
              |    action     |
              |  "scope_self" |

      Examples:
              |    action     |
              |   "scope_new" |
  1. Setup a variable flag and set it to false.

  2. Create a tagged Before hook for the @Mandatory tag. In this set the flag variable to true.

  3. In the step definition code for the mandatory option check if the flag variable is set to true or false. If true run the remaining code else skip to return.

I am basing this from Java but this should work for you in rspec...