Skip to content

Instantly share code, notes, and snippets.

@twoism
Created May 24, 2012 23:26
Show Gist options
  • Select an option

  • Save twoism/2784866 to your computer and use it in GitHub Desktop.

Select an option

Save twoism/2784866 to your computer and use it in GitHub Desktop.
package com.twitter.demo
import com.twitter.macaw.{FinatraController, Status}
class EchoController extends FinatraController {
get("/echo.json") { request =>
request.params.get("s") match {
case Some(s) =>
actionJsonObjectResponse(Map("echo" -> s))
case None =>
actionApiError("missing parameter: s", Status.BadRequest)
}
}
}
package com.twitter.demo
import com.twitter.macaw.test.MacawSpec
import com.twitter.macaw.Status
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
class EchoControllerSpec extends MacawSpec {
def app = { new EchoController() }
"GET /echo.json?s=foo" should "respond with an echo" in {
get("/echo.json", Map("s"->"foo"))
response should matchActionResponse(Map("echo" -> "foo"))
}
"GET /echo.json" should "respond with an error" in {
get("/echo.json")
response should matchActionApiError("missing parameter: s", Status.BadRequest)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment