One of the principal use cases for defining meta info in our stories is to be able to filter the stories based on the meta info provided.
A meta filter has a structure that mirrors that of the meta properties, i.e. it's expressed as a sequence of name-value patterns:
meta filter :== ([+|-] [name] [value pattern])+
where [+|-] indicates if the filter should include or exclude the meta property and the [value pattern] can be either an exact match of the property value (including empty value) or use the * matching notation.
The following are all valid meta filters:
+author Mauro +theme filtering +author * +theme filtering +author * +theme filtering -skip -skip
Let's now look at how the filtering is done. JBehave provides a MetaFilter component that interprets the parses the textual meta filter and provides a method to determine if a Meta instance is allowed or not:
MetaFilter metaFilter = new MetaFilter("+author * -skip"); Meta meta = ... // contains meta info as parsed from the textual story boolean allowed = metaFilter.allow(meta);
A few examples of meta filters and properties that allowed or not allowed:
Meta Filter | Meta Property | Allowed |
---|---|---|
+theme smoke testing -skip | @theme smoke testing | true |
+theme smoke testing -skip | @skip | false |
+theme smoke testing | @theme smoke testing | true |
+theme smoke testing | @theme testing | false |
-skip | @theme testing | true |
-skip | @skip | false |
+theme smoke testing -theme UI | @theme smoke testing | true |
+theme smoke testing -theme UI | @theme UI | false |
As usual, JBehave allow multiple equivalent ways of configuration. One can specify the meta filters directly via the Embedder, either programmatically or via the annotation:
Embedder embedder = ... // define as required embedder.useMetaFilters(asList("+author Mauro", "+theme filtering", "-skip"));
@RunWith(AnnotatedEmbedderRunner.class) @UsingEmbedder(metaFilters = {"+author Mauro", "+theme filtering", "-skip"}) public class AnnotatedTraderEmbedder extends InjectableEmbedder { }Note that because of its additive sequential nature, the meta filters will all be joined together when running the stories. Have different meta filters comes into play when doing story mapping.
The meta filter can also be specified via Ant tasks or Maven goals, using the "metaFilters" attribute or configuration element.