I have a test using Akka-http which has the error in Intellij No implicit arguments of type: Emptiness[Seq[Rejection]]
. However the code compiles using sbt compile
and the test passes using sbt test
. Even when I run the test from the Intellij it passes. IntelliJ shows the error on the line rejections should not be empty
or when I use rejections.should(not).be(empty)
.
First I had a problem using ~>
implicit operator and I fixed by adding implicit val timeout: RouteTestTimeout = RouteTestTimeout(2 seconds)
. Otherwise I had to explicit use request.~>(gameRoutes)(TildeArrow.injectIntoRoute)
, as it is saying in this question. I am using the following version on build.sbt
:
scalaVersion := "2.12.7"
val akkaVersion = "2.6.10"
val scalaTestVersion = "3.2.0"
lazy val akkaHttpVersion = "10.2.2"
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % akkaVersion,
"com.typesafe.akka" %% "akka-testkit" % akkaVersion,
"com.typesafe.akka" %% "akka-http" % akkaHttpVersion,
"com.typesafe.akka" %% "akka-http-spray-json" % akkaHttpVersion,
"com.typesafe.akka" %% "akka-http-testkit" % akkaHttpVersion,
"com.typesafe.akka" %% "akka-http2-support" % akkaHttpVersion
)
the test:
import akka.http.scaladsl.model.StatusCodes
import akka.http.scaladsl.server.MethodRejection
import akka.http.scaladsl.testkit.{RouteTestTimeout, ScalatestRouteTest}
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec
import scala.concurrent.duration._
class MarshallingJSONSpec
extends AnyWordSpec
with Matchers
with ScalatestRouteTest
with PlayerJsonProtocol {
import MarshallingJSON._
implicit val timeout: RouteTestTimeout = RouteTestTimeout(2 seconds)
"A Game area map backend" should {
"not accept other methods than POST and GET and DELETE" in {
Put("/api/player") ~> gameRoutes ~> check {
rejections should not be empty // IntteliJ SAYS THERE IS AN ERROR HERE
// rejections.should(not).be(empty) // SAME
val methodRejections = rejections.collect {
case rejection: MethodRejection => rejection
}
methodRejections.length shouldBe 3
}
}
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…