Created
June 3, 2015 00:35
-
-
Save etorreborre/ecd20fb884695968e019 to your computer and use it in GitHub Desktop.
Minimal spec based on specs2
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
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