Specs2 promotes functional style when dealing with Acceptance specification (even Unit specification if we want).
Risks of using old style (mutable style) are mentioned in the spec Specs2 philosophy and concernes potential unwanted side-effects:
The important things to know are:
side-effects are only used to build the specification fragments, by mutating a variable they are also used to short-circuit the execution of an example as soon as there is a failure (by throwing an exception). If you build fragments in the body of examples or execute the same specification concurrently, the sky should fall down. "context" management is to be done with case classes or traits (see org.specs2.examples.MutableSpec)
I don't figure out how a same specification could be run concurrently since each specification is distinct from the other (separated class's instances), even if we run the same twice or more simultaneously.
Indeed, specFragments
(mutable variable):
protected[mutable] var specFragments: Fragments = new Fragments()
is declared in a trait
called FragmentBuilder
, not in an object
(in scala sense => singleton) or other shared thing..., so specFragments
is a local variable to each Specification
's instance.
So what might a scenario be risking concurrency mechanism?
I don't really figure out a true scenario (non-stupid) proving the benefit of Specs2 functional style.