BDD encourages as much information as is meaningful to the business to be included in the stories and scenarios. But as these stories and scenarios grow it may become difficult to navigate through all this information. It will also become necessary to organise the growing number of stories by different criterias.
To help users better manage their stories, JBehave allow the specification of meta information, both at story and scenario level.
Meta: @author Mauro @themes UI Usability Scenario: A scenario in which the user can view all relevant information via UI Meta: @skip false Given ... // normal scenario steps Scenario: A scenario which we cannot run every time due to some technical contraint Meta: @skip true Given ... // normal scenario steps
When JBehave encounters the keyword Meta:, it collects the provided name-value properties, separated by property keyword @. Both keywords are configurable and localizable.
By convention, the first space in the property separates the name from the value, e.g. in the property "themes UI Usability", the name is "themes" and the value is "UI Usability".
Note that spaces are also allowed after the property keyword @, but these will be ignored in the parsing. E.g. if we wrote:
Meta: @ author Mauro @ themes UI Usability
the property names would still be "author" and "themes".
It is important to note that the meta property names are not constrained so users can chose whatever names are most appropriate for the information they are trying to convey. The properties are collected as part of the story and scenario parsing and made available for arbitrary purposes, e.g. filtering in the running of the stories.
Once we have defined the meta properties, we can use a filter to allow or not the running of a given story or scenario based on the meta information. The filtering is controlled by the MetaFilter via the Embedder:
Embedder embedder = ... // define as required embedder.useMetaFilters(asList("+author Mauro", "+theme filtering", "-skip"));
The filters are expressed as sequence of meta properties, where the property keyword "@" is replaced by "+" or "-" according to whether the property should be included or excluded by the filter.
The meta filter can also be specified via Ant or Maven, using the "metaFilters" attribute or configuration element.
The meta filters can also be used to create Story Maps, where each filter a subset of stories that are allowed by the filter.
The resulting output is found in target/jbehave-reports/maps.html, which uses a Swim Lane view to display the results of the mapping.