これは、最新の 1.12.2-SNAPSHOT で修正されています。あなたは今書くことができます:
import org.specs2.ScalaCheck
import org.specs2.mutable.{Around, Specification}
import org.specs2.execute.Result
class TestSpec extends Specification with ScalaCheck {
"test" >> prop { i: Int =>
around(i must be_>(1))
}
val around = new Around {
def around[T <% Result](t: =>T) = {
("testing a new Int").pp
try { t }
finally { "done".pp }
}
}
}
これにより、プロパティの「本体」の前後にコードが実行されます。
さらに一歩進んで、around
Propsに暗黙的に渡すサポート メソッドを作成することもできます。
class TestSpec extends Specification with ScalaCheck {
"test" >> propAround { i: Int =>
i must be_>(1)
}
// use any implicit "Around" value in scope
def propAround[T, R](f: T => R)
(implicit a: Around,
arb: Arbitrary[T], shrink: Shrink[T],
res: R => Result): Result =
prop((t: T) => a(f(t)))
implicit val around = new Around {
def around[T <% Result](t: =>T) = {
("testing a new Int").pp
try { t }
finally { "done".pp }
}
}
}