In your case the simplest thing to do is to use the org.specs2.specification.FixtureExample
trait:
class ExampleSpec extends Specification with FixtureExample[F] {
"Tests using a fixture" >> {
"you can use the fixture values" in { f: F =>
println("Running test 1 with "+f.sessionKey)
success
}
"there is cleanup after each example" in { f: F =>
success
}
}
def fixture[R : AsResult](f: F => R): Result = {
try AsResult(f(F()))
finally cleanup
}
def cleanup = println("cleanup")
}
case class F(sessionKey: String = "key")