Nesting Scenarios - xspec/xspec GitHub Wiki

You can nest scenarios inside each other. The nested scenarios inherit the context or call from its ancestor scenarios. All the scenarios in a particular tree have to be of the same type (matching, function or named template). Usually only the lowest level of the scenarios will contain any expectations.

Nesting Call

Here's an example of nesting the call:

<x:scenario label="when creating a table">
   <x:call template="createTable" />

   <x:scenario label="holding three values">
      <x:call>
         <x:param name="nodes">
            <value>A</value>
            <value>B</value>
            <value>C</value>
         </x:param>
      </x:call>

      <x:scenario label="in two columns">
         <x:call>
            <x:param name="cols" select="2" />
         </x:call>

         <x:expect
            label="the table should have two columns"
            test="/table/colgroup/col => count()"
            select="2" />
         <x:expect
            label="the first row should contain the first two values"
            test="/table/tbody/tr[1]">
            <tr>
               <td>A</td>
               <td>B</td>
            </tr>
         </x:expect>
      </x:scenario>

      <!-- ... other scenarios around creating tables with three values (with different numbers of columns) ... -->
   </x:scenario>

   <!-- ... other scenarios around creating tables ... -->
</x:scenario>

When you create scenarios like this, the labels of the nested scenarios are concatenated to create the label for the scenario. In the above example, the third scenario has the label "when creating a table holding three values in two columns".

Nesting Context

See test/nested-context.xspec for an example of nesting the context.

⚠️ **GitHub.com Fallback** ⚠️