org.specsy.scala.ScalaSpecsy.scala Maven / Gradle / Ivy
// Copyright © 2010-2012, Esko Luontola
// This software is released under the Apache License 2.0.
// The license text is at http://www.apache.org/licenses/LICENSE-2.0
package org.specsy.scala
import org.specsy.bootstrap.ContextDealer
import org.specsy.core.Closure
import fi.jumi.api.RunVia
import org.specsy.Specsy
@RunVia(classOf[Specsy])
abstract class ScalaSpecsy {
private val context = ContextDealer.take()
/**
* Declares a child spec.
*/
def spec(name: String)(spec: => Unit) {
context.spec(name, new ScalaClosure(spec))
}
protected implicit def String_to_NestedSpec(name: String): NestedSpec = new NestedSpec(name)
protected class NestedSpec(name: String) {
/**
* Declares a child spec.
*/
def >>(spec: => Unit) {
context.spec(name, new ScalaClosure(spec))
}
}
/**
* Defers the execution of a piece of code until the end of the current spec.
* All deferred closures will be executed in LIFO order when the current spec exits.
*/
def defer(block: => Unit) {
context.defer(new ScalaClosure(block))
}
/**
* Makes all child specs of the current spec able to see each other's side-effects.
*/
def shareSideEffects() {
context.shareSideEffects()
}
}
private class ScalaClosure(closure: => Unit) extends Closure {
def run() {
closure
}
}