Skip to content

Commit

Permalink
Prepare version 0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeWharton committed Jul 27, 2021
1 parent b13e19e commit edcbfa2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 28 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
## [Unreleased]


## [0.6.0]
### Added
- `expectMostRecentItem()` function consumes all received items and returns the most recent item.

### Changed
- Functions which may suspend to wait for an event are now prefixed with 'await'.

## [0.5.2]
### Fixed
- Support running on a background thread with Kotlin/Native.
Expand Down Expand Up @@ -52,7 +59,8 @@
Initial release


[Unreleased]: /~https://github.com/cashapp/turbine/compare/0.5.2...HEAD
[Unreleased]: /~https://github.com/cashapp/turbine/compare/0.6.0...HEAD
[0.6.0]: /~https://github.com/cashapp/turbine/releases/tag/0.6.0
[0.5.2]: /~https://github.com/cashapp/turbine/releases/tag/0.5.2
[0.5.1]: /~https://github.com/cashapp/turbine/releases/tag/0.5.1
[0.5.0]: /~https://github.com/cashapp/turbine/releases/tag/0.5.0
Expand Down
52 changes: 26 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ Turbine is a small testing library for kotlinx.coroutines

```kotlin
flowOf("one", "two").test {
assertEquals("one", expectItem())
assertEquals("two", expectItem())
expectComplete()
assertEquals("one", awaitItem())
assertEquals("two", awaitItem())
awaitComplete()
}
```

Expand All @@ -22,7 +22,7 @@ repositories {
mavenCentral()
}
dependencies {
testImplementation 'app.cash.turbine:turbine:0.5.2'
testImplementation 'app.cash.turbine:turbine:0.6.0'
}
```

Expand All @@ -37,7 +37,7 @@ repositories {
}
}
dependencies {
testImplementation 'app.cash.turbine:turbine:0.6.0-SNAPSHOT'
testImplementation 'app.cash.turbine:turbine:0.7.0-SNAPSHOT'
}
```

Expand All @@ -63,7 +63,7 @@ events will fail your test.

```kotlin
flowOf("one", "two").test {
assertEquals("one", expectItem())
assertEquals("one", awaitItem())
}
```
```
Expand All @@ -78,17 +78,17 @@ also be consumed.

```kotlin
flowOf("one", "two").test {
assertEquals("one", expectItem())
assertEquals("two", expectItem())
expectComplete()
assertEquals("one", awaitItem())
assertEquals("two", awaitItem())
awaitComplete()
}
```

Received events can be explicitly ignored, however.

```kotlin
flowOf("one", "two").test {
assertEquals("one", expectItem())
assertEquals("one", awaitItem())
cancelAndIgnoreRemainingEvents()
}
```
Expand Down Expand Up @@ -119,7 +119,7 @@ must consume.

```kotlin
flow { throw RuntimeException("broken!") }.test {
assertEquals("broken!", expectError().message)
assertEquals("broken!", awaitError().message)
}
```

Expand All @@ -141,7 +141,7 @@ Caused by: java.lang.RuntimeException: broken!

#### Asynchronous Flows

Calls to `expectItem()`, `expectComplete()`, and `expectError()` are suspending and will wait
Calls to `awaitItem()`, `awaitComplete()`, and `awaitError()` are suspending and will wait
for events from asynchronous flows.

```kotlin
Expand All @@ -151,12 +151,12 @@ channelFlow {
send("item")
}
}.test {
assertEquals("item", expectItem())
expectComplete()
assertEquals("item", awaitItem())
awaitComplete()
}
```

By default, when one of the "expect" methods suspends waiting for an event it will timeout after
By default, when one of the "await" methods suspends waiting for an event it will timeout after
one second.

```kotlin
Expand All @@ -166,8 +166,8 @@ channelFlow {
send("item")
}
}.test {
assertEquals("item", expectItem())
expectComplete()
assertEquals("item", awaitItem())
awaitComplete()
}
```
```
Expand All @@ -183,8 +183,8 @@ channelFlow {
send("item")
}
}.test(timeout = 3.seconds) {
assertEquals("item", expectItem())
expectComplete()
assertEquals("item", awaitItem())
awaitComplete()
}
```

Expand All @@ -200,9 +200,9 @@ channelFlow {
}
}
}.test {
assertEquals("item 0", expectItem())
assertEquals("item 1", expectItem())
assertEquals("item 2", expectItem())
assertEquals("item 0", awaitItem())
assertEquals("item 1", awaitItem())
assertEquals("item 2", awaitItem())
cancel()
}
```
Expand All @@ -216,7 +216,7 @@ Emissions to hot flows that don't have active consumers are dropped. It's import
val mutableSharedFlow = MutableSharedFlow<Int>(replay = 0)
mutableSharedFlow.emit(1)
mutableSharedFlow.test {
assertEquals(expectItem(), 1)
assertEquals(awaitItem(), 1)
cancelAndConsumeRemainingEvents()
}
```
Expand All @@ -226,9 +226,9 @@ will fail with a timeout exception.
```
kotlinx.coroutines.TimeoutCancellationException: Timed out waiting for 1000 ms
(Coroutine boundary)
at app.cash.turbine.ChannelBasedFlowTurbine$expectEvent$2.invokeSuspend(FlowTurbine.kt:238)
at app.cash.turbine.ChannelBasedFlowTurbine$awaitEvent$2.invokeSuspend(FlowTurbine.kt:238)
at app.cash.turbine.ChannelBasedFlowTurbine$withTimeout$2.invokeSuspend(FlowTurbine.kt:206)
at app.cash.turbine.ChannelBasedFlowTurbine.expectItem(FlowTurbine.kt:243)
at app.cash.turbine.ChannelBasedFlowTurbine.awaitItem(FlowTurbine.kt:243)
```

Proper usage of Turbine with hot flows looks like the following.
Expand All @@ -237,7 +237,7 @@ Proper usage of Turbine with hot flows looks like the following.
val mutableSharedFlow = MutableSharedFlow<Int>(replay = 0)
mutableSharedFlow.test {
mutableSharedFlow.emit(1)
assertEquals(expectItem(), 1)
assertEquals(awaitItem(), 1)
cancelAndConsumeRemainingEvents()
}
```
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ GROUP=app.cash.turbine
POM_ARTIFACT_ID=turbine

# HEY! If you change the major version here be sure to update release.yaml doc target folder!
VERSION_NAME=0.6.0-SNAPSHOT
VERSION_NAME=0.6.0

POM_NAME=Turbine
POM_DESCRIPTION=A small testing library for kotlinx.coroutines Flow.
Expand Down

0 comments on commit edcbfa2

Please sign in to comment.