Skip to content
davidmfoley edited this page Sep 13, 2010 · 10 revisions

StorEvil supports a subset of the Gherkin language.


Anything before the first line that starts with "scenario" is not executed.
This can be multiple lines long.

Scenario: This is a scenario title
  Given some precondition.
  When some awesome action is invoked

Exact and partial matches

Exact

An exact match is when a method matches an entire line of specification code.

These would be exact matches for lines in the above specification:

public void Given_some_precondition() {}

public void When_some_qualifier_action_is_invoked(string qualifier) {}

Partial

A partial match happens when there is a method that matches part of a line:
public ActionContext When_some_qualifier_action(string qualifier) { }

Note that a partial match must return a value (in this case, ActionContext).

StorEvil will attempt to match the rest of the line using the returned value, so, we might define ActionContext as follows:

[StorEvil.Context] public class ActionContext {public void Is_invoked(){}}

Precedence when multiple matches occur.

StorEvil favors an exact match over any partial matches, and favors longer partial matches (more words) over shorter matches (fewer words).

To GWT or not to GWT?

“Given”, “When” and “Then” are not hard-wired into the language… you may use any words you like for these concepts.

Special treatment of the word “And”

If the first word of a line is “And”, and there is no grammar match using “And”, StorEvil will attempt to use the most recent significant first word .

For example, given in the following,


Scenario: And has special treatment when it is the first word of a line
  Given some precondition.
  And another precondition

… StorEvil would try first to match with “And_another_precondition”, followed by “Given_another_precondition”.

Tabular data

Scenario Outlines

StorEvil supports scenario outlines that allow you to execute the specification for each row of data.
To execute an outline:

  1. surround the values in your story like this: <someValue>
  2. use Scenario Outline: rather than Scenario:.
  3. Put the data to be used for each test case into a row of a table.

The table is separated by pipe characters, and the first row is the names of the parameters, which much match the names of the <fields>.

(This example is from StorEvil’s executing_outlines_with_example_tables test fixture)


Story: test 
Scenario Outline:
Call a method with <int> and <string>
Examples:
|int|string|
|1|one|
|2|two|
|3|three|

This will invoke the following method three times:


 public void Call_a_method_with_intParam_and_stringParam(int intParam, string stringParam)

Tables of data in a scenario:
There are a couple of different ways to deal with tabular data.
See Tables of values for more information.

Clone this wiki locally