Also this one fails: ```import io.kotest.core.spec...
# kotest
k
Also this one fails:
Copy code
import io.kotest.core.spec.style.FreeSpec
import io.kotest.datatest.withData
import io.kotest.matchers.shouldBe

fun foo(i: Int) = i + 1

class `this works ok`: FreeSpec({
    withData(1, 2, 3) { i ->
        foo(i) shouldBe i + 1
    }
})

class `this doesn't work`: FreeSpec({
    "some context" {
        withData(1, 2, 3) { i ->
            foo(i) shouldBe i + 1
        }
    }
})
The second test class fails with
io.kotest.core.spec.InvalidDslException: Cannot add a root test after the spec has been instantiated: 1
e
You can't define tests with
withData
inside a leaf, only at root level or inside a container.
k
Ah, I see, thanks. It feels a little counterintuitive that when not using
withData
, the assertions must be inside a leaf (which may optionally be inside a container), but when using
withData
the assertions must be directly under a container.
e
withData
generates a leaf for each row under the hood, so they're not in a container. But I understand that it can be perceived as being directly under the container