У меня есть тест с использованием Akka-http, который имеет ошибку в Intellij No implicit arguments of type: Emptiness[Seq[Rejection]]
. Однако код компилируется с использованием sbt compile
, а тест проходит с использованием sbt test
. Даже когда я запускаю тест из Intellij, он проходит. IntelliJ показывает ошибку в строке rejections should not be empty
или когда я использую rejections.should(not).be(empty)
.
Сначала у меня возникла проблема с использованием неявного оператора ~>
, и я решил ее, добавив implicit val timeout: RouteTestTimeout = RouteTestTimeout(2 seconds)
. В противном случае мне пришлось явно использовать request.~>(gameRoutes)(TildeArrow.injectIntoRoute)
, как сказано в этом вопросе. Я использую следующую версию на 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
)
тест:
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
}
}
}
}