我想测试一个返回Future
的方法。我的尝试如下:
import org.specs2.mutable.Specification
import scala.concurrent.ExecutionContext.Implicits.global
import scala.util.{Failure, Success}
class AsyncWebClientSpec extends Specification{
"WebClient when downloading images" should {
"for a valid link return non-zero content " in {
val testImage = AsyncWebClient.get("https://www.google.cz/images/srpr/logo11ww.png")
testImage.onComplete { res =>
res match {
case Success(image) => image must not have length(0)
case _ =>
}
AsyncWebClient.shutDown
}
}
}
}
除了我无法使这段代码工作之外,我认为测试 futures 应该有更好的方法,并使用 Future
匹配器进行测试。
在 specs2 中应该如何正确实现呢?
value await is not a member of org.specs2.matcher.BeEqualTo
[error] Future(1) must beEqualTo(1).await
- Yar