Request was not handled with spray-testkit

感情迁移 提交于 2019-12-11 12:32:54

问题


My service route:

get(
  path("add" / IntNumber / IntNumber)( (a, b) =>
    complete((a + b).toString())
  )
) ~
post(
  path("add") (
    formFields('a.as[Int], 'b.as[Int]) {
      (a, b) => complete((a + b).toString())
    })
)

my spec:

import spray.http.FormData

class RouteDefinitionSpec
  extends org.specs2.mutable.Specification
  with org.specs2.ScalaCheck
  with spray.testkit.Specs2RouteTest with RouteDefinition {

  def actorRefFactory = system

  "the route" should {
    "add with get requests" in {
      prop { (a: Int, b: Int) =>
        Get(s"/add/$a/$b") ~> route ~> check {
          responseAs[String] === s"${a+b}"
        }
      }
    }

    "add with post form data request" in {
      prop { (a: Int, b: Int) =>
        Post("/add", FormData(Seq("a" -> a.toString, "b" -> b.toString))) ~> route ~> check {
          responseAs[String] === s"${a+b}"
        }
      }
    }
  }
}

Both GET and POST routes are working proper if tested in browser. The POST works also in test. What is wrong with my GET route? Why it can not be tested? What causes such an error and how to avoid it?

[info] RouteDefinitionSpec
[info]
[info] the route should
[error]   x add with get requests
[error]    Falsified after 0 passed tests.
[error]    > ARG_0: 2147483647
[error]    > ARG_1: -2147483648
[error]    > Request was not handled (RouteDefinitionSpec.scala:5)
[info]
[info]   + add with post form data request
[info]
[info]
[info] Total for specification RouteDefinitionSpec
[info] Finished in 393 ms
[info] 2 examples, 102 expectations, 1 failure, 0 error

UPDATE: it seems something to do with scalacheck because following not-property-based test is also "green":

"add test without scalacheck" in {
  Get("/add/30/58") ~> route ~> check {
    responseAs[String] === "88"
  }
}

来源:https://stackoverflow.com/questions/33669605/request-was-not-handled-with-spray-testkit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!