Last active
July 3, 2020 23:23
-
-
Save DanielBlanco/ce635b896dca654bc29f968c63dc32f2 to your computer and use it in GitHub Desktop.
Starting a Play application within zio-test context.
This file contains 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
package zio.test | |
import play.api.test._ | |
import play.api.test.Helpers._ | |
import zio.{UIO, URIO} | |
import zio.clock.Clock | |
import zio.duration._ | |
import zio.test.environment.TestEnvironment | |
/** A Play 2.3+ runnable spec that provides testable versions of all of the | |
* modules in ZIO (Clock, Random, etc). | |
*/ | |
trait PlayRunnableSpec extends DefaultRunnableSpec { | |
val testConfigMap = Map("test" -> true) | |
lazy val fakeApp = FakeApplication(additionalConfiguration = testConfigMap) | |
/** Returns an effect that executes a given spec, producing the results of the | |
* execution. | |
*/ | |
private[zio] override def runSpec( | |
spec: ZSpec[Environment, Failure] | |
): URIO[TestLogger with Clock, ExecutedSpec[Failure]] = | |
startPlay(fakeApp).bracket(_ => stopPlay) { _ => | |
runner.run(aspects.foldLeft(spec)(_ @@ _) @@ TestAspect.fibers) | |
} | |
def startPlay(app: play.api.Application) = | |
UIO.effectTotal(play.api.Play.start(app)) | |
def stopPlay = | |
UIO.effectTotal(play.api.Play.stop()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment