Skip to content

Commit 7899006

Browse files
authored
Rename turbine to turbineScope (#244)
1 parent 55853eb commit 7899006

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

api/Turbine.api

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ public final class app/cash/turbine/FlowKt {
5757
public static synthetic fun test-C2H2yOE$default (Lkotlinx/coroutines/flow/Flow;Lkotlin/time/Duration;Ljava/lang/String;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
5858
public static final fun testIn-5_5nbZA (Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/CoroutineScope;Lkotlin/time/Duration;Ljava/lang/String;)Lapp/cash/turbine/ReceiveTurbine;
5959
public static synthetic fun testIn-5_5nbZA$default (Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/CoroutineScope;Lkotlin/time/Duration;Ljava/lang/String;ILjava/lang/Object;)Lapp/cash/turbine/ReceiveTurbine;
60-
public static final fun turbine-k1IrOU0 (Lkotlin/time/Duration;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
61-
public static synthetic fun turbine-k1IrOU0$default (Lkotlin/time/Duration;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
60+
public static final fun turbineScope-k1IrOU0 (Lkotlin/time/Duration;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
61+
public static synthetic fun turbineScope-k1IrOU0$default (Lkotlin/time/Duration;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
6262
}
6363

6464
public abstract interface class app/cash/turbine/ReceiveTurbine {

src/commonMain/kotlin/app/cash/turbine/Turbine.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ public operator fun <T> Turbine<T>.plusAssign(value: T) { add(value) }
9494
* [withTurbineTimeout].
9595
* @param name If non-null, name is added to any exceptions thrown to help identify which [Turbine] failed.
9696
*/
97-
@Suppress("FunctionName") // Interface constructor pattern.
9897
public fun <T> Turbine(
9998
timeout: Duration? = null,
10099
name: String? = null,

src/commonMain/kotlin/app/cash/turbine/flow.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ internal class TurbineContextImpl(
5555

5656
private val turbineElements = (turbineContext[TurbineRegistryElement] ?: EmptyCoroutineContext) +
5757
(turbineContext[TurbineTimeoutElement] ?: EmptyCoroutineContext)
58+
5859
override fun <R> Flow<R>.testIn(
5960
scope: CoroutineScope,
6061
timeout: Duration?,
@@ -71,7 +72,7 @@ internal class TurbineContextImpl(
7172
/**
7273
* Run a validation block that catches and reports all unhandled exceptions in flows run by Turbine.
7374
*/
74-
public suspend fun turbine(
75+
public suspend fun turbineScope(
7576
timeout: Duration? = null,
7677
validate: suspend TurbineContext.() -> Unit,
7778
) {
@@ -137,7 +138,7 @@ public suspend fun <T> Flow<T>.test(
137138
name: String? = null,
138139
validate: suspend TurbineTestContext<T>.() -> Unit,
139140
) {
140-
turbine {
141+
turbineScope {
141142
collectTurbineIn(this, null, name).apply {
142143
val testContext = TurbineTestContextImpl(this@apply, currentCoroutineContext())
143144
if (timeout != null) {
@@ -185,7 +186,7 @@ private fun <T> testInInternal(flow: Flow<T>, timeout: Duration?, scope: Corouti
185186
checkTimeout(timeout)
186187
}
187188
if (scope.coroutineContext[TurbineRegistryElement] == null) {
188-
throw AssertionError("Turbine can only collect flows within a TurbineContext")
189+
throw AssertionError("Turbine can only collect flows within a TurbineContext. Wrap with turbineScope { .. }")
189190
}
190191

191192
val turbine = flow.collectTurbineIn(scope, timeout, name)

src/commonTest/kotlin/app/cash/turbine/FlowInScopeTest.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ class FlowInScopeTest {
254254
val expected = CustomThrowable("hi")
255255

256256
val actual = assertFailsWith<AssertionError> {
257-
turbine {
257+
turbineScope {
258258
flow<Nothing> {
259259
throw expected
260260
}.testIn(backgroundScope, name = "inner failing")
@@ -290,7 +290,10 @@ class FlowInScopeTest {
290290
val actual = assertFailsWith<AssertionError> {
291291
emptyFlow<Nothing>().testIn(backgroundScope, name = "inner failing")
292292
}
293-
assertEquals("Turbine can only collect flows within a TurbineContext", actual.message)
293+
assertEquals(
294+
"Turbine can only collect flows within a TurbineContext. Wrap with turbineScope { .. }",
295+
actual.message,
296+
)
294297
}
295298
}
296299

@@ -299,7 +302,7 @@ private interface TurbineTestScope : TurbineContext {
299302
}
300303

301304
private fun runTestTurbine(validate: suspend TurbineTestScope.() -> Unit) = runTest {
302-
turbine {
305+
turbineScope {
303306
val turbineTestScope = object : TurbineTestScope, TurbineContext by this {
304307
override val backgroundScope: CoroutineScope = this@runTest.backgroundScope
305308
}

0 commit comments

Comments
 (0)