Hi, I thought I can add some simple cool "rules" t...
# spek
l
Hi, I thought I can add some simple cool "rules" to Spek like this:
Copy code
fun <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:
Copy code
given("something") {
  val something by rule { createSomething() }
  ...
}
But kotlin compiler (1.0.x) does not allow to delegate local properties 😞