Skip to content

Instantly share code, notes, and snippets.

@gbougeard
Created November 8, 2013 10:52
Show Gist options
  • Select an option

  • Save gbougeard/7369396 to your computer and use it in GitHub Desktop.

Select an option

Save gbougeard/7369396 to your computer and use it in GitHub Desktop.
ScalaCheck to validate jsonification with Specs2
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