Created
November 8, 2013 10:52
-
-
Save gbougeard/7369396 to your computer and use it in GitHub Desktop.
ScalaCheck to validate jsonification with Specs2
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
| import models.Place | |
| import models.Place._ | |
| import org.specs2.mutable._ | |
| import org.specs2.ScalaCheck | |
| import play.api.libs.json.Json | |
| import org.scalacheck._ | |
| import Gen._ | |
| import Prop._ | |
| import Arbitrary._ | |
| /** | |
| * Add your spec here. | |
| * You can mock out a whole application including requests, plugins etc. | |
| * For more information, consult the wiki. | |
| */ | |
| object PlaceProp extends Properties("Place") { | |
| property("json idempotent") = forAll { | |
| p:Place => | |
| Json.fromJson(Json.toJson(p)) == p | |
| } | |
| lazy val genPlace: Gen[Place] = for { | |
| id <- arbitrary[Long] | |
| name <- arbitrary[String] | |
| address <- arbitrary[String] | |
| city <- arbitrary[String] | |
| zipcode <- arbitrary[String] | |
| } yield Place(Some(id), name, address, city, zipcode) | |
| implicit lazy val arbHeap: Arbitrary[Place] = Arbitrary(genPlace) | |
| } | |
| class PlaceSpec extends Specification with ScalaCheck { | |
| "jsonification idempotent" ! PlaceProp | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment