Skip to content

Instantly share code, notes, and snippets.

@lovuikeng
Created January 10, 2012 13:21
Show Gist options
  • Select an option

  • Save lovuikeng/1589059 to your computer and use it in GitHub Desktop.

Select an option

Save lovuikeng/1589059 to your computer and use it in GitHub Desktop.
Play 2 Specs2 form test
object Application extends Controller {
val helloForm = Form(
of(
"name" -> nonEmptyText,
"repeat" -> number(min = 1, max = 100),
"color" -> optional(text)
)
)
//
}
object FormSpec extends Specification {
import controllers.Application.helloForm
"HelloWorld form" should {
"require name" in {
val form = helloForm.bind(Map("repeat" -> "10", "color" -> "red"))
form.hasErrors must beTrue
form.errors.size must equalTo(1)
form("name").hasErrors must beTrue
form("repeat").hasErrors must beFalse
form("repeat").value must beSome.which(_ == "10")
}
//
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment