diff --git a/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/anyAssertions.kt b/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/anyAssertions.kt index 92154113e..02a2b165d 100644 --- a/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/anyAssertions.kt +++ b/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/anyAssertions.kt @@ -45,6 +45,7 @@ fun Expect.isSameAs(expected: T): Expect = _logicAppend { isSameAs(exp */ fun Expect.isNotSameAs(expected: T): Expect = _logicAppend { isNotSameAs(expected) } +//TODO move to anyExpectations.kt with 0.18.0 /** * Allows to state a reason for one or multiple assertions for the current subject. * @@ -55,7 +56,7 @@ fun Expect.isNotSameAs(expected: T): Expect = _logicAppend { isNotSame * * @since 0.15.0 * - * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.deprecated.AnyAssertionSamples.because + * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.AnyExpectationSamples.because */ fun Expect.because(reason: String, assertionCreator: Expect.() -> Unit): Expect = _logicAppend { because(reason, assertionCreator) } @@ -167,6 +168,7 @@ internal fun Expect<*>.isA(kClass: KClass): SubjectChangerBui inline fun Expect<*>.isA(noinline assertionCreator: Expect.() -> Unit): Expect = isA(TSub::class).transformAndAppend(assertionCreator) +//TODO move to anyExpectations.kt with 0.18.0 /** * Can be used to separate single assertions. * @@ -176,10 +178,11 @@ inline fun Expect<*>.isA(noinline assertionCreator: Expect< * * @return an [Expect] for the subject of `this` expectation. * - * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.deprecated.AnyAssertionSamples.andFeature + * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.AnyExpectationSamples.andFeature */ inline val Expect.and: Expect get() = this +//TODO move to anyExpectations.kt with 0.18.0 /** * Can be used to create a group of sub assertions when using the fluent API. * @@ -190,7 +193,7 @@ inline val Expect.and: Expect get() = this * * @return an [Expect] for the subject of `this` expectation. * - * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.deprecated.AnyAssertionSamples.and + * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.AnyExpectationSamples.and */ infix fun Expect.and(assertionCreator: Expect.() -> Unit): Expect = _logic.appendAssertionsCreatedBy(assertionCreator) diff --git a/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/anyExpectations.kt b/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/anyExpectations.kt new file mode 100644 index 000000000..fb004274f --- /dev/null +++ b/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/anyExpectations.kt @@ -0,0 +1,195 @@ +package ch.tutteli.atrium.api.fluent.en_GB + +import ch.tutteli.atrium.creating.Expect +import ch.tutteli.atrium.logic.creating.typeutils.IterableLike +import ch.tutteli.atrium.logic.* +import ch.tutteli.atrium.logic.creating.transformers.SubjectChangerBuilder +import ch.tutteli.atrium.logic.utils.iterableLikeToIterable +import ch.tutteli.kbox.glue +import kotlin.reflect.KClass + +/** + * Expects that the subject of `this` expectation is equal to [expected]. + * + * @return an [Expect] for the subject of `this` expectation. + * + * @since 0.17.0 + * + * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.AnyExpectationSamples.toEqual + */ +fun Expect.toEqual(expected: T): Expect = _logicAppend { toBe(expected) } + +/** + * Expects that the subject of `this` expectation is **not** equal to [expected]. + * + * @return an [Expect] for the subject of `this` expectation. + * + * @since 0.17.0 + * + * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.AnyExpectationSamples.notToEqual + */ +fun Expect.notToEqual(expected: T): Expect = _logicAppend { notToBe(expected) } + +/** + * Expects that the subject of `this` expectation is the same instance as [expected]. + * + * @return an [Expect] for the subject of `this` expectation. + * + * @since 0.17.0 + * + * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.AnyExpectationSamples.toBeTheInstance + */ +fun Expect.toBeTheInstance(expected: T): Expect = _logicAppend { isSameAs(expected) } + +/** + * Expects that the subject of `this` expectation is **not** the same instance as [expected]. + * + * @return an [Expect] for the subject of `this` expectation. + * + * @since 0.17.0 + * + * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.AnyExpectationSamples.notToBeTheInstance + */ +fun Expect.notToBeTheInstance(expected: T): Expect = _logicAppend { isNotSameAs(expected) } + +/** + * Expects that the subject of `this` expectation is either `null` in case [assertionCreatorOrNull] + * is `null` or is not `null` and holds all assertions [assertionCreatorOrNull] creates. + * + * @return an [Expect] for the subject of `this` expectation. + * + * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.AnyExpectationSamples.toEqualNullIfNullGivenElse + */ +fun Expect.toEqualNullIfNullGivenElse( + assertionCreatorOrNull: (Expect.() -> Unit)? +): Expect = _logicAppend { toBeNullIfNullGivenElse(assertionCreatorOrNull) } + +/** + * Expects that the subject of `this` expectation is not null and changes the subject to the non-nullable version. + * + * @return An [Expect] with the non-nullable type [T] (was `T?` before). + * + * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.AnyExpectationSamples.notToEqualNullFeature + */ +inline fun Expect.notToEqualNull(): Expect = notToEqualNullButToBeA(T::class).transform() + + +@PublishedApi // in order that _logic does not become part of the API we have this extra function +internal fun Expect.notToEqualNullButToBeA(kClass: KClass): SubjectChangerBuilder.ExecutionStep = + _logic.notToBeNullButOfType(kClass) + +/** + * Expects that the subject of `this` expectation is not null and + * that it holds all assertions the given [assertionCreator] creates. + * + * @return An [Expect] with the non-nullable type [T] (was `T?` before) + * + * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.AnyExpectationSamples.notToEqualNull + */ +inline fun Expect.notToEqualNull(noinline assertionCreator: Expect.() -> Unit): Expect = + notToEqualNullButToBeA(T::class).transformAndAppend(assertionCreator) +/** + * Expects that the subject of `this` expectation *is a* [TSub] (the same type or a sub-type) + * and changes the subject to this type. + * + * Notice, that asserting a function type is [flawed](https://youtrack.jetbrains.com/issue/KT-27846). + * The actual types are ignored as function types erase to Function0, + * Function1 etc. on byte code level, which means the assertion holds as long as the subject is a + * function and has the same amount of arguments regardless if the types differ. For instance + * `expect({x: Int -> "hello"}).toBeA Unit>{}` holds, even though `(Int) -> String` is clearly not + * a `(String) -> Unit`. + * + * More generally speaking, the [flaw](https://youtrack.jetbrains.com/issue/KT-27826) applies to all generic types. + * For instance `toBeA>` would only check if the subject is a `List` without checking if + * the element type is actually `String`. Or in other words + * `expect(listOf(1, 2)).toBeA>{}` holds, even though `List` is clearly not a `List`. + * + * @return An [Expect] with the new type [TSub]. + * + * @since 0.17.0 + * + * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.AnyExpectationSamples.toBeAFeature + */ +inline fun Expect<*>.toBeA(): Expect = toBeA(TSub::class).transform() + +@PublishedApi // in order that _logic does not become part of the API we have this extra function +internal fun Expect<*>.toBeA(kClass: KClass): SubjectChangerBuilder.ExecutionStep = + _logic.isA(kClass) + +/** + * Expects that the subject of `this` expectation *is a* [TSub] (the same type or a sub-type) and + * that it holds all assertions the given [assertionCreator] creates. + * + * Notice, in contrast to other assertion functions which expect an [assertionCreator], this function returns not + * [Expect] of the initial type, which was some type `T `, but an [Expect] of the specified type [TSub]. + * This has the side effect that a subsequent call has only assertion functions available which are suited for [TSub]. + * Since [Expect] is invariant it especially means that an assertion function which was not written in a generic way + * will not be available. Fixing such a function is easy (in most cases), + * you need to transform it into a generic from. Following an example: + * + * ``` + * interface Person + * class Student: Person + * fun Expect.foo() = "dummy" // limited only to Person, not recommended + * fun Expect.bar() = "dummy" // available to Person and all subtypes, the way to go + * fun Expect.baz() = "dummy" // specific only for Student, ok since closed class + * + * val p: Person = Student() + * expect(p) // subject of type Person + * .toBeA { ... } // subject now refined to Student + * .baz() // available via Student + * .foo() // not available to Student, only to Person, results in compilation error + * .bar() // available via T : Person + * ``` + * + * Notice, that asserting a function type is [flawed](https://youtrack.jetbrains.com/issue/KT-27846). + * The actual types are ignored as function types erase to Function0, + * Function1 etc. on byte code level, which means the assertion holds as long as the subject is a + * function and has the same amount of arguments regardless if the types differ. For instance + * `expect({x: Int -> "hello"}).toBeA Unit>{}` holds, even though `(Int) -> String` is clearly not + * a `(String) -> Unit`. + * + * More generally speaking, the [flaw](https://youtrack.jetbrains.com/issue/KT-27826) applies to all generic types. + * For instance `toBeA>` would only check if the subject is a `List` without checking if + * the element type is actually `String`. Or in other words + * `expect(listOf(1, 2)).toBeA>{}` holds, even though `List` is clearly not a `List`. + * + * @return An [Expect] with the new type [TSub]. + * + * @since 0.17.0 + * + * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.AnyExpectationSamples.toBeA + */ +inline fun Expect<*>.toBeA(noinline assertionCreator: Expect.() -> Unit): Expect = + toBeA(TSub::class).transformAndAppend(assertionCreator) + + +/** + * Expects that the subject of `this` expectation is not (equal to) [expected] and [otherValues]. + * + * @return an [Expect] for the subject of `this` expectation. + * + * @since 0.17.0 + * + * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.AnyExpectationSamples.notToEqualOneOf + */ +fun Expect.notToEqualOneOf(expected: T, vararg otherValues: T): Expect = + _logicAppend { isNotIn(expected glue otherValues) } + +/** + * Expects that the subject of `this` expectation is not (equal to) any value of [expected]. + * + * Notice that a runtime check applies which assures that only [Iterable], [Sequence] or one of the [Array] types + * are passed. This function expects [IterableLike] (which is a typealias for [Any]) to avoid cluttering the API. + * + * @return an [Expect] for the subject of `this` expectation. + * @throws IllegalArgumentException in case the iterable is empty. + * + * @since 0.17.0 + * + * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.AnyExpectationSamples.notToEqualOneIn + */ +fun Expect.notToEqualOneIn(expected: IterableLike): Expect = + _logicAppend { isNotIn(iterableLikeToIterable(expected)) } + + diff --git a/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/AnyExpectationsSpec.kt b/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/AnyExpectationsSpec.kt index 6ac8f4e8d..76cb27b66 100644 --- a/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/AnyExpectationsSpec.kt +++ b/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/AnyExpectationsSpec.kt @@ -10,81 +10,81 @@ import kotlin.reflect.KFunction2 import kotlin.reflect.KProperty1 class AnyExpectationsSpec : ch.tutteli.atrium.specs.integration.AnyExpectationsSpec( - fun1(Expect::toBe), - fun1(Expect::toBe), - fun1(Expect::toBe).withNullableSuffix(), - fun1(Expect::toBe).withNullableSuffix(), - fun1(Expect::notToBe), - fun1(Expect::notToBe), - fun1(Expect::notToBe).withNullableSuffix(), - fun1(Expect::notToBe).withNullableSuffix(), - fun1(Expect::isSameAs), - fun1(Expect::isSameAs), - fun1(Expect::isSameAs).withNullableSuffix(), - fun1(Expect::isSameAs).withNullableSuffix(), - fun1(Expect::isNotSameAs), - fun1(Expect::isNotSameAs), - fun1(Expect::isNotSameAs).withNullableSuffix(), - fun1(Expect::isNotSameAs).withNullableSuffix(), - fun2(Expect::isNoneOf), - fun2(Expect::isNoneOf), - fun2(Expect::isNoneOf).withNullableSuffix(), - fun2(Expect::isNoneOf).withNullableSuffix(), - fun1(Expect::isNotIn), - fun1(Expect::isNotIn), - fun1(Expect::isNotIn).withNullableSuffix(), - fun1(Expect::isNotIn).withNullableSuffix(), + fun1(Expect::toEqual), + fun1(Expect::toEqual), + fun1(Expect::toEqual).withNullableSuffix(), + fun1(Expect::toEqual).withNullableSuffix(), + fun1(Expect::notToEqual), + fun1(Expect::notToEqual), + fun1(Expect::notToEqual).withNullableSuffix(), + fun1(Expect::notToEqual).withNullableSuffix(), + fun1(Expect::toBeTheInstance), + fun1(Expect::toBeTheInstance), + fun1(Expect::toBeTheInstance).withNullableSuffix(), + fun1(Expect::toBeTheInstance).withNullableSuffix(), + fun1(Expect::notToBeTheInstance), + fun1(Expect::notToBeTheInstance), + fun1(Expect::notToBeTheInstance).withNullableSuffix(), + fun1(Expect::notToBeTheInstance).withNullableSuffix(), + fun2(Expect::notToEqualOneOf), + fun2(Expect::notToEqualOneOf), + fun2(Expect::notToEqualOneOf).withNullableSuffix(), + fun2(Expect::notToEqualOneOf).withNullableSuffix(), + fun1(Expect::notToEqualOneIn), + fun1(Expect::notToEqualOneIn), + fun1(Expect::notToEqualOneIn).withNullableSuffix(), + fun1(Expect::notToEqualOneIn).withNullableSuffix(), fun2(Expect::because), fun2(Expect::because), - "${Expect::toBe.name}(null)" to Companion::toBeNull, - fun1(Expect::toBeNullIfNullGivenElse), - ("isA" to Companion::isAIntFeature).withFeatureSuffix(), - "isA" to Companion::isAInt, - ("isA" to Companion::isASuperTypeFeature).withFeatureSuffix(), - "isA" to Companion::isASuperType, - ("isA" to Companion::isASubTypeFeature).withFeatureSuffix(), - "isA" to Companion::isASubType, + "${Expect::toEqual.name}(null)" to Companion::toEqualNull, + fun1(Expect::toEqualNullIfNullGivenElse), + ("toBeA" to Companion::toBeAIntFeature).withFeatureSuffix(), + "toBeA" to Companion::toBeAInt, + ("toBeA" to Companion::toBeASuperTypeFeature).withFeatureSuffix(), + "toBeA" to Companion::toBeASuperType, + ("toBeA" to Companion::toBeASubTypeFeature).withFeatureSuffix(), + "toBeA" to Companion::toBeASubType, - feature0(Expect::notToBeNull), - "notToBeNull" to Companion::notToBeNull, + feature0(Expect::notToEqualNull), + "notToEqualNull" to Companion::notToEqualNull, getAndImmediatePair(), getAndLazyPair() ) { companion object { - private fun toBeNull(expect: Expect) = expect.toBe(null) + private fun toEqualNull(expect: Expect) = expect.toEqual(null) @Suppress("RemoveExplicitTypeArguments") - private fun isAIntFeature(expect: Expect): Expect = - expect.isA() + private fun toBeAIntFeature(expect: Expect): Expect = + expect.toBeA() @Suppress("RemoveExplicitTypeArguments") - private fun isAInt(expect: Expect, assertionCreator: Expect.() -> Unit): Expect = - expect.isA { assertionCreator() } + private fun toBeAInt(expect: Expect, assertionCreator: Expect.() -> Unit): Expect = + expect.toBeA { assertionCreator() } @Suppress("RemoveExplicitTypeArguments") - private fun isASuperTypeFeature(expect: Expect): Expect = - expect.isA() + private fun toBeASuperTypeFeature(expect: Expect): Expect = + expect.toBeA() @Suppress("RemoveExplicitTypeArguments") - private fun isASuperType( + private fun toBeASuperType( expect: Expect, assertionCreator: Expect.() -> Unit ): Expect = - expect.isA { assertionCreator() } + expect.toBeA { assertionCreator() } @Suppress("RemoveExplicitTypeArguments") - private fun isASubTypeFeature(expect: Expect): Expect = - expect.isA() + private fun toBeASubTypeFeature(expect: Expect): Expect = + expect.toBeA() @Suppress("RemoveExplicitTypeArguments") - private fun isASubType( + private fun toBeASubType( expect: Expect, assertionCreator: Expect.() -> Unit ): Expect = - expect.isA { assertionCreator() } + expect.toBeA { assertionCreator() } private val andImmediate: KProperty1, Expect> = Expect::and fun getAndImmediatePair(): Pair.() -> Expect> = andImmediate.name to Expect::and @@ -93,14 +93,11 @@ class AnyExpectationsSpec : ch.tutteli.atrium.specs.integration.AnyExpectationsS fun getAndLazyPair(): Pair.(Expect.() -> Unit) -> Expect> = andLazyName.name to Expect::and - private fun notToBeNullFeature(expect: Expect) = - expect.notToBeNull() - - private fun notToBeNull(expect: Expect, assertionCreator: Expect.() -> Unit) = - expect.notToBeNull(assertionCreator) + private fun notToEqualNull(expect: Expect, assertionCreator: Expect.() -> Unit) = + expect.notToEqualNull(assertionCreator) } //regression for #298, should compile without the need for E : Any or List @Suppress("unused") - fun Expect>.firstIs(value: E) = get(0) { toBe(value) } + fun Expect>.firstIs(value: E) = get(0) { toEqual(value) } } diff --git a/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/samples/AnyExpectationSamples.kt b/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/samples/AnyExpectationSamples.kt new file mode 100644 index 000000000..62ae8a46b --- /dev/null +++ b/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/samples/AnyExpectationSamples.kt @@ -0,0 +1,221 @@ +package ch.tutteli.atrium.api.fluent.en_GB.samples + +import ch.tutteli.atrium.api.fluent.en_GB.* +import ch.tutteli.atrium.api.verbs.internal.expect +import kotlin.test.Test + +class AnyExpectationSamples { + + @Test + fun toEqual() { + expect(12).toEqual(12) // holds + + fails { + expect(12).toEqual(11) + } + + // holds, toEqual is based on equality, use toBeTheInstance for identity + expect(listOf(1)).toEqual(listOf(1)) + + fails { // because array has not implemented equals, so is the same as using toBeTheInstance + expect(arrayOf(1)).toEqual(arrayOf(1)) + } + } + + @Test + fun notToEqual() { + expect(2).notToEqual(3) + + fails { + expect(12).notToEqual(12) + } + + expect(listOf(2)).notToEqual(listOf(3)) + + fails { + expect(listOf(2)).notToEqual(listOf(2)) + } + } + + @Test + fun toBeTheInstance() { + val list = listOf(3) + expect(list).toBeTheInstance(list) + + fails { + // fails because toBeTheInstance is based on identity, use toEqual for equality + expect(listOf(3)).toBeTheInstance(listOf(3)) + } + } + + @Test + fun notToBeTheInstance() { + // holds because notToBeTheInstance is based on identity, use noToEqual for equality + expect(listOf(2)).notToBeTheInstance(listOf(2)) + + fails { + val list = listOf(3) + expect(list).notToBeTheInstance(list) + } + } + + @Test + fun toEqualNullIfNullGivenElse() { + expect(null).toEqualNullIfNullGivenElse(null) + + expect(1).toEqualNullIfNullGivenElse { + isLessThan(2) + } + + fails { + // sub-expectation fails + expect(1).toEqualNullIfNullGivenElse { + isLessThan(0) + } + } + } + + @Test + fun notToEqualNullFeature() { + expect(1) + .notToEqualNull() // subject is now of type Int + .isLessThan(2) + + fails { + expect(null) + .notToEqualNull() // fails + .isLessThan(2) // not shown in reporting as notToEqualNull already fails + } + } + + @Test + fun notToEqualNull() { + expect(1).notToEqualNull { // subject is now of type Int, within this block but also afterwards + isGreaterThan(0) + isLessThan(10) + }.toEqual(1) + + fails { + // because you forgot to define an expectation in the expectation group block + // use `notToEqualNull()` if this is all you want to assert + expect(1).notToEqualNull { } + } + + + fails { + // notToBeNull already fails, reporting mentions that subject was expected `to equal: 2` + expect(null).notToEqualNull { + isGreaterThan(2) + } + } + + fails { + // sub-expectation fails + expect(1).notToEqualNull { + isLessThan(0) + } + } + } + + @Test + fun toBeAFeature() { + val n: Number = 1 + expect(n) + .toBeA() // subject is now of type Int + .isGreaterThan(0) + + fails { + expect("A") + .toBeA() + .isLessThan(2L) // not shown in reporting as `toBeA()` already fails + + } + } + + @Test + fun toBeA() { + val n: Number = 16 + expect(n).toBeA { // subject is now of type Int, within this block but also afterwards + isGreaterThanOrEqual(15) + }.isLessThan(20) + + fails { + // because wrong type expected (Long instead of String) + expect("A").toBeA { + toEqual(43) + } + } + + fails { + // type fits, but sub-expectation fails + expect(54L).toBeA { + toEqual(-1L) + } + } + } + + @Test + fun andFeature() { + // and is just a filler word; does not have any behaviour + expect(13).isGreaterThan(5).and.isLessThan(20) + + // i.e. the above is equivalent to: + expect(13).isGreaterThan(5).isLessThan(20) + } + + @Test + fun and() { + expect(13).toBeA().and { + isGreaterThan(5) + isLessThan(20) + } + + fails { + expect(13).toBeA().and { + // introduces an expectation group block + // all expectations are evaluated inside an expectation group block; for more details: + // https://github.com/robstoll/atrium#define-single-expectations-or-expectation-groups + // use `.and.` if you want fail fast behaviour + + notToEqualOneOf(1, 2, 13) // fails + isLessThan(10) // still evaluated and included in the error report + } + } + } + + @Test + fun notToEqualOneOf() { + expect(99).notToEqualOneOf(1, 2, 3, 4) + + fails { + expect(1).notToEqualOneOf(1, 2, 3, 4) + } + } + + @Test + fun notToEqualOneIn() { + expect(99).notToEqualOneIn(listOf(1, 2, 3, 4)) + + fails { + expect(1).notToEqualOneIn(listOf(1, 2, 3, 4)) + } + } + + data class Person(val age: Int) + + private val customers = listOf(Person(21)) + + @Test + fun because() { + expect("filename") + .because("? is not allowed in file names on Windows") { + containsNot("?") + } + + expect(customers).all { + because("the legal age of maturity in Switzerland is 18") { + feature { f(it::age) }.isGreaterThanOrEqual(18) + } + } + } +} diff --git a/misc/specs/atrium-specs-common/src/main/kotlin/ch/tutteli/atrium/specs/integration/AnyExpectationsSpec.kt b/misc/specs/atrium-specs-common/src/main/kotlin/ch/tutteli/atrium/specs/integration/AnyExpectationsSpec.kt index b1be200d4..7454486a0 100644 --- a/misc/specs/atrium-specs-common/src/main/kotlin/ch/tutteli/atrium/specs/integration/AnyExpectationsSpec.kt +++ b/misc/specs/atrium-specs-common/src/main/kotlin/ch/tutteli/atrium/specs/integration/AnyExpectationsSpec.kt @@ -18,43 +18,43 @@ import org.spekframework.spek2.Spek import org.spekframework.spek2.style.specification.Suite abstract class AnyExpectationsSpec( - toBeInt: Fun1, - toBeDataClass: Fun1, - toBeNullableInt: Fun1, - toBeNullableDataClass: Fun1, - notToBeInt: Fun1, - notToBeDataClass: Fun1, - notToBeNullableInt: Fun1, - notToBeNullableDataClass: Fun1, - isSameInt: Fun1, - isSameDataClass: Fun1, - isSameNullableInt: Fun1, - isSameNullableDataClass: Fun1, - isNotSameInt: Fun1, - isNotSameDataClass: Fun1, - isNotSameNullableInt: Fun1, - isNotSameNullableDataClass: Fun1, - isNoneOfInt: Fun2>, - isNoneOfDataClass: Fun2>, - isNoneOfNullableInt: Fun2>, - isNoneOfNullableDataClass: Fun2>, - isNotInInt: Fun1>, - isNotInDataClass: Fun1>, - isNotInNullableInt: Fun1>, - isNotInNullableDataClass: Fun1>, + toEqualInt: Fun1, + toEqualDataClass: Fun1, + toEqualNullableInt: Fun1, + toEqualNullableDataClass: Fun1, + notToEqualInt: Fun1, + notToEqualDataClass: Fun1, + notToEqualNullableInt: Fun1, + notToEqualNullableDataClass: Fun1, + toBeTheInstanceInt: Fun1, + toBeTheInstanceDataClass: Fun1, + toBeTheInstanceNullableInt: Fun1, + toBeTheInstanceNullableDataClass: Fun1, + notToBeTheInstanceInt: Fun1, + notToBeTheInstanceDataClass: Fun1, + notToBeTheInstanceNullableInt: Fun1, + notToBeTheInstanceNullableDataClass: Fun1, + notToEqualOneOfInt: Fun2>, + notToEqualOneOfDataClass: Fun2>, + notToEqualOneOfNullableInt: Fun2>, + notToEqualOneOfNullableDataClass: Fun2>, + notToEqualOneInInt: Fun1>, + notToEqualOneInDataClass: Fun1>, + notToBeNullableInt: Fun1>, + notToEqualOneInNullableDataClass: Fun1>, because: Fun2.() -> Unit>, becauseInt: Fun2.() -> Unit>, toBeNull: Fun0, toBeNullIfNullGivenElse: Fun1.() -> Unit)?>, - isAIntFeature: Feature0, - isAInt: Feature1.() -> Unit, Int>, + toBeAIntFeature: Feature0, + toBeAInt: Feature1.() -> Unit, Int>, - isASuperTypeFeature: Feature0, - isASuperType: Feature1.() -> Unit, SuperType>, - isASubTypeFeature: Feature0, - isASubType: Feature1.() -> Unit, SubType>, + toBeASuperTypeFeature: Feature0, + toBeASuperType: Feature1.() -> Unit, SuperType>, + toBeASubTypeFeature: Feature0, + toBeASubType: Feature1.() -> Unit, SubType>, notToBeNullFeature: Feature0, notToBeNull: Feature1.() -> Unit, Int>, @@ -67,27 +67,27 @@ abstract class AnyExpectationsSpec( include(object : SubjectLessSpec( describePrefix, - toBeInt.forSubjectLess(1), - notToBeInt.forSubjectLess(1), - isSameInt.forSubjectLess(1), - isNotSameInt.forSubjectLess(1), - isNoneOfInt.forSubjectLess(1, emptyArray()), - isNotInInt.forSubjectLess(listOf(1)), + toEqualInt.forSubjectLess(1), + notToEqualInt.forSubjectLess(1), + toBeTheInstanceInt.forSubjectLess(1), + notToBeTheInstanceInt.forSubjectLess(1), + notToEqualOneOfInt.forSubjectLess(1, emptyArray()), + notToEqualOneInInt.forSubjectLess(listOf(1)), andPair.forSubjectLess(), andLazyPair.forSubjectLess { toBe(1) } ) {}) include(object : SubjectLessSpec( "$describePrefix[nullable] ", - toBeNullableInt.forSubjectLess(1), - notToBeNullableInt.forSubjectLess(1), - isSameNullableInt.forSubjectLess(1), - isNotSameNullableInt.forSubjectLess(1), - isNoneOfNullableInt.forSubjectLess(1, emptyArray()), - isNotInNullableInt.forSubjectLess(listOf(1)), + toEqualNullableInt.forSubjectLess(1), + notToEqualNullableInt.forSubjectLess(1), + toBeTheInstanceNullableInt.forSubjectLess(1), + notToBeTheInstanceNullableInt.forSubjectLess(1), + notToEqualOneOfNullableInt.forSubjectLess(1, emptyArray()), + notToBeNullableInt.forSubjectLess(listOf(1)), toBeNull.forSubjectLess(), - isAIntFeature.forSubjectLess(), - isAInt.forSubjectLess { toBe(1) }, + toBeAIntFeature.forSubjectLess(), + toBeAInt.forSubjectLess { toBe(1) }, notToBeNullFeature.forSubjectLess(), notToBeNull.forSubjectLess { toBe(1) } ) {}) @@ -100,10 +100,10 @@ abstract class AnyExpectationsSpec( "$describePrefix[nullable Element] ", 1, toBeNullIfNullGivenElse.forAssertionCreatorSpec("$toBeDescr: 1") { toBe(1) }, assertionCreatorSpecTriple( - isAInt.name, + toBeAInt.name, "$toBeDescr: 1", - { apply { isAInt.invoke(this) { toBe(1) } } }, - { apply { isAInt.invoke(this) {} } }), + { apply { toBeAInt.invoke(this) { toBe(1) } } }, + { apply { toBeAInt.invoke(this) {} } }), assertionCreatorSpecTriple( notToBeNull.name, "$toBeDescr: 1", @@ -123,61 +123,61 @@ abstract class AnyExpectationsSpec( fun Suite.checkInt( description: String, expectSubject: Expect, - toBe: Fun1, - notToBe: Fun1, - isSame: Fun1, - isNotSame: Fun1, - isNoneOf: Fun2>, - isNotIn: Fun1> + toEqual: Fun1, + notToEqual: Fun1, + toBeTheInstance: Fun1, + notToBeTheInstance: Fun1, + notToEqualOneOf: Fun2>, + notToEqualOneIn: Fun1> ) { context(description) { - val toBeFun = toBe.lambda - val notToBeFun = notToBe.lambda - val isSameFun = isSame.lambda - val isNotSameFun = isNotSame.lambda - val isNoneOfFun = isNoneOf.lambda - val isNotInFun = isNotIn.lambda + val toEqualFun = toEqual.lambda + val notToEqualFun = notToEqual.lambda + val toBeTheInstanceFun = toBeTheInstance.lambda + val notToBeTheInstanceFun = notToBeTheInstance.lambda + val notToEqualOneOfFun = notToEqualOneOf.lambda + val notToEqualOneInFun = notToEqualOneIn.lambda context("one equals the other") { - it("${toBe.name} does not throw") { - expectSubject.toBeFun(1) + it("${toEqual.name} does not throw") { + expectSubject.toEqualFun(1) } - it("${isSame.name} does not throw") { - expectSubject.isSameFun(1) + it("${toBeTheInstance.name} does not throw") { + expectSubject.toBeTheInstanceFun(1) } - it("${notToBe.name} throws AssertionError") { + it("${notToEqual.name} throws AssertionError") { expect { - expectSubject.notToBeFun(1) + expectSubject.notToEqualFun(1) }.toThrow { messageContains(NOT_TO_BE.getDefault()) } } - it("${isNotSame.name} throws AssertionError") { + it("${notToBeTheInstance.name} throws AssertionError") { expect { - expectSubject.isNotSameFun(1) + expectSubject.notToBeTheInstanceFun(1) }.toThrow { messageContains(IS_NOT_SAME.getDefault()) } } } context("one does not equal the other") { - it("${toBe.name} throws AssertionError") { + it("${toEqual.name} throws AssertionError") { expect { - expectSubject.toBeFun(2) + expectSubject.toEqualFun(2) }.toThrow { messageContains(TO_BE.getDefault()) } } - it("${notToBe.name} does not throw") { - expectSubject.notToBeFun(2) + it("${notToEqual.name} does not throw") { + expectSubject.notToEqualFun(2) } - it("${isSame.name} throws AssertionError") { + it("${toBeTheInstance.name} throws AssertionError") { expect { - expectSubject.isSameFun(2) + expectSubject.toBeTheInstanceFun(2) }.toThrow { messageContains(IS_SAME.getDefault()) } } - it("${isNotSame.name} does not throw") { - expectSubject.isNotSameFun(2) + it("${notToBeTheInstance.name} does not throw") { + expectSubject.notToBeTheInstanceFun(2) } } context("one equals only one of the others") { - it("${isNoneOf.name} throws AssertionError") { + it("${notToEqualOneOf.name} throws AssertionError") { expect { - expectSubject.isNoneOfFun(1, arrayOf(2)) + expectSubject.notToEqualOneOfFun(1, arrayOf(2)) }.toThrow { message { containsRegex( @@ -188,9 +188,9 @@ abstract class AnyExpectationsSpec( } } } - it("${isNotIn.name} throws AssertionError") { + it("${notToEqualOneIn.name} throws AssertionError") { expect { - expectSubject.isNotInFun(listOf(1, 2)) + expectSubject.notToEqualOneInFun(listOf(1, 2)) }.toThrow { message { contains(IS_NONE_OF.getDefault(), "${listBulletPoint}1") @@ -200,11 +200,11 @@ abstract class AnyExpectationsSpec( } } context("one does not equal to any of the others") { - it("${isNoneOf.name} does not throw") { - expectSubject.isNoneOfFun(2, arrayOf(3)) + it("${notToEqualOneOf.name} does not throw") { + expectSubject.notToEqualOneOfFun(2, arrayOf(3)) } - it("${isNotIn.name} does not throw") { - expectSubject.isNotInFun(listOf(2, 3)) + it("${notToEqualOneIn.name} does not throw") { + expectSubject.notToEqualOneInFun(listOf(2, 3)) } } } @@ -213,102 +213,102 @@ abstract class AnyExpectationsSpec( fun Suite.checkDataClass( description: String, expectSubject: Expect, - toBe: Fun1, - notToBe: Fun1, - isSame: Fun1, - isNotSame: Fun1, - isNoneOf: Fun2>, - isNotIn: Fun1>, + toEqual: Fun1, + notToEqual: Fun1, + toBeTheInstance: Fun1, + notToBeTheInstance: Fun1, + notToEqualOneOf: Fun2>, + notToEqualOneIn: Fun1>, test: DataClass ) { - val toBeFun = toBe.lambda - val notToBeFun = notToBe.lambda - val isSameFun = isSame.lambda - val isNotSameFun = isNotSame.lambda - val isNoneOfFun = isNoneOf.lambda - val isNotInFun = isNotIn.lambda + val toEqualFun = toEqual.lambda + val notToEqualFun = notToEqual.lambda + val toBeTheInstanceFun = toBeTheInstance.lambda + val notToBeTheInstanceFun = notToBeTheInstance.lambda + val notToEqualOneOfFun = notToEqualOneOf.lambda + val notToEqualOneInFun = notToEqualOneIn.lambda context(description) { context("same") { - it("${toBe.name} does not throw") { - expectSubject.toBeFun(test) + it("${toEqual.name} does not throw") { + expectSubject.toEqualFun(test) } - it("${notToBe.name} throws AssertionError") { + it("${notToEqual.name} throws AssertionError") { expect { - expectSubject.notToBeFun(test) + expectSubject.notToEqualFun(test) }.toThrow() } - it("${isSame.name} does not throw") { - expectSubject.isSameFun(test) + it("${toBeTheInstance.name} does not throw") { + expectSubject.toBeTheInstanceFun(test) } - it("${isNotSame.name} throws AssertionError") { + it("${notToBeTheInstance.name} throws AssertionError") { expect { - expectSubject.isNotSameFun(test) + expectSubject.notToBeTheInstanceFun(test) }.toThrow() } - it("${isNoneOf.name} throws AssertionError") { + it("${notToEqualOneOf.name} throws AssertionError") { expect { - expectSubject.isNoneOfFun(test, emptyArray()) + expectSubject.notToEqualOneOfFun(test, emptyArray()) }.toThrow { messageContains(IS_NONE_OF.getDefault()) } } - it("${isNotIn.name} throws AssertionError") { + it("${notToEqualOneIn.name} throws AssertionError") { expect { - expectSubject.isNotInFun(listOf(test)) + expectSubject.notToEqualOneInFun(listOf(test)) }.toThrow { messageContains(IS_NONE_OF.getDefault()) } } } context("not same but one equals the other") { val other = DataClass(true) - it("${toBe.name} does not throw") { - expectSubject.toBeFun(other) + it("${toEqual.name} does not throw") { + expectSubject.toEqualFun(other) } - it("${notToBe.name} throws AssertionError") { + it("${notToEqual.name} throws AssertionError") { expect { - expectSubject.notToBeFun(other) + expectSubject.notToEqualFun(other) }.toThrow() } - it("${isSame.name} throws AssertionError") { + it("${toBeTheInstance.name} throws AssertionError") { expect { - expectSubject.isSameFun(other) + expectSubject.toBeTheInstanceFun(other) }.toThrow() } - it("${isNotSame.name} does not throw") { - expectSubject.isNotSameFun(other) + it("${notToBeTheInstance.name} does not throw") { + expectSubject.notToBeTheInstanceFun(other) } - it("${isNoneOf.name} throws AssertionError") { + it("${notToEqualOneOf.name} throws AssertionError") { expect { - expectSubject.isNoneOfFun(other, emptyArray()) + expectSubject.notToEqualOneOfFun(other, emptyArray()) }.toThrow { messageContains(IS_NONE_OF.getDefault()) } } - it("${isNotIn.name} throws AssertionError") { + it("${notToEqualOneIn.name} throws AssertionError") { expect { - expectSubject.isNotInFun(listOf(other)) + expectSubject.notToEqualOneInFun(listOf(other)) }.toThrow { messageContains(IS_NONE_OF.getDefault()) } } } context("one does not equal the other") { val other = DataClass(false) - it("${toBe.name} does not throw") { + it("${toEqual.name} does not throw") { expect { - expectSubject.toBeFun(other) + expectSubject.toEqualFun(other) }.toThrow() } - it("${notToBe.name} throws AssertionError") { - expectSubject.notToBeFun(other) + it("${notToEqual.name} throws AssertionError") { + expectSubject.notToEqualFun(other) } - it("${isSame.name} throws AssertionError") { + it("${toBeTheInstance.name} throws AssertionError") { expect { - expectSubject.isSameFun(other) + expectSubject.toBeTheInstanceFun(other) }.toThrow() } - it("${isNotSame.name} does not throw") { - expectSubject.isNotSameFun(other) + it("${notToBeTheInstance.name} does not throw") { + expectSubject.notToBeTheInstanceFun(other) } - it("${isNoneOf.name} does not throw") { - expectSubject.isNoneOfFun(other, emptyArray()) + it("${notToEqualOneOf.name} does not throw") { + expectSubject.notToEqualOneOfFun(other, emptyArray()) } - it("${isNotIn.name} does not throw") { - expectSubject.isNotInFun(listOf(other)) + it("${notToEqualOneIn.name} does not throw") { + expectSubject.notToEqualOneInFun(listOf(other)) } } } @@ -316,138 +316,138 @@ abstract class AnyExpectationsSpec( fun Suite.checkNull( description: String, - toBe: Fun1, - notToBe: Fun1, - isSame: Fun1, - isNotSame: Fun1, - isNoneOf: Fun2>, - isNotIn: Fun1>, + toEqual: Fun1, + notToEqual: Fun1, + toBeTheInstance: Fun1, + notToBeTheInstance: Fun1, + notToEqualOneOf: Fun2>, + notToEqualOneIn: Fun1>, value: T, emptyArray: Array ) { - val toBeFun = toBe.lambda - val notToBeFun = notToBe.lambda - val isSameFun = isSame.lambda - val isNotSameFun = isNotSame.lambda - val isNoneOfFun = isNoneOf.lambda - val isNotInFun = isNotIn.lambda + val toEqualFun = toEqual.lambda + val notToEqualFun = notToEqual.lambda + val toBeTheInstanceFun = toBeTheInstance.lambda + val notToBeTheInstanceFun = notToBeTheInstance.lambda + val notToEqualOneOfFun = notToEqualOneOf.lambda + val notToEqualOneInFun = notToEqualOneIn.lambda val expectSubject = expect(null as T?) context(description) { context("one equals the other") { - it("${toBe.name} does not throw") { - expectSubject.toBeFun(null) + it("${toEqual.name} does not throw") { + expectSubject.toEqualFun(null) } - it("${isSame.name} does not throw") { - expectSubject.isSameFun(null) + it("${toBeTheInstance.name} does not throw") { + expectSubject.toBeTheInstanceFun(null) } - it("${notToBe.name} throws AssertionError") { + it("${notToEqual.name} throws AssertionError") { expect { - expectSubject.notToBeFun(null) + expectSubject.notToEqualFun(null) }.toThrow { messageContains(NOT_TO_BE.getDefault()) } } - it("${isNotSame.name} throws AssertionError") { + it("${notToBeTheInstance.name} throws AssertionError") { expect { - expectSubject.isNotSameFun(null) + expectSubject.notToBeTheInstanceFun(null) }.toThrow { messageContains(IS_NOT_SAME.getDefault()) } } - it("${isNoneOf.name} throws AssertionError") { + it("${notToEqualOneOf.name} throws AssertionError") { expect { - expectSubject.isNoneOfFun(null, emptyArray) + expectSubject.notToEqualOneOfFun(null, emptyArray) }.toThrow { messageContains(IS_NONE_OF.getDefault()) } } - it("${isNotIn.name} throws AssertionError") { + it("${notToEqualOneIn.name} throws AssertionError") { expect { - expectSubject.isNotInFun(listOf(null)) + expectSubject.notToEqualOneInFun(listOf(null)) }.toThrow { messageContains(IS_NONE_OF.getDefault()) } } } context("one does not equal the other") { - it("${toBe.name} throws AssertionError") { + it("${toEqual.name} throws AssertionError") { expect { - expect(null as T?).toBeFun(value) + expect(null as T?).toEqualFun(value) }.toThrow { messageContains(TO_BE.getDefault()) } } - it("${notToBe.name} does not throw") { - expectSubject.notToBeFun(value) + it("${notToEqual.name} does not throw") { + expectSubject.notToEqualFun(value) } - it("${isSame.name} throws AssertionError") { + it("${toBeTheInstance.name} throws AssertionError") { expect { - expectSubject.isSameFun(value) + expectSubject.toBeTheInstanceFun(value) }.toThrow { messageContains(IS_SAME.getDefault()) } } - it("${isNotSame.name} does not throw") { - expectSubject.isNotSameFun(value) + it("${notToBeTheInstance.name} does not throw") { + expectSubject.notToBeTheInstanceFun(value) } - it("${isNoneOf.name} does not throw") { - expectSubject.isNoneOfFun(value, emptyArray) + it("${notToEqualOneOf.name} does not throw") { + expectSubject.notToEqualOneOfFun(value, emptyArray) } - it("${isNotIn.name} does not throw") { - expectSubject.isNotInFun(listOf(value)) + it("${notToEqualOneIn.name} does not throw") { + expectSubject.notToEqualOneInFun(listOf(value)) } } } } - describeFun(toBeInt, notToBeInt, isSameInt, isNotSameInt, isNoneOfInt, isNotInInt) { - checkInt("primitive", expect(1), toBeInt, notToBeInt, isSameInt, isNotSameInt, isNoneOfInt, isNotInInt) + describeFun(toEqualInt, notToEqualInt, toBeTheInstanceInt, notToBeTheInstanceInt, notToEqualOneOfInt, notToEqualOneInInt) { + checkInt("primitive", expect(1), toEqualInt, notToEqualInt, toBeTheInstanceInt, notToBeTheInstanceInt, notToEqualOneOfInt, notToEqualOneInInt) checkInt( "nullable primitive", expect(1 as Int?), - toBeNullableInt, - notToBeNullableInt, - isSameNullableInt, - isNotSameNullableInt, - isNoneOfNullableInt, - isNotInNullableInt + toEqualNullableInt, + notToEqualNullableInt, + toBeTheInstanceNullableInt, + notToBeTheInstanceNullableInt, + notToEqualOneOfNullableInt, + notToBeNullableInt ) val subject = DataClass(true) checkDataClass( "class", expect(subject), - toBeDataClass, - notToBeDataClass, - isSameDataClass, - isNotSameDataClass, - isNoneOfDataClass, - isNotInDataClass, + toEqualDataClass, + notToEqualDataClass, + toBeTheInstanceDataClass, + notToBeTheInstanceDataClass, + notToEqualOneOfDataClass, + notToEqualOneInDataClass, subject ) checkDataClass( "nullable class", expect(subject as DataClass?), - toBeNullableDataClass, - notToBeNullableDataClass, - isSameNullableDataClass, - isNotSameNullableDataClass, - isNoneOfNullableDataClass, - isNotInNullableDataClass, + toEqualNullableDataClass, + notToEqualNullableDataClass, + toBeTheInstanceNullableDataClass, + notToBeTheInstanceNullableDataClass, + notToEqualOneOfNullableDataClass, + notToEqualOneInNullableDataClass, subject ) checkNull( "null as Int?", - toBeNullableInt, + toEqualNullableInt, + notToEqualNullableInt, + toBeTheInstanceNullableInt, + notToBeTheInstanceNullableInt, + notToEqualOneOfNullableInt, notToBeNullableInt, - isSameNullableInt, - isNotSameNullableInt, - isNoneOfNullableInt, - isNotInNullableInt, 2, emptyArray() ) checkNull( "null as DataClass?", - toBeNullableDataClass, - notToBeNullableDataClass, - isSameNullableDataClass, - isNotSameNullableDataClass, - isNoneOfNullableDataClass, - isNotInNullableDataClass, + toEqualNullableDataClass, + notToEqualNullableDataClass, + toBeTheInstanceNullableDataClass, + notToBeTheInstanceNullableDataClass, + notToEqualOneOfNullableDataClass, + notToEqualOneInNullableDataClass, subject, emptyArray() ) @@ -485,17 +485,17 @@ abstract class AnyExpectationsSpec( } } - describeFun(toBeNullableInt) { - val toBeNullableFun = toBeNullableInt.lambda + describeFun(toEqualNullableInt) { + val toEqualFun = toEqualNullableInt.lambda context("subject is null") { val subject: Int? = null it("does not throw if null is passed") { - expect(subject).toBeNullableFun(null) + expect(subject).toEqualFun(null) } it("throws an AssertionError if not null is passed") { expect { - expect(subject).toBeNullableFun(1) + expect(subject).toEqualFun(1) }.toThrow { messageContains(": null", "${TO_BE.getDefault()}: 1") } @@ -505,18 +505,18 @@ abstract class AnyExpectationsSpec( context("subject is not null") { val subject: Int? = 1 it("does not throw if expected is subject") { - expect(subject).toBeNullableFun(subject) + expect(subject).toEqualFun(subject) } it("throws an AssertionError if null is passed") { expect { - expect(subject).toBeNullableFun(null) + expect(subject).toEqualFun(null) }.toThrow { messageContains(": 1", "${TO_BE.getDefault()}: null") } } it("throws an AssertionError if expected does not equal subject") { expect { - expect(subject).toBeNullableFun(2) + expect(subject).toEqualFun(2) }.toThrow { messageContains(": 1", "${TO_BE.getDefault()}: 2") } @@ -661,14 +661,14 @@ abstract class AnyExpectationsSpec( } } - describeFun(isAIntFeature, isAInt) { - val isAIntFunctions = unifySignatures(isAIntFeature, isAInt) + describeFun(toBeAIntFeature, toBeAInt) { + val toBeAIntFunctions = unifySignatures(toBeAIntFeature, toBeAInt) context("subject is not in type hierarchy") { - isAIntFunctions.forEach { (name, isAInt, hasExtraHint) -> + toBeAIntFunctions.forEach { (name, toBeAInt, hasExtraHint) -> it("$name - throws an AssertionError" + showsSubAssertionIf(hasExtraHint)) { expect { - expect("hello" as Any?).isAInt { toBe(1) } + expect("hello" as Any?).toBeAInt { toBe(1) } }.toThrow { messageContains(IS_A.getDefault() + ": Int (kotlin.Int)") if (hasExtraHint) messageContains(TO_BE.getDefault() + ": 1") @@ -680,16 +680,16 @@ abstract class AnyExpectationsSpec( context("subject is the same type") { context("it allows to perform sub assertions") { - isAIntFunctions.forEach { (name, isAInt, _) -> + toBeAIntFunctions.forEach { (name, toBeAInt, _) -> it("$name - does not throw if it holds") { - expect(1 as Any?).isAInt { isLessThan(2) } + expect(1 as Any?).toBeAInt { isLessThan(2) } } val expectedLessThan = 2 val actualValue: Any? = 5 it("$name - throws if it does not hold") { expect { - expect(actualValue).isAInt { isLessThan(expectedLessThan) } + expect(actualValue).toBeAInt { isLessThan(expectedLessThan) } }.toThrow { messageContains(actualValue as Any, IS_LESS_THAN.getDefault(), expectedLessThan) } @@ -699,20 +699,20 @@ abstract class AnyExpectationsSpec( } context("subject is a subtype") { - val isASuperTypeFunctions = unifySignatures(isASuperTypeFeature, isASuperType) + val toBeASuperTypeFunctions = unifySignatures(toBeASuperTypeFeature, toBeASuperType) context("it allows to perform sub assertions") { - isASuperTypeFunctions.forEach { (name, isASuperType, _) -> + toBeASuperTypeFunctions.forEach { (name, toBeASuperType, _) -> it("$name - does not throw if it holds") { val subject = SubType() - expect(subject as Any?).isASuperType { isSameAs(subject) } + expect(subject as Any?).toBeASuperType { isSameAs(subject) } } it("$name - throws if it does not hold") { val subject = SubType() val otherSubType = SubType() expect { - expect(subject as Any?).isASuperType { isSameAs(otherSubType) } + expect(subject as Any?).toBeASuperType { isSameAs(otherSubType) } }.toThrow { messageContains(subject.toString(), IS_SAME.getDefault(), otherSubType.toString()) } @@ -722,12 +722,12 @@ abstract class AnyExpectationsSpec( } context("subject is a supertype") { - val isASubTypeFunctions = unifySignatures(isASubTypeFeature, isASubType) - isASubTypeFunctions.forEach { (name, isASubType, hasExtraHint) -> + val toBeASubTypeFunctions = unifySignatures(toBeASubTypeFeature, toBeASubType) + toBeASubTypeFunctions.forEach { (name, toBeASubType, hasExtraHint) -> it("$name - throws an AssertionError" + showsSubAssertionIf(hasExtraHint)) { expect { - expect(SuperType() as Any?).isASubType { isSameAs(SubType()) } + expect(SuperType() as Any?).toBeASubType { isSameAs(SubType()) } }.toThrow { messageContains( SuperType::class.fullName,