我刚刚升级到Play 2.2,并且由于Helpers
已更改,我的测试不再编译了。
import org.specs2.mutable.Specification
import play.api.test._
import play.api.test.Helpers._
import play.api.libs.ws._
import play.api.mvc.Results._
class ApplicationSpec extends Specification {
import controllers._
"Application" should {
"test WS logic" in new WithServer {
await(WS.url("http://localhost:3333").get()).status must equalTo(OK)
}
}
}
给出以下编译错误
type mismatch;
[error] found : scala.concurrent.Future[play.api.libs.ws.Response]
[error] required: org.specs2.matcher.Matcher[?]
答案 0 :(得分:6)
这只是play.api.test.Helpers.await
和org.specs2.matcher.FutureMatchers.await
之间的名称冲突。
您可以更明确地引用播放助手(或重命名导入):
Helpers.await(WS.url("http://localhost:3333").get()).status must equalTo(OK)
然而,以下情况可能更好,但尚未进入文档:
因此,只需在测试中扩展PlaySpecification
而不是Specification
:
import org.specs2.mutable.Specification
import play.api.test._
import play.api.test.Helpers._
import play.api.libs.ws._
import play.api.mvc.Results._
class ApplicationSpec extends PlaySpecification {
import controllers._
"Application" should {
"test WS logic" in new WithServer {
await(WS.url("http://localhost:3333").get()).status must equalTo(OK)
}
}
}