Skip to content

Instantly share code, notes, and snippets.

@mikemckibben
Last active August 29, 2015 14:11
Show Gist options
  • Save mikemckibben/5d00481ef0004e48f30c to your computer and use it in GitHub Desktop.
Save mikemckibben/5d00481ef0004e48f30c to your computer and use it in GitHub Desktop.
Spray AnyParam with default value Bug
import org.specs2.mutable.Specification
import spray.http._
import spray.routing._
import spray.testkit.Specs2RouteTest
class AnyParamSpec extends Specification with Specs2RouteTest with Directives {
val route = anyParam('p ? "default") { p => complete(StatusCodes.OK, p) }
// replace with the following workaround
//val route = (anyParam('p) | provide("default")) { p => complete(StatusCodes.OK, p) }
"anyParam with default value should check form fields and query parameters before applying default value" >> {
"request with explicit form field" in {
Post("/", FormData(Seq("p" -> "specified"))) ~> route ~> check {
responseAs[String] must_== "specified"
}
}
"request with explicit query param" in {
Get("/?p=specified") ~> route ~> check {
responseAs[String] must_== "specified"
}
}
"request with no param" in {
Get("/") ~> route ~> check {
responseAs[String] must_== "default"
}
}
}
}
scalaVersion := "2.11.4"
scalaSource in Test := baseDirectory.value
libraryDependencies ++= Seq(
"io.spray" %% "spray-routing-shapeless2" % "1.3.2",
"io.spray" %% "spray-testkit" % "1.3.2",
"org.specs2" %% "specs2" % "2.4.10"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment