diff --git a/apis/fluent-en_GB/extensions/kotlin_1_3/atrium-api-fluent-en_GB-kotlin_1_3-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/kotlin_1_3/resultAssertions.kt b/apis/fluent-en_GB/extensions/kotlin_1_3/atrium-api-fluent-en_GB-kotlin_1_3-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/kotlin_1_3/resultAssertions.kt index 24427022c..ab8dea1ef 100644 --- a/apis/fluent-en_GB/extensions/kotlin_1_3/atrium-api-fluent-en_GB-kotlin_1_3-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/kotlin_1_3/resultAssertions.kt +++ b/apis/fluent-en_GB/extensions/kotlin_1_3/atrium-api-fluent-en_GB-kotlin_1_3-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/kotlin_1_3/resultAssertions.kt @@ -13,6 +13,7 @@ import ch.tutteli.atrium.logic.kotlin_1_3.isSuccess * * @since 0.9.0 */ +@Deprecated("Use toBeASuccess; will be removed with 1.0.0 at the latest", ReplaceWith("this.toBeASuccess()")) fun > Expect.isSuccess(): Expect = _logic.isSuccess().transform() @@ -24,6 +25,10 @@ fun > Expect.isSuccess(): Expect = * * @since 0.9.0 */ +@Deprecated( + "Use toBeASuccess; will be removed with 1.0.0 at the latest", + ReplaceWith("this.toBeASuccess(assertionCreator)") +) fun > Expect.isSuccess(assertionCreator: Expect.() -> Unit): Expect = _logic.isSuccess().collectAndAppend(assertionCreator) @@ -35,6 +40,7 @@ fun > Expect.isSuccess(assertionCreator: Expect.() -> Uni * * @since 0.9.0 */ +@Deprecated("Use toBeAFailure; will be removed with 1.0.0 at the latest", ReplaceWith("this.toBeAFailure()")) inline fun Expect>.isFailure(): Expect = _logic.isFailureOfType(TExpected::class).transform() @@ -47,6 +53,10 @@ inline fun Expect>.isFailure(): Ex * * @since 0.9.0 */ +@Deprecated( + "Use toBeAFailure; will be removed with 1.0.0 at the latest", + ReplaceWith("this.toBeAFailure(assertionCreator)") +) inline fun Expect>.isFailure( noinline assertionCreator: Expect.() -> Unit ): Expect = _logic.isFailureOfType(TExpected::class).transformAndAppend(assertionCreator) diff --git a/apis/fluent-en_GB/extensions/kotlin_1_3/atrium-api-fluent-en_GB-kotlin_1_3-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/kotlin_1_3/resultExpectations.kt b/apis/fluent-en_GB/extensions/kotlin_1_3/atrium-api-fluent-en_GB-kotlin_1_3-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/kotlin_1_3/resultExpectations.kt new file mode 100644 index 000000000..a02ed8614 --- /dev/null +++ b/apis/fluent-en_GB/extensions/kotlin_1_3/atrium-api-fluent-en_GB-kotlin_1_3-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/kotlin_1_3/resultExpectations.kt @@ -0,0 +1,52 @@ +package ch.tutteli.atrium.api.fluent.en_GB.kotlin_1_3 + +import ch.tutteli.atrium.creating.Expect +import ch.tutteli.atrium.logic._logic +import ch.tutteli.atrium.logic.kotlin_1_3.isFailureOfType +import ch.tutteli.atrium.logic.kotlin_1_3.isSuccess + +/** + * Expects that the subject of `this` expectation (a [Result]) is a success ([Result.isSuccess]) + * and returns an [Expect] for the inner type [E]. + * + * @return The newly created [Expect] if the given assertion is a success. + * + * @since 0.17.0 + */ +fun > Expect.toBeASuccess(): Expect = + _logic.isSuccess().transform() + +/** + * Expects that the subject of `this` expectation (a [Result]) is a success ([Result.isSuccess]) and + * that it holds all assertions the given [assertionCreator] creates. + * + * @return an [Expect] for the subject of `this` expectation. + * + * @since 0.17.0 + */ +fun > Expect.toBeASuccess(assertionCreator: Expect.() -> Unit): Expect = + _logic.isSuccess().collectAndAppend(assertionCreator) + +/** + * Expects that the subject of `this` expectation (a [Result]) is a failure ([Result.isFailure]) and + * that it encapsulates an exception of type [TExpected]. + * + * @return An [Expect] with the new type [TExpected] + * + * @since 0.17.0 + */ +inline fun Expect>.toBeAFailure(): Expect = + _logic.isFailureOfType(TExpected::class).transform() + +/** + * Expects that the subject of `this` expectation (a [Result]) is a failure ([Result.isFailure]) , + * that it encapsulates an exception of type [TExpected] and + * that the exception holds all assertions the given [assertionCreator] creates. + * + * @return An [Expect] with the new type [TExpected] + * + * @since 0.17.0 + */ +inline fun Expect>.toBeAFailure( + noinline assertionCreator: Expect.() -> Unit +): Expect = _logic.isFailureOfType(TExpected::class).transformAndAppend(assertionCreator) diff --git a/apis/fluent-en_GB/extensions/kotlin_1_3/atrium-api-fluent-en_GB-kotlin_1_3-common/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/kotlin_1_3/ResultExpectationsSpec.kt b/apis/fluent-en_GB/extensions/kotlin_1_3/atrium-api-fluent-en_GB-kotlin_1_3-common/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/kotlin_1_3/ResultExpectationsSpec.kt index b730284f5..43dbe7631 100644 --- a/apis/fluent-en_GB/extensions/kotlin_1_3/atrium-api-fluent-en_GB-kotlin_1_3-common/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/kotlin_1_3/ResultExpectationsSpec.kt +++ b/apis/fluent-en_GB/extensions/kotlin_1_3/atrium-api-fluent-en_GB-kotlin_1_3-common/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/kotlin_1_3/ResultExpectationsSpec.kt @@ -4,20 +4,20 @@ import ch.tutteli.atrium.creating.Expect import ch.tutteli.atrium.specs.* class ResultExpectationsSpec : ch.tutteli.atrium.specs.integration.ResultExpectationsSpec( - feature0, Int>(Expect>::isSuccess), - fun1, Expect.() -> Unit>(Expect>::isSuccess), - feature0, Int?>(Expect>::isSuccess).withNullableSuffix(), - fun1, Expect.() -> Unit>(Expect>::isSuccess).withNullableSuffix(), - ("isFailure" to Companion::isFailureFeature).withFeatureSuffix(), - "isFailure" to Companion::isFailure + feature0, Int>(Expect>::toBeASuccess), + fun1, Expect.() -> Unit>(Expect>::toBeASuccess), + feature0, Int?>(Expect>::toBeASuccess).withNullableSuffix(), + fun1, Expect.() -> Unit>(Expect>::toBeASuccess).withNullableSuffix(), + ("isFailure" to Companion::toBeAFailureFeature).withFeatureSuffix(), + "isFailure" to Companion::toBeAFailure ) { companion object { - private fun isFailureFeature(expect: Expect>) = expect.isFailure() + private fun toBeAFailureFeature(expect: Expect>) = expect.toBeAFailure() - private fun isFailure( + private fun toBeAFailure( expect: Expect>, assertionCreator: Expect.() -> Unit - ) = expect.isFailure { assertionCreator() } + ) = expect.toBeAFailure { assertionCreator() } @Suppress("unused", "UNUSED_VALUE", "UNUSED_VARIABLE") private fun ambiguityTest() { @@ -26,23 +26,23 @@ class ResultExpectationsSpec : ch.tutteli.atrium.specs.integration.ResultExpecta var star: Expect> = notImplemented() - a1.isSuccess() - a1 = a1.isSuccess { } + a1.toBeASuccess() + a1 = a1.toBeASuccess { } - a1.isFailure() - val r1: Expect = a1.isFailure { } + a1.toBeAFailure() + val r1: Expect = a1.toBeAFailure { } - a1b.isSuccess() - a1b = a1b.isSuccess { } + a1b.toBeASuccess() + a1b = a1b.toBeASuccess { } - a1b.isFailure() - val r1b: Expect = a1b.isFailure { } + a1b.toBeAFailure() + val r1b: Expect = a1b.toBeAFailure { } - star.isSuccess() - star = star.isSuccess { } + star.toBeASuccess() + star = star.toBeASuccess { } - star.isFailure() - val r3: Expect = star.isFailure { } + star.toBeAFailure() + val r3: Expect = star.toBeAFailure { } } } } diff --git a/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/helperFunctions.kt b/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/helperFunctions.kt index ff06fed4a..7c0c6dadc 100644 --- a/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/helperFunctions.kt +++ b/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/helperFunctions.kt @@ -56,9 +56,18 @@ fun regexPatterns(pattern: String, vararg otherPatterns: String): RegexPatterns /** * Helper function to create a [SuccessWithCreator] based on the given [assertionCreator]. */ +@Deprecated("Use aSuccess; will be removed with 1.0.0 at the latest", ReplaceWith("aSuccess(assertionCreator)")) fun success(assertionCreator: Expect.() -> Unit): SuccessWithCreator = SuccessWithCreator(assertionCreator) +/** + * Helper function to create a [SuccessWithCreator] based on the given [assertionCreator]. + * + * @since 0.17.0 + */ +fun aSuccess(assertionCreator: Expect.() -> Unit): SuccessWithCreator = + SuccessWithCreator(assertionCreator) + /** * Helper function to create a [Value] based on the given [value]. */ @@ -69,4 +78,3 @@ fun value(value: T): Value = Value(value) * -- allows to express `T, vararg T`. */ fun values(value: T, vararg otherValues: T): Values = Values(value, otherValues) - diff --git a/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/keywords.kt b/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/keywords.kt index 5b0cb6c17..4529ff2d5 100644 --- a/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/keywords.kt +++ b/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/keywords.kt @@ -131,13 +131,25 @@ object present : Keyword object readable : Keyword /** - * Represents the pseudo keyword `success` as in [toEqual] `success. + * Represents the pseudo keyword `success` as in [toEqual] `success`. * It can be used for a parameterless function so that it has one parameter and thus can be used as infix function. * * @since 0.12.0 */ +@Deprecated( + "Use aSuccess; will be removed with 1.0.0 at the latest", + ReplaceWith("aSuccess", "ch.tutteli.atrium.api.infix.en_GB.aSuccess") +) object success : Keyword +/** + * A helper construct to allow expressing expectations about a something being a success. + * It can be used for a parameterless function so that it has one parameter and thus can be used as infix function. + * + * @since 0.17.0 + */ +object aSuccess : Keyword + /** * A helper construct to allow expressing expectations about a path being writable. * It can be used for a parameterless function so that it has one parameter and thus can be used as infix function. @@ -173,4 +185,4 @@ object duplicates : Keyword * * @since 0.17.0 */ -object elements: Keyword +object elements : Keyword diff --git a/apis/infix-en_GB/extensions/kotlin_1_3/atrium-api-infix-en_GB-kotlin_1_3-common/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/kotlin_1_3/resultAssertions.kt b/apis/infix-en_GB/extensions/kotlin_1_3/atrium-api-infix-en_GB-kotlin_1_3-common/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/kotlin_1_3/resultAssertions.kt index beb7d3dd5..f755939ea 100644 --- a/apis/infix-en_GB/extensions/kotlin_1_3/atrium-api-infix-en_GB-kotlin_1_3-common/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/kotlin_1_3/resultAssertions.kt +++ b/apis/infix-en_GB/extensions/kotlin_1_3/atrium-api-infix-en_GB-kotlin_1_3-common/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/kotlin_1_3/resultAssertions.kt @@ -1,7 +1,6 @@ package ch.tutteli.atrium.api.infix.en_GB.kotlin_1_3 import ch.tutteli.atrium.api.infix.en_GB.creating.SuccessWithCreator -import ch.tutteli.atrium.api.infix.en_GB.success import ch.tutteli.atrium.creating.Expect import ch.tutteli.atrium.logic._logic import ch.tutteli.atrium.logic.kotlin_1_3.isFailureOfType @@ -15,14 +14,20 @@ import ch.tutteli.atrium.logic.kotlin_1_3.isSuccess * * @since 0.12.0 */ -infix fun > Expect.toBe(@Suppress("UNUSED_PARAMETER") success: success): Expect = +@Suppress("DEPRECATION") +@Deprecated( + "Use toBe ASuccess; will be removed with 1.0.0 at the latest", + ReplaceWith("this.toBe(aSuccess)", "ch.tutteli.atrium.api.infix.en_GB.aSuccess") +) +infix fun > Expect.toBe(@Suppress("UNUSED_PARAMETER") success: ch.tutteli.atrium.api.infix.en_GB.success): Expect = _logic.isSuccess().transform() +//TODO move to resultExpectations with 0.18.0 /** - * Expects that the subject of `this` expectation (a [Result]]) is a Success and + * Expects that the subject of `this` expectation (a [Result]) is a success ([Result.isSuccess]) and * that it holds all assertions the given [SuccessWithCreator.assertionCreator] creates. * - * Use the function `success { ... }` to create a [SuccessWithCreator]. + * Use the function `aSuccess { ... }` to create a [SuccessWithCreator]. * * @return an [Expect] for the subject of `this` expectation. * @@ -39,6 +44,7 @@ infix fun > Expect.toBe(success: SuccessWithCreator): Exp * * @since 0.12.0 */ +@Deprecated("Use toBeAFailure; will be removed with 1.0.0 at the latest", ReplaceWith("this.toBeAFailure()")) inline fun Expect>.isFailure(): Expect = _logic.isFailureOfType(TExpected::class).transform() @@ -51,6 +57,10 @@ inline fun Expect>.isFailure(): Ex * * @since 0.12.0 */ +@Deprecated( + "Use toBeAFailure; will be removed with 1.0.0 at the latest", + ReplaceWith("this.toBeAFailure(assertionCreator)") +) inline infix fun Expect>.isFailure( noinline assertionCreator: Expect.() -> Unit ): Expect = _logic.isFailureOfType(TExpected::class).transformAndAppend(assertionCreator) diff --git a/apis/infix-en_GB/extensions/kotlin_1_3/atrium-api-infix-en_GB-kotlin_1_3-common/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/kotlin_1_3/resultExpectations.kt b/apis/infix-en_GB/extensions/kotlin_1_3/atrium-api-infix-en_GB-kotlin_1_3-common/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/kotlin_1_3/resultExpectations.kt new file mode 100644 index 000000000..5386d7c08 --- /dev/null +++ b/apis/infix-en_GB/extensions/kotlin_1_3/atrium-api-infix-en_GB-kotlin_1_3-common/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/kotlin_1_3/resultExpectations.kt @@ -0,0 +1,42 @@ +package ch.tutteli.atrium.api.infix.en_GB.kotlin_1_3 + +import ch.tutteli.atrium.api.infix.en_GB.aSuccess +import ch.tutteli.atrium.creating.Expect +import ch.tutteli.atrium.logic._logic +import ch.tutteli.atrium.logic.kotlin_1_3.isFailureOfType +import ch.tutteli.atrium.logic.kotlin_1_3.isSuccess + +/** + * Expects that the subject of `this` expectation (a [Result]) is a success ([Result.isSuccess]) + * and returns an [Expect] for the inner type [E]. + * + * @return The newly created [Expect] if the given assertion is success. + * + * @since 0.17.0 + */ +infix fun > Expect.toBe(@Suppress("UNUSED_PARAMETER") aSuccess: aSuccess): Expect = + _logic.isSuccess().transform() + +/** + * Expects that the subject of `this` expectation (a [Result]) is a failure ([Result.isFailure]) and + * that it encapsulates an exception of type [TExpected]. + * +* @return An [Expect] with the new type [TExpected] + * + * @since 0.17.0 + */ +inline fun Expect>.toBeAFailure(): Expect = + _logic.isFailureOfType(TExpected::class).transform() + +/** + * Expects that the subject of `this` expectation (a [Result]) is a failure ([Result.isFailure]) , + * that it encapsulates an exception of type [TExpected] and + * that the exception holds all assertions the given [assertionCreator] creates. + * + * @return An [Expect] with the new type [TExpected] + * + * @since 0.17.0 + */ +inline infix fun Expect>.toBeAFailure( + noinline assertionCreator: Expect.() -> Unit +): Expect = _logic.isFailureOfType(TExpected::class).transformAndAppend(assertionCreator) diff --git a/apis/infix-en_GB/extensions/kotlin_1_3/atrium-api-infix-en_GB-kotlin_1_3-common/src/test/kotlin/ch/tutteli/atrium/api/infix/en_GB/kotlin_1_3/ResultExpectationsSpec.kt b/apis/infix-en_GB/extensions/kotlin_1_3/atrium-api-infix-en_GB-kotlin_1_3-common/src/test/kotlin/ch/tutteli/atrium/api/infix/en_GB/kotlin_1_3/ResultExpectationsSpec.kt index 95cdac8c9..9182e44e2 100644 --- a/apis/infix-en_GB/extensions/kotlin_1_3/atrium-api-infix-en_GB-kotlin_1_3-common/src/test/kotlin/ch/tutteli/atrium/api/infix/en_GB/kotlin_1_3/ResultExpectationsSpec.kt +++ b/apis/infix-en_GB/extensions/kotlin_1_3/atrium-api-infix-en_GB-kotlin_1_3-common/src/test/kotlin/ch/tutteli/atrium/api/infix/en_GB/kotlin_1_3/ResultExpectationsSpec.kt @@ -1,5 +1,6 @@ package ch.tutteli.atrium.api.infix.en_GB.kotlin_1_3 +import ch.tutteli.atrium.api.infix.en_GB.aSuccess import ch.tutteli.atrium.api.infix.en_GB.success import ch.tutteli.atrium.creating.Expect import ch.tutteli.atrium.specs.integration.ResultExpectationsSpec @@ -8,34 +9,34 @@ import ch.tutteli.atrium.specs.withFeatureSuffix import ch.tutteli.atrium.specs.withNullableSuffix class ResultExpectationsSpec : ResultExpectationsSpec( - ("toBe ${success::class::simpleName}" to (Companion::toBeSuccessFeature)).withFeatureSuffix(), - "toBe ${success::class::simpleName}" to Companion::toBeSuccess, - ("toBe ${success::class::simpleName}" to (Companion::toBeSuccessFeatureNullable)).withFeatureSuffix() + ("toBe ${aSuccess::class::simpleName}" to (Companion::toBeASuccessFeature)).withFeatureSuffix(), + "toBe ${aSuccess::class::simpleName}" to Companion::toBeASuccess, + ("toBe ${aSuccess::class::simpleName}" to (Companion::toBeASuccessFeatureNullable)).withFeatureSuffix() .withNullableSuffix(), - ("toBe ${success::class::simpleName}" to (Companion::toBeSuccessNullable)).withNullableSuffix(), - ("isFailure" to Companion::isFailureFeature).withFeatureSuffix(), - "isFailure" to Companion::isFailure + ("toBe ${aSuccess::class::simpleName}" to (Companion::toBeASuccessNullable)).withNullableSuffix(), + ("toBeAFailure" to Companion::toBeAFailureFeature).withFeatureSuffix(), + "toBeAFailure" to Companion::toBeAFailure ) { companion object { - private fun toBeSuccessFeature(expect: Expect>) = expect toBe success - private fun isFailureFeature(expect: Expect>) = expect.isFailure() + private fun toBeASuccessFeature(expect: Expect>) = expect toBe aSuccess + private fun toBeAFailureFeature(expect: Expect>) = expect.toBeAFailure() - private fun toBeSuccessFeatureNullable(expect: Expect>) = expect toBe success + private fun toBeASuccessFeatureNullable(expect: Expect>) = expect toBe aSuccess - private fun toBeSuccessNullable( + private fun toBeASuccessNullable( expect: Expect>, assertionCreator: Expect.() -> Unit - ) = expect toBe success { assertionCreator() } + ) = expect toBe aSuccess { assertionCreator() } - private fun toBeSuccess( + private fun toBeASuccess( expect: Expect>, assertionCreator: Expect.() -> Unit - ) = expect toBe success { assertionCreator() } + ) = expect toBe aSuccess { assertionCreator() } - private fun isFailure( + private fun toBeAFailure( expect: Expect>, assertionCreator: Expect.() -> Unit - ) = expect.isFailure { assertionCreator() } + ) = expect.toBeAFailure { assertionCreator() } @Suppress("unused", "UNUSED_VALUE", "UNUSED_VARIABLE") private fun ambiguityTest() { @@ -44,23 +45,23 @@ class ResultExpectationsSpec : ResultExpectationsSpec( var star: Expect> = notImplemented() - a1 toBe success - a1 = a1 toBe success { } + a1 toBe aSuccess + a1 = a1 toBe aSuccess { } - a1.isFailure() - val r1: Expect = a1.isFailure { } + a1.toBeAFailure() + val r1: Expect = a1.toBeAFailure { } - a1b toBe success - a1b = a1b toBe success { } + a1b toBe aSuccess + a1b = a1b toBe aSuccess { } - a1b.isFailure() - val r1b: Expect = a1b.isFailure { } + a1b.toBeAFailure() + val r1b: Expect = a1b.toBeAFailure { } - star toBe success - star = star toBe success { } + star toBe aSuccess + star = star toBe aSuccess { } - star.isFailure() - val r3: Expect = star.isFailure { } + star.toBeAFailure() + val r3: Expect = star.toBeAFailure { } } } } diff --git a/bundles/infix-en_GB/extensions/atrium-infix-en_GB-smoke-test-kotlin_1_3/src/test/kotlin/custom/SmokeSpec.kt b/bundles/infix-en_GB/extensions/atrium-infix-en_GB-smoke-test-kotlin_1_3/src/test/kotlin/custom/SmokeSpec.kt index 9ba076f08..b6a04caa3 100644 --- a/bundles/infix-en_GB/extensions/atrium-infix-en_GB-smoke-test-kotlin_1_3/src/test/kotlin/custom/SmokeSpec.kt +++ b/bundles/infix-en_GB/extensions/atrium-infix-en_GB-smoke-test-kotlin_1_3/src/test/kotlin/custom/SmokeSpec.kt @@ -6,7 +6,7 @@ package custom import ch.tutteli.atrium.api.infix.en_GB.kotlin_1_3.toBe -import ch.tutteli.atrium.api.infix.en_GB.success +import ch.tutteli.atrium.api.infix.en_GB.aSuccess import ch.tutteli.atrium.api.infix.en_GB.toEqual import ch.tutteli.atrium.api.verbs.expect import ch.tutteli.atrium.assertions.Assertion @@ -26,7 +26,7 @@ object SmokeSpec : Spek({ } test("see if `Result.isSuccess` can be used") { - expect(Result.success(1)) toBe success + expect(Result.success(1)) toBe aSuccess } test("see if own expectation function without i18n can be used") { diff --git a/misc/specs/atrium-specs-common/src/main/kotlin/ch/tutteli/atrium/specs/integration/ResultExpectationsSpec.kt b/misc/specs/atrium-specs-common/src/main/kotlin/ch/tutteli/atrium/specs/integration/ResultExpectationsSpec.kt index c85787ca0..ddf61b3ce 100644 --- a/misc/specs/atrium-specs-common/src/main/kotlin/ch/tutteli/atrium/specs/integration/ResultExpectationsSpec.kt +++ b/misc/specs/atrium-specs-common/src/main/kotlin/ch/tutteli/atrium/specs/integration/ResultExpectationsSpec.kt @@ -14,44 +14,44 @@ import org.spekframework.spek2.Spek import org.spekframework.spek2.style.specification.Suite abstract class ResultExpectationsSpec( - isSuccessFeature: Feature0, Int>, - isSuccess: Fun1, Expect.() -> Unit>, - isSuccessFeatureNullable: Feature0, Int?>, - isSuccessNullable: Fun1, Expect.() -> Unit>, - isFailureFeature: Feature0, IllegalArgumentException>, - isFailure: Feature1, Expect.() -> Unit, IllegalArgumentException>, + toBeASuccessFeature: Feature0, Int>, + toBeASuccess: Fun1, Expect.() -> Unit>, + toBeASuccessFeatureNullable: Feature0, Int?>, + toBeASuccessNullable: Fun1, Expect.() -> Unit>, + toBeAFailureFeature: Feature0, IllegalArgumentException>, + toBeAFailure: Feature1, Expect.() -> Unit, IllegalArgumentException>, describePrefix: String = "[Atrium] " ) : Spek({ include(object : SubjectLessSpec>( describePrefix, - isSuccessFeature.forSubjectLess(), - isSuccess.forSubjectLess { toEqual(1) }, - isFailureFeature.forSubjectLess(), - isFailure.forSubjectLess { messageToContain("message") } + toBeASuccessFeature.forSubjectLess(), + toBeASuccess.forSubjectLess { toEqual(1) }, + toBeAFailureFeature.forSubjectLess(), + toBeAFailure.forSubjectLess { messageToContain("message") } ) {}) include(object : SubjectLessSpec>( "$describePrefix[nullable] ", - isSuccessFeatureNullable.forSubjectLess(), - isSuccessNullable.forSubjectLess { toEqual(1) } + toBeASuccessFeatureNullable.forSubjectLess(), + toBeASuccessNullable.forSubjectLess { toEqual(1) } ) {}) include(object : AssertionCreatorSpec>( describePrefix, Result.success(2), - isSuccess.forAssertionCreatorSpec("$toBeDescr: 2") { toEqual(2) } + toBeASuccess.forAssertionCreatorSpec("$toBeDescr: 2") { toEqual(2) } ) {}) include(object : AssertionCreatorSpec>( "$describePrefix[nullable] ", Result.success(2), - isSuccessNullable.forAssertionCreatorSpec("$toBeDescr: 2") { toEqual(2) } + toBeASuccessNullable.forAssertionCreatorSpec("$toBeDescr: 2") { toEqual(2) } ) {}) include(object : AssertionCreatorSpec>( "$describePrefix[failure] ", Result.failure(IllegalArgumentException("oh no...")), assertionCreatorSpecTriple( - isFailure.name, + toBeAFailure.name, "${VALUE.getDefault()}: \"oh no...\"", - { apply { isFailure.invoke(this) { messageToContain("oh no...") } } }, - { apply { isFailure.invoke(this) {} } } + { apply { toBeAFailure.invoke(this) { messageToContain("oh no...") } } }, + { apply { toBeAFailure.invoke(this) {} } } ) ) {}) @@ -67,31 +67,31 @@ abstract class ResultExpectationsSpec( val isNotFailureDescr = DescriptionResultAssertion.IS_NOT_FAILURE.getDefault() val exceptionDescr = DescriptionResultAssertion.EXCEPTION.getDefault() - describeFun(isSuccessFeature, isSuccess, isSuccessFeatureNullable, isSuccessNullable, isFailureFeature, isFailure) { + describeFun(toBeASuccessFeature, toBeASuccess, toBeASuccessFeatureNullable, toBeASuccessNullable, toBeAFailureFeature, toBeAFailure) { val successFunctions = uncheckedToNonNullable( - unifySignatures(isSuccessFeature, isSuccess), - unifySignatures(isSuccessFeatureNullable, isSuccessNullable) + unifySignatures(toBeASuccessFeature, toBeASuccess), + unifySignatures(toBeASuccessFeatureNullable, toBeASuccessNullable) ) - val failureFunctions = unifySignatures(isFailureFeature, isFailure) + val failureFunctions = unifySignatures(toBeAFailureFeature, toBeAFailure) context("subject is $resultSuccess") { - successFunctions.forEach { (name, isSuccessFun, _) -> + successFunctions.forEach { (name, toBeASuccessFun, _) -> it("$name - can perform sub-assertion which holds") { - expect(resultSuccess).isSuccessFun { toEqual(1) } + expect(resultSuccess).toBeASuccessFun { toEqual(1) } } it("$name - can perform sub-assertion which fails, throws AssertionError") { expect { - expect(resultSuccess).isSuccessFun { toEqual(2) } + expect(resultSuccess).toBeASuccessFun { toEqual(2) } }.toThrow { messageToContain("value: 1", "$toBeDescr: 2") } } } - failureFunctions.forEach { (name, isFailureFun, hasExtraHint) -> + failureFunctions.forEach { (name, toBeAFailureFun, hasExtraHint) -> it("$name - throws AssertionError showing the expected type" + if (hasExtraHint) " and the expected message" else "") { expect { - expect(resultSuccess).isFailureFun { messageToContain("oh yes...") } + expect(resultSuccess).toBeAFailureFun { messageToContain("oh yes...") } }.toThrow { messageToContain( "exception: $isNotFailureDescr", @@ -109,10 +109,10 @@ abstract class ResultExpectationsSpec( } context("subject is $resultFailure") { - successFunctions.forEach { (name, isSuccessFun, hasExtraHint) -> + successFunctions.forEach { (name, toBeASuccessFun, hasExtraHint) -> it("$name throws AssertionError" + showsSubAssertionIf(hasExtraHint)) { expect { - expect(resultFailure).isSuccessFun { toEqual(1) } + expect(resultFailure).toBeASuccessFun { toEqual(1) } }.toThrow { messageToContain("value: $isNotSuccessDescr") if (hasExtraHint) messageToContain("$toBeDescr: 1") @@ -120,13 +120,13 @@ abstract class ResultExpectationsSpec( } } - failureFunctions.forEach { (name, isFailureFun, _) -> + failureFunctions.forEach { (name, toBeAFailureFun, _) -> it("$name - can perform sub-assertion which holds") { - expect(resultFailure).isFailureFun { messageToContain("oh no...") } + expect(resultFailure).toBeAFailureFun { messageToContain("oh no...") } } it("$name - can perform sub-assertion which fails, throws AssertionError") { expect { - expect(resultFailure).isFailureFun { messageToContain("oh yes...") } + expect(resultFailure).toBeAFailureFun { messageToContain("oh yes...") } }.toThrow { messageToContain( "$exceptionDescr: ${IllegalArgumentException::class.fullName}", @@ -138,17 +138,17 @@ abstract class ResultExpectationsSpec( } } - describeFun(isSuccessFeatureNullable, isSuccessNullable) { - val successFunctions = unifySignatures(isSuccessFeatureNullable, isSuccessNullable) + describeFun(toBeASuccessFeatureNullable, toBeASuccessNullable) { + val successFunctions = unifySignatures(toBeASuccessFeatureNullable, toBeASuccessNullable) - successFunctions.forEach { (name, isSuccessFun, hasExtraHint) -> + successFunctions.forEach { (name, toBeASuccessFun, hasExtraHint) -> context("subject is $resultNullSuccess") { it("$name - can perform sub-assertion which holds") { - expect(resultNullSuccess).isSuccessFun { toEqual(null) } + expect(resultNullSuccess).toBeASuccessFun { toEqual(null) } } it("$name - can perform sub-assertion which fails, throws AssertionError") { expect { - expect(resultNullSuccess).isSuccessFun { toEqual(2) } + expect(resultNullSuccess).toBeASuccessFun { toEqual(2) } }.toThrow { messageToContain("value: null", "$toBeDescr: 2") } @@ -156,9 +156,9 @@ abstract class ResultExpectationsSpec( } context("subject is $resultNullableFailure") { - it("${isSuccessFeature.name} throws AssertionError" + showsSubAssertionIf(hasExtraHint)) { + it("${toBeASuccessFeature.name} throws AssertionError" + showsSubAssertionIf(hasExtraHint)) { expect { - expect(resultNullableFailure).isSuccessFun { toEqual(1) } + expect(resultNullableFailure).toBeASuccessFun { toEqual(1) } }.toThrow { messageToContain("value: $isNotSuccessDescr") if (hasExtraHint) messageToContain("$toBeDescr: 1")