langara
10/16/2016, 9:10 AMfun <T> Dsl.rule(before: () -> T, after: (T) -> Unit = {}) = object : ReadOnlyProperty<Any?, T> {
private var currentValue: T = before()
init {
beforeEach { currentValue = before() }
afterEach { after(currentValue) }
}
override fun getValue(thisRef: Any?, property: KProperty<*>) = currentValue
}
And then use it like this:
given("something") {
val something by rule { createSomething() }
...
}
But kotlin compiler (1.0.x) does not allow to delegate local properties 😞