Skip to content

Commit

Permalink
shouldBe/shouldNotBe chain (#3186)
Browse files Browse the repository at this point in the history
* shouldBe/shouldNotBe chain

* Fixing compilation issue

---------

Co-authored-by: Emil Kantis <emil.kantis@protonmail.com>
  • Loading branch information
sksamuel and Kantis committed Apr 1, 2023
1 parent beec6d5 commit 400ebc1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ class EventuallyTest : WordSpec() {
}

"call the listener when an exception is thrown in the producer function" {
var state: EventuallyState<Unit>? = null
var state: EventuallyState<Int>? = null

shouldThrow<Throwable> {
eventually(retries = 1, listener = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import io.kotest.assertions.print.Printed
import io.kotest.assertions.print.print

@Suppress("UNCHECKED_CAST")
infix fun <T, U : T> T.shouldBe(expected: U?) {
infix fun <T, U : T> T.shouldBe(expected: U?): T {
when (expected) {
is Matcher<*> -> should(expected as Matcher<T>)
else -> {
Expand All @@ -23,14 +23,16 @@ infix fun <T, U : T> T.shouldBe(expected: U?) {
eq(actual, expected)?.let(errorCollector::collectOrThrow)
}
}
return this
}

@Suppress("UNCHECKED_CAST")
infix fun <T> T.shouldNotBe(any: Any?) {
infix fun <T> T.shouldNotBe(any: Any?): T {
when (any) {
is Matcher<*> -> shouldNot(any as Matcher<T>)
else -> shouldNot(equalityMatcher(any))
}
return this
}

infix fun <T> T.shouldHave(matcher: Matcher<T>) = should(matcher)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ class EventuallySpec : FunSpec({
}

test("eventually calls the listener when an exception is thrown in the producer function") {
var state: EventuallyState<Unit>? = null
var state: EventuallyState<Int>? = null

shouldThrow<Throwable> {
eventually({
Expand Down

0 comments on commit 400ebc1

Please sign in to comment.