I'm struggling a bit with this <@UFGCACPE0>: ```va...
# opensavvy
d
I'm struggling a bit with this @CLOVIS:
Copy code
val trackUsages by prepared { mutableList<String>() }
val subject by createSubject(...) {
  // How can I save per test what urls were passed here? I can't just use trackUsages() since I don't have a TestDsl...
  ...
}

private fun createSubject(
  dep1: Prepared<Foo>,
  dep2: Prepared<Bar>,
  fetcher: suspend Foo.(url: String) -> Baz
) = prepared { ... }
is there any clean way to do this?
c
Can do you explain in text what you are trying to do?
d
I need to track calls to that lambda so I can use it in an assert (instead of using mocks and verify...)
c
What are you trying to track calls of?
This should work, I think:
Copy code
val trackUsages by prepared { mutableList<String>() }

fun <A, T> TestDsl.track(block: suspend TestDsl.(A) -> T): suspend (A) -> T {
    val usages = trackUsages()

    return {
        trackUsages += "Called with $it"
        block(it)
    }
}

// Usage:
test("…") {
    val tracked = track { it * 2 }

    tracked(1)
    tracked(2)

    trackUsages() shouldBe listOf("Called with 1", "Called with 2")
}
d
That lambda is passed in the constructor of the subject class... so the way you proposed would force me to instanciate the test subject in each test with all it's deps...
The truth is, I guess I could use the track { } inside the prepared block that creates my subject, the little issue left is that my lambda is something like:
suspend Foo.(url: String) -> Baz
, so I can't really past the TestDsl there... I'll maybe just have to pass both as parameters...