Skip to content

Instantly share code, notes, and snippets.

@etorreborre
Created March 14, 2012 01:35
Show Gist options
  • Save etorreborre/2033254 to your computer and use it in GitHub Desktop.
Save etorreborre/2033254 to your computer and use it in GitHub Desktop.
Implicit FakeApplication context for a Play 2.0 Specification
package examples
import org.specs2._
import specification._
import FakeApplication._
/**
* This Specification shows how to declare only once the FakeApplication context in which all the examples
* must be executed
*/
class PlaySpec extends mutable.Specification {
// all the examples will be executed in this FakeApplication context
implicit val application = RunAround(FakeApplication())
"Computer model" should {
"be retrieved by id" in {
val Some(macintosh) = Computer.findById(21)
macintosh.name must equalTo("Macintosh")
}
}
}
// This could be added to the Play 2.0 testing library
import execute._
case class RunAround(app: FakeApplication) extends Around {
def around[R <% Result](r: =>R) = running(app)(r)
}
/**
* Support class for compilation
*/
object Computer {
def findById(id: Int): Option[Computer] = Some(Computer("Macintosh"))
}
case class Computer(name: String = "name")
case class FakeApplication()
object FakeApplication {
def running[R <% Result](app: FakeApplication)(r: =>R) = r
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment