Skip to content

Instantly share code, notes, and snippets.

@oyvindberg
Created October 23, 2015 13:11
Show Gist options
  • Save oyvindberg/bb1844cb97b2280d8881 to your computer and use it in GitHub Desktop.
Save oyvindberg/bb1844cb97b2280d8881 to your computer and use it in GitHub Desktop.
import java.io.File
import java.net.URL
import org.scalatest.{FunSpec, Matchers}
import unfiltered.filter.Plan
import unfiltered.jetty.Server
trait UnfilteredFixture extends FunSpec with Matchers {
private val port = unfiltered.util.Port.any
val host = dispatch.host("localhost", port)
def planToTest: Plan
private final def newServer = Server
.http(port)
.plan(planToTest)
.resources(new URL(s"file://${new File( "." ).getCanonicalPath}/web/src/main/webapp"))
override final protected def withFixture(test: NoArgTest) = {
val server = newServer
server.start()
try {
test() // Invoke the test function
} finally {
server.stop()
server.destroy()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment