https://kotlinlang.org logo
Title
t

taer

12/03/2020, 8:02 PM
Or, better question, how do I get a "ContainerScope" inside a StringSpec?
s

sam

12/03/2020, 8:14 PM
Use free spec
Which is just nested string spec
t

taer

12/03/2020, 8:16 PM
ok.. Tried funSpec, and then just now Free. The nested contexts aren't running in either.. Tried both intellij and gradle runners
s

sam

12/03/2020, 8:17 PM
Gradle should be fine. I use that myself. Got example code? What about the tests in kotest itself can you run those ?
t

taer

12/03/2020, 8:17 PM
Was about to try a generic test to post.
import io.kotest.core.datatest.forAll
import io.kotest.core.spec.style.FreeSpec
import io.kotest.matchers.shouldBe

class ATest:FreeSpec( {
    data class TestData(val number1: Int, val number2: Int, val sum: Int)
    "test" {
        "nested" - {
            forAll(
                TestData(1,2,3),
                TestData(2,2,0),
            ){
                    (a,b,c) -> a+b shouldBe  c
            }
        }
    }
})
using
testImplementation("io.kotest:kotest-runner-junit5-jvm:4.3.1")
    testImplementation("io.kotest:kotest-assertions-core:4.3.1")
from my debugger, it doesn't seem to be going inside the nested one. a breakpoint on the forAll never fires
oh...
"test" {
  "test" - {
that's subtle.
FunSpec does the same:
class ATest:FunSpec( {
    data class TestData(val number1: Int, val number2: Int, val sum: Int)
    test("test") {
        context("nested") {
            forAll(
                TestData(1,2,3),
                TestData(2,2,0),
            ){
                    (a,b,c) -> a+b shouldBe  c
            }
        }
    }
})
That context isn't valid there, and gets 100% ignored
I was using the example under FunSpec which was actually a DescribeSpec. If I just drop the
test
scope, it works as expectd
s

sam

12/03/2020, 10:10 PM
You can't nest context inside test as test is a final scope.
Maybe the DSL could be improved to fix
class ATest: FreeSpec() {
    data class TestData(val number1: Int, val number2: Int, val sum: Int)
    "test" - {
            forAll(
                TestData(1,2,3),
                TestData(2,2,0),
            ){
                    (a,b,c) -> a+b shouldBe  c
            }
    }
})
That should work (without testing it)
c

christophsturm

12/04/2020, 9:29 AM
context could just throw if its inside a test
t

taer

12/04/2020, 5:52 PM
Yeah. My only concern would be a subtle error like what I did creep in somehow, and suddenly the tests become no-ops
It's totally working w/ the
"test" -
syntax
and with the FunSpec's
context("name")
s

sam

12/04/2020, 6:31 PM
@christophsturm is right, we should throw errors at runtime for ill defined tests. I'll ticket that up.
t

taer

12/08/2020, 3:48 PM
Awesome. Thanks!