Meta Filters

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 FilterMeta PropertyAllowed
+theme smoke testing -skip@theme smoke testingtrue
+theme smoke testing -skip@skipfalse
+theme smoke testing@theme smoke testingtrue
+theme smoke testing@theme testingfalse
-skip@theme testingtrue
-skip@skipfalse
+theme smoke testing -theme UI@theme smoke testingtrue
+theme smoke testing -theme UI@theme UIfalse

Configuring Meta Filters

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.