Scala / specs2 : 找不到类型为 AsExecution 的证据参数的隐式值 [ExecutionEnv => MatchResult[Future[AuthenticationR



我正在尝试将 Scala/Play 应用程序升级到Play 2.7Scala 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的构造函数,这是有道理的...

那我该如何解决这个问题呢?

这应该有效

class AuthenticationServiceSpec(implicit ee: ExecutionEnv) extends Specification {
"The AuthenticationService" should {
val service: AuthenticationService = new MyAuthenticationService
"correctly authenticate Me" in {
service.authenticateUser("myname", "mypassword") must beEqualTo (AuthenticationSuccessful).await(1, 200.millis)
}
}
}

构建时,ee: ExecutionEnv将直接注入到规范中。

这就是消息的含义Can't find a suitable constructor with 0 or 1 parameter for class ....specs2尝试递归地为规范构建参数,如果他们有一个具有 0 或 1 参数的构造函数。ExecutionEnv就是这样一个论点,specs2能够自己建立起来。

相关内容

  • 没有找到相关文章

最新更新