【发布时间】:2020-09-14 04:46:45
【问题描述】:
我正在尝试将 Scala/Play 应用程序升级到 Play 2.7、Scala 2.12.11。
在升级 Play 和 Scala 之前,我进行了以下测试。
升级后出现如下编译错误:
Error: could not find implicit value for evidence parameter of type org.specs2.specification.core.AsExecution[org.specs2.concurrent.ExecutionEnv => org.specs2.matcher.MatchResult[scala.concurrent.Future[services.AuthenticationResult]]]
import org.specs2.concurrent.ExecutionEnv
import org.specs2.mutable.Specification
import scala.concurrent.duration._
class AuthenticationServiceSpec extends Specification {
"The AuthenticationService" should {
val service: AuthenticationService = new MyAuthenticationService
"correctly authenticate Me" in { implicit ee: ExecutionEnv =>
service.authenticateUser("myname", "mypassowrd") must beEqualTo (AuthenticationSuccessful).await(1, 200.millis)
}
}
}
为了尝试解决编译错误,我在类构造函数中添加了一个隐式参数(顺便说一句,之前它是如何工作的,没有隐式参数?):
import org.specs2.concurrent.ExecutionEnv
import org.specs2.mutable.Specification
import scala.concurrent.duration._
import scala.concurrent.Future
import org.specs2.specification.core.AsExecution
import org.specs2.matcher.MatchResult
class AuthenticationServiceSpec(implicit ee: AsExecution[ExecutionEnv => MatchResult[Future[AuthenticationResult]]]) extends Specification {
"The AuthenticationService" should {
val service: AuthenticationService = new MyAuthenticationService
"correctly authenticate Me" in { implicit ee: ExecutionEnv =>
service.authenticateUser("myname", "mypassowrd") must beEqualTo (AuthenticationSuccessful).await(1, 200.millis)
}
}
}
但是在运行时,当我运行测试时,我得到了错误:
Can't find a suitable constructor with 0 or 1 parameter for class org.specs2.specification.core.AsExecution
基于AsExecution的构造函数,有道理……
那我该如何解决这个问题呢?
【问题讨论】:
标签: scala playframework implicit specs2