Skip to content

Commit

Permalink
Add test support for HEAD methods. [#20]
Browse files Browse the repository at this point in the history
HEAD support has existed in main for a long time, but previous versions of
Jetty choked while testing it.  7.4.x handles it just fine, so the methods
have been added ot the test DSL.

Add support for the other methods before we close #51.
  • Loading branch information
rossabaker committed Jul 28, 2011
1 parent 8fbf725 commit f25bc33
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
25 changes: 25 additions & 0 deletions core/src/test/scala/org/scalatra/HeadSpec.scala
@@ -0,0 +1,25 @@
package org.scalatra

import org.scalatra.specs2.ScalatraSpec

class HeadSpec extends ScalatraSpec { def is =
"A HEAD request should" ^
"return no body" ! noBody^
"preserve headers" ! preserveHeaders^
end

val servletHolder = addServlet(classOf[HeadSpecServlet], "/*")

def noBody = head("/") { response.body must_== "" }

def preserveHeaders = head("/") {
header("X-Powered-By") must_== "caffeine"
}
}

class HeadSpecServlet extends ScalatraServlet {
get("/") {
response.addHeader("X-Powered-By", "caffeine")
"poof -- watch me disappear"
}
}
1 change: 1 addition & 0 deletions notes/2.0.0.M5.markdown
Expand Up @@ -10,3 +10,4 @@
## scalatra-scalatest
* New convenience traits for Suites other than FunSuite. [(GH-21)](http://github.com/scalatra/scalatra/issues/21)
* For convenience, ScalatraSuite now extends MustMatchers and ShouldMatchers.
* Support for testing HEAD requests. [(GH-20)](http://github.com/scalatra/scalatra/issues/20)
6 changes: 6 additions & 0 deletions test/src/main/scala/org/scalatra/test/ScalatraTests.scala
Expand Up @@ -117,6 +117,12 @@ trait ScalatraTests {
def get[A](uri: String, params: Iterable[(String, String)] = Seq.empty, headers: Map[String, String] = Map.empty)(f: => A): A =
withResponse(httpRequest("GET", uri, params, headers), f)

def head[A](uri: String)(f: => A): A = withResponse(httpRequest("HEAD", uri), f)
def head[A](uri: String, params: Tuple2[String, String]*)(f: => A): A =
get(uri, params, Map[String, String]())(f)
def head[A](uri: String, params: Iterable[(String, String)] = Seq.empty, headers: Map[String, String] = Map.empty)(f: => A): A =
withResponse(httpRequest("HEAD", uri, params, headers), f)

def post[A](uri: String, params: Tuple2[String, String]*)(f: => A): A =
post(uri, params)(f)
def post[A](uri: String, params: Iterable[(String,String)])(f: => A): A =
Expand Down

0 comments on commit f25bc33

Please sign in to comment.