최신 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
에 전달하는 지원 방법을 만들 수 있습니다 Prop`에`Result``에서 암시 적 변환이 있지만,
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 }
}
}
}
문제는이다 , 다른쪽으로 돌아가는 사람은 없습니다. –