|
Play Framework/Scala example source code file (Specs.scala)
The Specs.scala Play Framework example source code/* * Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com> */ package play.api.test import org.specs2.mutable.Around import org.specs2.specification.Scope import org.openqa.selenium.WebDriver import org.specs2.execute.{ AsResult, Result } // NOTE: Do *not* put any initialisation code in the below classes, otherwise delayedInit() gets invoked twice // which means around() gets invoked twice and everything is not happy. Only lazy vals and defs are allowed, no vals // or any other code blocks. /** * Used to run specs within the context of a running application. * * @param app The fake application */ abstract class WithApplication(val app: FakeApplication = FakeApplication()) extends Around with Scope { implicit def implicitApp = app override def around[T: AsResult](t: => T): Result = { Helpers.running(app)(AsResult.effectively(t)) } } /** * Used to run specs within the context of a running server. * * @param app The fake application * @param port The port to run the server on */ abstract class WithServer(val app: FakeApplication = FakeApplication(), val port: Int = Helpers.testServerPort) extends Around with Scope { implicit def implicitApp = app implicit def implicitPort: Port = port override def around[T: AsResult](t: => T): Result = Helpers.running(TestServer(port, app))(AsResult.effectively(t)) } /** * Used to run specs within the context of a running server, and using a web browser * * @param webDriver The driver for the web browser to use * @param app The fake application * @param port The port to run the server on */ abstract class WithBrowser[WEBDRIVER <: WebDriver]( val webDriver: WebDriver = WebDriverFactory(Helpers.HTMLUNIT), val app: FakeApplication = FakeApplication(), val port: Int = Helpers.testServerPort) extends Around with Scope { def this( webDriver: Class[WEBDRIVER], app: FakeApplication, port: Int) = this(WebDriverFactory(webDriver), app, port) implicit def implicitApp = app implicit def implicitPort: Port = port lazy val browser: TestBrowser = TestBrowser(webDriver, Some("http://localhost:" + port)) override def around[T: AsResult](t: => T): Result = { try { Helpers.running(TestServer(port, app))(AsResult.effectively(t)) } finally { browser.quit() } } } Other Play Framework source code examplesHere is a short list of links related to this Play Framework Specs.scala source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.