Created
January 10, 2012 13:21
-
-
Save lovuikeng/1589059 to your computer and use it in GitHub Desktop.
Play 2 Specs2 form test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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