Request was not handled with spray-testkit

时间:2015-11-12 10:42:43

标签: scalacheck spray-test spec2 spray-routing

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

0 个答案:

没有答案