Skip to content

Commit

Permalink
Add convenience traits for various Suites. [fixes #21]
Browse files Browse the repository at this point in the history
  • Loading branch information
rossabaker committed Jul 26, 2011
1 parent 1d8b7ab commit 4240b58
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 25 deletions.
16 changes: 14 additions & 2 deletions README.markdown
Expand Up @@ -488,9 +488,9 @@ ScalaTest

### Code

Mix in ShouldMatchers or MustMatchers to your taste...
Extend ScalatraSuite with your preferred Suite implementation:

class MyScalatraServletTests extends ScalatraFunSuite with ShouldMatchers {
class MyScalatraServletTests extends ScalatraSuite with FunSuite with ShouldMatchers {
// `MyScalatraServlet` is your app which extends ScalatraServlet
addServlet(classOf[MyScalatraServlet], "/*")

Expand All @@ -502,6 +502,18 @@ Mix in ShouldMatchers or MustMatchers to your taste...
}
}

Convenience traits are provided for many Suite implementations:

* ScalatraSpec
* ScalatraFlatSpec
* ScalatraFreeSpec
* ScalatraWordSpec
* ScalatraFunSuite
* ScalatraFeatureSpec
* ScalatraJUnit3Suite
* ScalatraJUnitSuite (JUnit 4)
* ScalatraTestNGSuite

Specs
-----

Expand Down
3 changes: 3 additions & 0 deletions notes/2.0.0.M5.markdown
Expand Up @@ -3,3 +3,6 @@

## scalatra-socketio
* Change interface to socket io to something that allows to keep state per client. [(GH-72)](http://github.com/scalatra/scalatra/issues/72)

## scalatra-scalatest
* New convenience traits for Suites other than FunSuite. [(GH-21)](http://github.com/scalatra/scalatra/issues/21)
4 changes: 3 additions & 1 deletion project/build.scala
Expand Up @@ -148,6 +148,8 @@ object ScalatraBuild extends Build {
val servletApi = "javax.servlet" % "servlet-api" % "2.5" % "provided"

def socketioCore(version: String) = "org.scalatra.socketio-java" % "socketio-core" % version

val testng = "org.testng" % "testng" % "6.1.1" % "optional"
}
import Dependencies._

Expand Down Expand Up @@ -227,7 +229,7 @@ object ScalatraBuild extends Build {
settings = scalatraSettings)
.settings(
libraryDependencies <<= (scalaVersion, libraryDependencies) {
(sv, deps) => deps ++ Seq(scalatest(sv), junit)
(sv, deps) => deps ++ Seq(scalatest(sv), junit, testng)
},
description := "ScalaTest support for the Scalatra test framework")
.dependsOn(scalatraTest)
Expand Down

This file was deleted.

This file was deleted.

@@ -0,0 +1,67 @@
package org.scalatra.test
package scalatest

import org.junit.runner.RunWith
import org.eclipse.jetty.testing.ServletTester
import org.scalatest._
import org.scalatest.junit.{JUnitSuite, JUnit3Suite, JUnitRunner}
import org.scalatest.testng.TestNGSuite

@RunWith(classOf[JUnitRunner])
/**
* Provides Scalatra test support to ScalaTest suites. The servlet tester
* is started before the first test in the suite and stopped after the last.
*/
trait ScalatraSuite extends ScalatraTests with BeforeAndAfterAll {
this: Suite =>

lazy val tester = new ServletTester

override protected def beforeAll(): Unit = start()
override protected def afterAll(): Unit = stop()
}

/**
* Convenience trait to add Scalatra test support to JUnit3Suite.
*/
trait ScalatraJUnit3Suite extends JUnit3Suite with ScalatraSuite

/**
* Convenience trait to add Scalatra test support to JUnitSuite.
*/
trait ScalatraJUnitSuite extends JUnitSuite with ScalatraSuite

/**
* Convenience trait to add Scalatra test support to TestNGSuite.
*/
trait ScalatraTestNGSuite extends TestNGSuite with ScalatraSuite

/**
* Convenience trait to add Scalatra test support to FeatureSpec.
*/
trait ScalatraFeatureSpec extends FeatureSpec with ScalatraSuite

/**
* Convenience trait to add Scalatra test support to Spec.
*/
trait ScalatraSpec extends Spec with ScalatraSuite

/**
* Convenience trait to add Scalatra test support to FlatSpec.
*/
trait ScalatraFlatSpec extends FlatSpec with ScalatraSuite

/**
* Convenience trait to add Scalatra test support to FreeSpec.
*/
trait ScalatraFreeSpec extends FreeSpec with ScalatraSuite

/**
* Convenience trait to add Scalatra test support to WordSpec.
*/
trait ScalatraWordSpec extends WordSpec with ScalatraSuite

/**
* Convenience trait to add Scalatra test support to FunSuite.
*/
trait ScalatraFunSuite extends FunSuite with ScalatraSuite

0 comments on commit 4240b58

Please sign in to comment.