Let's pretend that we want some dummy data available for use in our specs. We can ensure that each spec gets its own data set by creating a behavior.

First, let's register our behavior. This time, we want it to only apply to specs that implement a specific interface: INeedDummyData.

ο»Ώ

Now let's define our INeedDummyData interface:

ο»Ώ

The interface defines a single writable property: Foos. Our behavior will create some Foo objects and assign them there for the spec to use.

Here's our behavior:

ο»Ώ

Now our specs have access to a collection of Foo's that they can use, without having to do anything special:

ο»Ώ

You can also use a behavior to modify the [auto-mocking](πŸ”—ο»Ώ) container:

ο»Ώ

Specs can then request either the real service or the pre-configured mock object by implementing the corresponding marker interface.

ο»Ώ

Behaviors can do more than just define state before a spec executes. [They can also clean things up after a spec executes](πŸ”—ο»Ώ).