Story Syntax

JBehave supports multiple story syntaxes.

JBehave Syntax

JBehave's syntax is supported by the RegexStoryParser:

A story is a collection of scenarios

Narrative:
In order to communicate effectively to the business some functionality
As a development team
I want to use Behaviour-Driven Development

Lifecycle: 
Before:
Scope: STORY
Given a step that is executed before each story
Scope: SCENARIO
Given a step that is executed before each scenario
Scope: STEP
Given a step that is executed before each scenario step
After:
Scope: STEP
Given a step that is executed after each scenario step
Scope: SCENARIO
Outcome: ANY
Given a step that is executed after each scenario regardless of outcome
Outcome: SUCCESS 
Given a step that is executed after each successful scenario
Outcome: FAILURE 
Given a step that is executed after each failed scenario
Scope: STORY
Outcome: ANY
Given a step that is executed after each story regardless of outcome
Outcome: SUCCESS
Given a step that is executed after each successful story
Outcome: FAILURE
Given a step that is executed after each failed story
Examples:
|story-level-precondition|
|cba                     |
|zyx                     |

Scenario:  A scenario is a collection of executable steps of different type

Given a [story-level-precondition]
Given step represents a precondition to an event
When step represents the occurrence of the event
Then step represents the outcome of the event

Scenario:  Another scenario exploring different combination of events

Given a [precondition]
When a negative event occurs
Then a the outcome should [be-captured]    

Examples: 
|precondition|be-captured    |
|abc         |be captured    |
|xyz         |not be captured|

Gherkin Syntax

Gherkin syntax is supported by the GherkinStoryParser:

Feature: A story is a collection of scenarios

Narrative:
In order to communicate effectively to the business some functionality
As a development team
I want to use Behaviour-Driven Development
    
Background: 

Given a step that is executed before each scenario 

Scenario:  A scenario is a collection of executable steps of different type

Given step represents a precondition to an event
When step represents the occurrence of the event
Then step represents the outcome of the event

Scenario Outline:  Another scenario exploring different combination of events

Given a [precondition]
When a negative event occurs
Then a the outcome should [be-captured]    

Examples: 
|precondition|be-captured|
|abc|be captured    |
|xyz|not be captured|

The Gherkin syntax is supported via story transformers, that use the Gherkin parser to transform the syntax to JBehave's.

Note that Gherkin's Background element corresponds to the JBehave Lifecycle Before scenario-scoped element. JBehave also supports Lifecycle story-scoped elements and After element which are not currently available in Gherkin.