Skip to content

Instantly share code, notes, and snippets.

@etorreborre
Created June 3, 2015 00:35
Show Gist options
  • Save etorreborre/ecd20fb884695968e019 to your computer and use it in GitHub Desktop.
Save etorreborre/ecd20fb884695968e019 to your computer and use it in GitHub Desktop.
Minimal spec based on specs2
import org.specs2._
import execute._
import specification._
import core._
class TestSuite(tests: Fragment*) extends Specification {
def is = br ^ Fragments.foreach(tests)(f => Fragments(f, br))
}
object TestSuite {
// something smarter based on macros here
def assert(boolean: =>Boolean): Result =
AsResult(if (boolean) Success("") else Failure("failed"))
def test(r: =>Result): Fragment =
test("test")(r)
def test(name: String)(r: =>Result): Fragment =
Fragment(Text(name), Execution.result(r))
implicit class StringTest(name: String) {
def -(r: =>Result): Fragment =
test(name)(r)
}
implicit def ResultToTest(r: =>Result): Fragment =
test(r)
}
import TestSuite._
// usage: test suite
object MySuiteSpec extends TestSuite(
test{ // anonymous test
assert(2 == 1+1)
},
test("my test"){ // named test
assert(2 == 1+1)
},
"my test" - { // optional magic String#- extension method
assert(2 == 1+1)
},
// optional magic conversion for anonymous test
assert(2 == 1+1)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment