简体   繁体   English

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

[英]Scala / specs2 : could not find implicit value for evidence parameter of type AsExecution[ExecutionEnv => MatchResult[Future[AuthenticationResult]]]

I am trying to upgrade a Scala/Play application to Play 2.7 , Scala 2.12.11 .我正在尝试将 Scala/Play 应用程序升级到Play 2.7Scala 2.12.11

I have the following test that probably used to work before I upgraded Play and Scala.在升级 Play 和 Scala 之前,我进行了以下测试。

After the upgrade, I got the following compilation error:升级后出现如下编译错误:

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)
    }

  }

}

To try to solve the compilation error, I added an implicit parameter to the class constructor (BTW, how did it work before, without an implicit parameter?):为了尝试解决编译错误,我在 class 构造函数中添加了一个隐式参数(顺便说一句,之前它是如何工作的,没有隐式参数?):

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)
    }

  }

}

However in runtime when I run the test, I am getting the error:但是在运行时,当我运行测试时,我得到了错误:

Can't find a suitable constructor with 0 or 1 parameter for class org.specs2.specification.core.AsExecution

Based on the constructor of AsExecution , it makes sense...基于AsExecution的构造函数,这很有意义......

How can I solve this problem then?那我该如何解决这个问题呢?

This should work这应该工作

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)
    }

  }

}

The ee: ExecutionEnv will be injected directly in the specification when it is built. ee: ExecutionEnv在构建时会直接注入到规范中。

That's the meaning of the message Can't find a suitable constructor with 0 or 1 parameter for class... .这就是消息Can't find a suitable constructor with 0 or 1 parameter for class... specs2 tries to recursively build arguments for a specification if they have a constructor with 0 or 1 argument.如果 specs2 有一个带 0 或 1 个参数的构造函数,则specs2尝试为规范递归构建 arguments。 The ExecutionEnv is such an argument that specs2 is able to build on its own. ExecutionEnv就是这样一个参数, specs2能够自行构建。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在play中的Specs2测试给我“找不到org.specs2.main.CommandLineAsResult类型的证据参数的隐含值 - Specs2 test within plays gives me "could not find implicit value for evidence parameter of type org.specs2.main.CommandLineAsResult Scala编译错误-找不到类型为证据的隐式值 - Scala compile error - could not find implicit value for evidence parameter of type 无法找到类型证据参数的隐式值 - Could not find implicit value for evidence parameter of type 找不到类型^的证据参数的隐含值 - could not find implicit value for evidence parameter of type ^ Scala / Specs2: def is(implicit ee: ExecutionEnv) = { “Service” should {…} } - Scala / Specs2 : def is(implicit ee: ExecutionEnv) = { “Service” should {…} } 加特林scala扩展失败,找不到证据参数的隐式值 - Gatling scala extension fails with, could not find implicit value for evidence parameter 斯卡拉<console> :24: 错误: 找不到微风.storage.DefaultArrayValue [Any] 类型的证据参数的隐式值 - Scala <console>:24: error: could not find implicit value for evidence parameter of type breeze.storage.DefaultArrayValue[Any] 找不到scala.reflect.ClassManifest [T]类型的证据参数的隐式值 - Could not find implicit value for evidence parameter of type scala.reflect.ClassManifest[T] 找不到scalaz.Applicative类型的证据参数的隐含值 - could not find implicit value for evidence parameter of type scalaz.Applicative 无法找到有序类型的证据参数的隐含值[T] - could not find implicit value for evidence parameter of type Ordered[T]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM