mirror of
https://github.com/jlengrand/atrium.git
synced 2026-03-10 08:01:19 +00:00
deprecate iterableAssertions, use mew ...Expectations in api-fluent
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
package ch.tutteli.atrium.specs
|
||||
|
||||
import ch.tutteli.atrium.api.fluent.en_GB.all
|
||||
import ch.tutteli.atrium.api.fluent.en_GB.feature
|
||||
import ch.tutteli.atrium.api.fluent.en_GB.toEqual
|
||||
import ch.tutteli.atrium.api.fluent.en_GB.toHaveNextAndAll
|
||||
import ch.tutteli.atrium.api.verbs.internal.expect
|
||||
import ch.tutteli.atrium.assertions.Assertion
|
||||
import ch.tutteli.atrium.assertions.AssertionGroup
|
||||
@@ -55,7 +55,7 @@ abstract class SubjectLessSpec<T>(
|
||||
}
|
||||
}
|
||||
|
||||
describe("${groupPrefix}assertion function does not hold if there is no subject") {
|
||||
describe("${groupPrefix}expectation function does not hold if there is no subject") {
|
||||
assertionCreator.forEach { (name, createAssertion) ->
|
||||
it("fun `$name`") {
|
||||
@Suppress("DEPRECATION" /* OptIn is only available since 1.3.70 which we cannot use if we want to support 1.2 */)
|
||||
@@ -63,7 +63,9 @@ abstract class SubjectLessSpec<T>(
|
||||
val assertions = CollectingExpect<T>(None, expect(1)._logic.components)
|
||||
.addAssertionsCreatedBy(createAssertion)
|
||||
.getAssertions()
|
||||
expect(assertions).all { feature(Assertion::holds).toEqual(false) }
|
||||
expect(assertions).toHaveNextAndAll {
|
||||
feature(Assertion::holds).toEqual(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package ch.tutteli.atrium.specs.integration
|
||||
|
||||
import ch.tutteli.atrium.api.fluent.en_GB.contains
|
||||
import ch.tutteli.atrium.api.fluent.en_GB.containsExactly
|
||||
import ch.tutteli.atrium.api.fluent.en_GB.toContain
|
||||
import ch.tutteli.atrium.api.fluent.en_GB.toContainExactly
|
||||
import ch.tutteli.atrium.api.verbs.internal.expect
|
||||
import ch.tutteli.atrium.creating.Expect
|
||||
import ch.tutteli.atrium.logic.utils.expectLambda
|
||||
@@ -36,39 +38,39 @@ abstract class ArrayAsListExpectationsSpec(
|
||||
val asListWithCreator = "$asListFunName with Creator"
|
||||
include(object : SubjectLessSpec<Array<Int>>("$describePrefix[arr] ",
|
||||
asListFunName to expectLambda { arr(this) },
|
||||
asListWithCreator to expectLambda { arrWithCreator(this) { contains(1) } }
|
||||
asListWithCreator to expectLambda { arrWithCreator(this) { toContain(1) } }
|
||||
) {})
|
||||
include(object : SubjectLessSpec<ByteArray>("$describePrefix[arrByte] ",
|
||||
asListFunName to expectLambda { arrByte(this) },
|
||||
asListWithCreator to expectLambda { arrByteWithCreator(this) { contains(1) } }
|
||||
asListWithCreator to expectLambda { arrByteWithCreator(this) { toContain(1) } }
|
||||
) {})
|
||||
include(object : SubjectLessSpec<CharArray>("$describePrefix[arrChar] ",
|
||||
asListFunName to expectLambda { arrChar(this) },
|
||||
asListWithCreator to expectLambda { arrCharWithCreator(this) { contains('a') } }
|
||||
asListWithCreator to expectLambda { arrCharWithCreator(this) { toContain('a') } }
|
||||
) {})
|
||||
include(object : SubjectLessSpec<ShortArray>("$describePrefix[arrShort] ",
|
||||
asListFunName to expectLambda { arrShort(this) },
|
||||
asListWithCreator to expectLambda { arrShortWithCreator(this) { contains(1.toShort()) } }
|
||||
asListWithCreator to expectLambda { arrShortWithCreator(this) { toContain(1.toShort()) } }
|
||||
) {})
|
||||
include(object : SubjectLessSpec<IntArray>("$describePrefix[arrInt] ",
|
||||
asListFunName to expectLambda { arrInt(this) },
|
||||
asListWithCreator to expectLambda { arrIntWithCreator(this) { contains(1) } }
|
||||
asListWithCreator to expectLambda { arrIntWithCreator(this) { toContain(1) } }
|
||||
) {})
|
||||
include(object : SubjectLessSpec<LongArray>("$describePrefix[arrLong] ",
|
||||
asListFunName to expectLambda { arrLong(this) },
|
||||
asListWithCreator to expectLambda { arrLongWithCreator(this) { contains(1L) } }
|
||||
asListWithCreator to expectLambda { arrLongWithCreator(this) { toContain(1L) } }
|
||||
) {})
|
||||
include(object : SubjectLessSpec<FloatArray>("$describePrefix[arrFloat] ",
|
||||
asListFunName to expectLambda { arrFloat(this) },
|
||||
asListWithCreator to expectLambda { arrFloatWithCreator(this) { contains(1f) } }
|
||||
asListWithCreator to expectLambda { arrFloatWithCreator(this) { toContain(1f) } }
|
||||
) {})
|
||||
include(object : SubjectLessSpec<DoubleArray>("$describePrefix[arrDouble] ",
|
||||
asListFunName to expectLambda { arrDouble(this) },
|
||||
asListWithCreator to expectLambda { arrDoubleWithCreator(this) { contains(1.0) } }
|
||||
asListWithCreator to expectLambda { arrDoubleWithCreator(this) { toContain(1.0) } }
|
||||
) {})
|
||||
include(object : SubjectLessSpec<BooleanArray>("$describePrefix[arrBoolean] ",
|
||||
asListFunName to expectLambda { arrBoolean(this) },
|
||||
asListWithCreator to expectLambda { arrBooleanWithCreator(this) { contains(true) } }
|
||||
asListWithCreator to expectLambda { arrBooleanWithCreator(this) { toContain(true) } }
|
||||
) {})
|
||||
|
||||
fun bytes(vararg bytes: Byte) = bytes
|
||||
@@ -86,7 +88,7 @@ abstract class ArrayAsListExpectationsSpec(
|
||||
assertionCreatorSpecTriple(
|
||||
asListFunName,
|
||||
anElementWhich,
|
||||
{ arrWithCreator.invoke(this) { contains(1) } },
|
||||
{ arrWithCreator.invoke(this) { toContain(1) } },
|
||||
{ arrWithCreator.invoke(this) {} })
|
||||
) {})
|
||||
include(object : AssertionCreatorSpec<ByteArray>(
|
||||
@@ -94,7 +96,7 @@ abstract class ArrayAsListExpectationsSpec(
|
||||
assertionCreatorSpecTriple(
|
||||
asListFunName,
|
||||
anElementWhich,
|
||||
{ arrByteWithCreator.invoke(this) { contains(1) } },
|
||||
{ arrByteWithCreator.invoke(this) { toContain(1) } },
|
||||
{ arrByteWithCreator.invoke(this) {} })
|
||||
) {})
|
||||
include(object : AssertionCreatorSpec<CharArray>(
|
||||
@@ -102,7 +104,7 @@ abstract class ArrayAsListExpectationsSpec(
|
||||
assertionCreatorSpecTriple(
|
||||
asListFunName,
|
||||
anElementWhich,
|
||||
{ arrCharWithCreator.invoke(this) { contains('a') } },
|
||||
{ arrCharWithCreator.invoke(this) { toContain('a') } },
|
||||
{ arrCharWithCreator.invoke(this) {} })
|
||||
) {})
|
||||
include(object : AssertionCreatorSpec<ShortArray>(
|
||||
@@ -110,7 +112,7 @@ abstract class ArrayAsListExpectationsSpec(
|
||||
assertionCreatorSpecTriple(
|
||||
asListFunName,
|
||||
anElementWhich,
|
||||
{ arrShortWithCreator.invoke(this) { contains(1) } },
|
||||
{ arrShortWithCreator.invoke(this) { toContain(1) } },
|
||||
{ arrShortWithCreator.invoke(this) {} })
|
||||
) {})
|
||||
include(object : AssertionCreatorSpec<IntArray>(
|
||||
@@ -118,7 +120,7 @@ abstract class ArrayAsListExpectationsSpec(
|
||||
assertionCreatorSpecTriple(
|
||||
asListFunName,
|
||||
anElementWhich,
|
||||
{ arrIntWithCreator.invoke(this) { contains(1) } },
|
||||
{ arrIntWithCreator.invoke(this) { toContain(1) } },
|
||||
{ arrIntWithCreator.invoke(this) {} })
|
||||
) {})
|
||||
include(object : AssertionCreatorSpec<LongArray>(
|
||||
@@ -126,7 +128,7 @@ abstract class ArrayAsListExpectationsSpec(
|
||||
assertionCreatorSpecTriple(
|
||||
asListFunName,
|
||||
anElementWhich,
|
||||
{ arrLongWithCreator.invoke(this) { contains(1) } },
|
||||
{ arrLongWithCreator.invoke(this) { toContain(1) } },
|
||||
{ arrLongWithCreator.invoke(this) {} })
|
||||
) {})
|
||||
include(object : AssertionCreatorSpec<FloatArray>(
|
||||
@@ -134,7 +136,7 @@ abstract class ArrayAsListExpectationsSpec(
|
||||
assertionCreatorSpecTriple(
|
||||
asListFunName,
|
||||
anElementWhich,
|
||||
{ arrFloatWithCreator.invoke(this) { contains(1.0f) } },
|
||||
{ arrFloatWithCreator.invoke(this) { toContain(1.0f) } },
|
||||
{ arrFloatWithCreator.invoke(this) {} })
|
||||
) {})
|
||||
include(object : AssertionCreatorSpec<DoubleArray>(
|
||||
@@ -142,7 +144,7 @@ abstract class ArrayAsListExpectationsSpec(
|
||||
assertionCreatorSpecTriple(
|
||||
asListFunName,
|
||||
anElementWhich,
|
||||
{ arrDoubleWithCreator.invoke(this) { contains(1.0) } },
|
||||
{ arrDoubleWithCreator.invoke(this) { toContain(1.0) } },
|
||||
{ arrDoubleWithCreator.invoke(this) {} })
|
||||
) {})
|
||||
include(object : AssertionCreatorSpec<BooleanArray>(
|
||||
@@ -150,81 +152,81 @@ abstract class ArrayAsListExpectationsSpec(
|
||||
assertionCreatorSpecTriple(
|
||||
asListFunName,
|
||||
anElementWhich,
|
||||
{ arrBooleanWithCreator.invoke(this) { contains(true) } },
|
||||
{ arrBooleanWithCreator.invoke(this) { toContain(true) } },
|
||||
{ arrBooleanWithCreator.invoke(this) {} })
|
||||
) {})
|
||||
|
||||
describe("$asListFunName arr") {
|
||||
it("transformation can be applied and a subsequent assertion made") {
|
||||
expect(arrayOf(1, 2)).arr().containsExactly(1, 2)
|
||||
expect(arrayOf(1, 2)).arr().toContainExactly(1, 2)
|
||||
}
|
||||
it("transformation can be applied and a sub-assertion made") {
|
||||
expect(arrayOf(1, 2)).arrWithCreator { containsExactly(1, 2) }
|
||||
expect(arrayOf(1, 2)).arrWithCreator { toContainExactly(1, 2) }
|
||||
}
|
||||
}
|
||||
|
||||
describe("$asListFunName arrByte") {
|
||||
it("transformation can be applied and a subsequent assertion made") {
|
||||
expect(bytes(1.toByte(), 2.toByte())).arrByte().containsExactly(1.toByte(), 2.toByte())
|
||||
expect(bytes(1.toByte(), 2.toByte())).arrByte().toContainExactly(1.toByte(), 2.toByte())
|
||||
}
|
||||
it("transformation can be applied and a sub assertion made") {
|
||||
expect(bytes(1.toByte(), 2.toByte())).arrByteWithCreator { containsExactly(1.toByte(), 2.toByte()) }
|
||||
expect(bytes(1.toByte(), 2.toByte())).arrByteWithCreator { toContainExactly(1.toByte(), 2.toByte()) }
|
||||
}
|
||||
}
|
||||
describe("$asListFunName arrChar") {
|
||||
it("transformation can be applied and a subsequent assertion made") {
|
||||
expect(chars(1.toChar(), 2.toChar())).arrChar().containsExactly(1.toChar(), 2.toChar())
|
||||
expect(chars(1.toChar(), 2.toChar())).arrChar().toContainExactly(1.toChar(), 2.toChar())
|
||||
}
|
||||
it("transformation can be applied and a sub assertion made") {
|
||||
expect(chars(1.toChar(), 2.toChar())).arrCharWithCreator { containsExactly(1.toChar(), 2.toChar()) }
|
||||
expect(chars(1.toChar(), 2.toChar())).arrCharWithCreator { toContainExactly(1.toChar(), 2.toChar()) }
|
||||
}
|
||||
}
|
||||
describe("$asListFunName arrShort") {
|
||||
it("transformation can be applied and a subsequent assertion made") {
|
||||
expect(shorts(1, 2)).arrShort().containsExactly(1.toShort(), 2.toShort())
|
||||
expect(shorts(1, 2)).arrShort().toContainExactly(1.toShort(), 2.toShort())
|
||||
}
|
||||
it("transformation can be applied and a sub assertion made") {
|
||||
expect(shorts(1, 2)).arrShortWithCreator { containsExactly(1.toShort(), 2.toShort()) }
|
||||
expect(shorts(1, 2)).arrShortWithCreator { toContainExactly(1.toShort(), 2.toShort()) }
|
||||
}
|
||||
}
|
||||
describe("$asListFunName arrInt") {
|
||||
it("transformation can be applied and a subsequent assertion made") {
|
||||
expect(ints(1, 2)).arrInt().containsExactly(1, 2)
|
||||
expect(ints(1, 2)).arrInt().toContainExactly(1, 2)
|
||||
}
|
||||
it("transformation can be applied and a sub assertion made") {
|
||||
expect(ints(1, 2)).arrIntWithCreator { containsExactly(1, 2) }
|
||||
expect(ints(1, 2)).arrIntWithCreator { toContainExactly(1, 2) }
|
||||
}
|
||||
}
|
||||
describe("$asListFunName arrLong") {
|
||||
it("transformation can be applied and a subsequent assertion made") {
|
||||
expect(longs(1, 2)).arrLong().containsExactly(1L, 2L)
|
||||
expect(longs(1, 2)).arrLong().toContainExactly(1L, 2L)
|
||||
}
|
||||
it("transformation can be applied and a sub assertion made") {
|
||||
expect(longs(1, 2)).arrLongWithCreator { containsExactly(1L, 2L) }
|
||||
expect(longs(1, 2)).arrLongWithCreator { toContainExactly(1L, 2L) }
|
||||
}
|
||||
}
|
||||
describe("$asListFunName arrFloat") {
|
||||
it("transformation can be applied and a subsequent assertion made") {
|
||||
expect(floats(1f, 2f)).arrFloat().containsExactly(1f, 2f)
|
||||
expect(floats(1f, 2f)).arrFloat().toContainExactly(1f, 2f)
|
||||
}
|
||||
it("transformation can be applied and a sub assertion made") {
|
||||
expect(floats(1f, 2f)).arrFloatWithCreator { containsExactly(1f, 2f) }
|
||||
expect(floats(1f, 2f)).arrFloatWithCreator { toContainExactly(1f, 2f) }
|
||||
}
|
||||
}
|
||||
describe("$asListFunName arrDouble") {
|
||||
it("transformation can be applied and a subsequent assertion made") {
|
||||
expect(doubles(1.0, 2.0)).arrDouble().containsExactly(1.0, 2.0)
|
||||
expect(doubles(1.0, 2.0)).arrDouble().toContainExactly(1.0, 2.0)
|
||||
}
|
||||
it("transformation can be applied and a sub assertion made") {
|
||||
expect(doubles(1.0, 2.0)).arrDoubleWithCreator { containsExactly(1.0, 2.0) }
|
||||
expect(doubles(1.0, 2.0)).arrDoubleWithCreator { toContainExactly(1.0, 2.0) }
|
||||
}
|
||||
}
|
||||
describe("$asListFunName arrBoolean") {
|
||||
it("transformation can be applied and a subsequent assertion made") {
|
||||
expect(booleans(true, false)).arrBoolean().containsExactly(true, false)
|
||||
expect(booleans(true, false)).arrBoolean().toContainExactly(true, false)
|
||||
}
|
||||
it("transformation can be applied and a sub assertion made") {
|
||||
expect(booleans(true, false)).arrBooleanWithCreator { containsExactly(true, false) }
|
||||
expect(booleans(true, false)).arrBooleanWithCreator { toContainExactly(true, false) }
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -16,7 +16,7 @@ abstract class MapAsEntriesExpectationsSpec(
|
||||
include(object : SubjectLessSpec<Map<String, Int>>(
|
||||
describePrefix,
|
||||
asEntriesFeature.forSubjectLess(),
|
||||
asEntries.forSubjectLess { contains("a" to 1) }
|
||||
asEntries.forSubjectLess { toContain("a" to 1) }
|
||||
) {})
|
||||
|
||||
fun describeFun(vararg pairs: SpecPair<*>, body: Suite.() -> Unit) =
|
||||
@@ -28,7 +28,7 @@ abstract class MapAsEntriesExpectationsSpec(
|
||||
asEntriesFunctions.forEach{ (name, asEntriesFun, _) ->
|
||||
it("$name - transformation can be applied and an assertion made") {
|
||||
expect(mapOf("a" to 1, "b" to 2)).asEntriesFun {
|
||||
contains.inAnyOrder.only.entries(
|
||||
toContain.inAnyOrder.only.entries(
|
||||
{ isKeyValue("b", 2) },
|
||||
{
|
||||
key { toStartWith("a") }
|
||||
|
||||
@@ -57,8 +57,8 @@ abstract class MapExpectationsSpec(
|
||||
|
||||
include(object : AssertionCreatorSpec<Map<out String, Int>>(
|
||||
describePrefix, map,
|
||||
keys.forAssertionCreatorSpec("$toBeDescr: a") { containsExactly({ toEqual("a") }, { toEqual("b") }) },
|
||||
values.forAssertionCreatorSpec("$toBeDescr: 1") { containsExactly({ toEqual(1) }, { toEqual(2) }) },
|
||||
keys.forAssertionCreatorSpec("$toBeDescr: a") { toContainExactly({ toEqual("a") }, { toEqual("b") }) },
|
||||
values.forAssertionCreatorSpec("$toBeDescr: 1") { toContainExactly({ toEqual(1) }, { toEqual(2) }) },
|
||||
getExisting.forAssertionCreatorSpec("$toBeDescr: 2", "b") { toEqual(2) }
|
||||
) {})
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package ch.tutteli.atrium.specs.reporting
|
||||
|
||||
import ch.tutteli.atrium.api.fluent.en_GB.contains
|
||||
import ch.tutteli.atrium.api.fluent.en_GB.containsNot
|
||||
import ch.tutteli.atrium.api.fluent.en_GB.notToContain
|
||||
import ch.tutteli.atrium.api.fluent.en_GB.toContain
|
||||
import ch.tutteli.atrium.api.verbs.internal.expect
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package ch.tutteli.atrium.specs.reporting.translating
|
||||
|
||||
import ch.tutteli.atrium.api.fluent.en_GB.containsExactly
|
||||
import ch.tutteli.atrium.api.fluent.en_GB.toContainExactly
|
||||
import ch.tutteli.atrium.api.verbs.internal.expect
|
||||
import ch.tutteli.atrium.reporting.translating.Locale
|
||||
import ch.tutteli.atrium.reporting.translating.LocaleOrderDecider
|
||||
@@ -50,9 +51,9 @@ abstract class LocaleOrderDeciderSpec(
|
||||
context("primary locale is $localeDe") {
|
||||
it("returns $localeDe$andAdditional") {
|
||||
val result = testee.determineOrder(localeDe, fallbackLocales).asIterable()
|
||||
expect(result).containsExactly(
|
||||
localeDe
|
||||
, *additionalLocaleCandidates
|
||||
expect(result).toContainExactly(
|
||||
localeDe,
|
||||
*additionalLocaleCandidates
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -60,10 +61,10 @@ abstract class LocaleOrderDeciderSpec(
|
||||
context("primary locale is $localeDeCh") {
|
||||
it("returns $localeDeCh, $localeDe$andAdditional") {
|
||||
val result = testee.determineOrder(localeDeCh, fallbackLocales).asIterable()
|
||||
expect(result).containsExactly(
|
||||
localeDeCh
|
||||
, localeDe
|
||||
, *additionalLocaleCandidates
|
||||
expect(result).toContainExactly(
|
||||
localeDeCh,
|
||||
localeDe,
|
||||
*additionalLocaleCandidates
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -77,11 +78,11 @@ abstract class LocaleOrderDeciderSpec(
|
||||
+ andAdditional
|
||||
) {
|
||||
val result = testee.determineOrder(localeDeChVariantA, fallbackLocales).asIterable()
|
||||
expect(result).containsExactly(
|
||||
localeDeChVariantA
|
||||
, localeDeCh
|
||||
, localeDe
|
||||
, *additionalLocaleCandidates
|
||||
expect(result).toContainExactly(
|
||||
localeDeChVariantA,
|
||||
localeDeCh,
|
||||
localeDe,
|
||||
*additionalLocaleCandidates
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -96,12 +97,12 @@ abstract class LocaleOrderDeciderSpec(
|
||||
+ andAdditional
|
||||
) {
|
||||
val result = testee.determineOrder(localeDeChVariantAVariantB, fallbackLocales).asIterable()
|
||||
expect(result).containsExactly(
|
||||
localeDeChVariantAVariantB
|
||||
, localeDeChVariantA
|
||||
, localeDeCh
|
||||
, localeDe
|
||||
, *additionalLocaleCandidates
|
||||
expect(result).toContainExactly(
|
||||
localeDeChVariantAVariantB,
|
||||
localeDeChVariantA,
|
||||
localeDeCh,
|
||||
localeDe,
|
||||
*additionalLocaleCandidates
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -118,14 +119,14 @@ abstract class LocaleOrderDeciderSpec(
|
||||
+ andAdditional
|
||||
) {
|
||||
val result = testee.determineOrder(localeDeScriptLatnChVariantA, fallbackLocales).asIterable()
|
||||
expect(result).containsExactly(
|
||||
localeDeScriptLatnChVariantA
|
||||
, localeDeScriptLatnCh
|
||||
, localeDeScriptLatn
|
||||
, localeDeChVariantA
|
||||
, localeDeCh
|
||||
, localeDe
|
||||
, *additionalLocaleCandidates
|
||||
expect(result).toContainExactly(
|
||||
localeDeScriptLatnChVariantA,
|
||||
localeDeScriptLatnCh,
|
||||
localeDeScriptLatn,
|
||||
localeDeChVariantA,
|
||||
localeDeCh,
|
||||
localeDe,
|
||||
*additionalLocaleCandidates
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package readme.examples
|
||||
import ch.tutteli.atrium.api.fluent.en_GB.asIterable
|
||||
import ch.tutteli.atrium.api.fluent.en_GB.contains
|
||||
import ch.tutteli.atrium.api.fluent.en_GB.feature
|
||||
import ch.tutteli.atrium.api.fluent.en_GB.toContain
|
||||
import org.spekframework.spek2.Spek
|
||||
import readme.examples.utils.expect
|
||||
|
||||
@@ -22,9 +23,9 @@ import readme.examples.utils.expect
|
||||
*/
|
||||
object FaqSpec : Spek({
|
||||
test("code-faq-1") {
|
||||
expect(sequenceOf(1, 2, 3)).asIterable().contains(2)
|
||||
expect(sequenceOf(1, 2, 3)).asIterable().toContain(2)
|
||||
}
|
||||
test("code-faq-2") {
|
||||
expect(sequenceOf(1, 2, 3)).feature { f(it::asIterable) }.contains(2)
|
||||
expect(sequenceOf(1, 2, 3)).feature { f(it::asIterable) }.toContain(2)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -2,6 +2,7 @@ package readme.examples
|
||||
|
||||
import readme.examples.utils.expect
|
||||
import ch.tutteli.atrium.api.fluent.en_GB.*
|
||||
import ch.tutteli.atrium.creating.Expect
|
||||
import org.spekframework.spek2.Spek
|
||||
import java.math.BigDecimal
|
||||
|
||||
@@ -33,7 +34,7 @@ class MostExamplesSpec : Spek({
|
||||
//snippet-code-single-end
|
||||
}
|
||||
|
||||
test("code-single-explained"){
|
||||
test("code-single-explained") {
|
||||
//snippet-code-single-insert
|
||||
}
|
||||
|
||||
@@ -55,7 +56,7 @@ class MostExamplesSpec : Spek({
|
||||
//snippet-code-and-end
|
||||
}
|
||||
|
||||
test("code-and"){
|
||||
test("code-and") {
|
||||
expect(5).toBeGreaterThan(2).and.toBeLessThan(10)
|
||||
|
||||
//snippet-code-and-insert
|
||||
@@ -122,40 +123,46 @@ class MostExamplesSpec : Spek({
|
||||
}
|
||||
|
||||
test("ex-collection-short-1") {
|
||||
expect(listOf(1, 2, 2, 4)).contains(2, 3)
|
||||
expect(listOf(1, 2, 2, 4)).toContain(2, 3)
|
||||
}
|
||||
|
||||
test("ex-collection-short-2") {
|
||||
expect(listOf(1, 2, 2, 4)).contains(
|
||||
expect(listOf(1, 2, 2, 4)).toContain(
|
||||
{ toBeLessThan(0) },
|
||||
{ toBeGreaterThan(2).toBeLessThan(4) }
|
||||
)
|
||||
}
|
||||
|
||||
test("ex-collection-any") {
|
||||
expect(listOf(1, 2, 3, 4)).any { toBeLessThan(0) }
|
||||
expect(listOf(1, 2, 3, 4)).toHaveNextAndAny {
|
||||
toBeLessThan(0)
|
||||
}
|
||||
}
|
||||
test("ex-collection-none") {
|
||||
expect(listOf(1, 2, 3, 4)).none { toBeGreaterThan(2) }
|
||||
expect(listOf(1, 2, 3, 4)).toHaveNextAndNone {
|
||||
toBeGreaterThan(2)
|
||||
}
|
||||
}
|
||||
test("ex-collection-all") {
|
||||
expect(listOf(1, 2, 3, 4)).all { toBeGreaterThan(2) }
|
||||
expect(listOf(1, 2, 3, 4)).toHaveNextAndAll {
|
||||
toBeGreaterThan(2)
|
||||
}
|
||||
}
|
||||
|
||||
test("ex-collection-builder-1") {
|
||||
expect(listOf(1, 2, 2, 4)).contains.inOrder.only.entries({ toBeLessThan(3) }, { toBeLessThan(2) })
|
||||
expect(listOf(1, 2, 2, 4)).toContain.inOrder.only.entries({ toBeLessThan(3) }, { toBeLessThan(2) })
|
||||
}
|
||||
test("ex-collection-builder-2") {
|
||||
expect(listOf(1, 2, 2, 4)).contains.inOrder.only.values(1, 2, 2, 3, 4)
|
||||
expect(listOf(1, 2, 2, 4)).toContain.inOrder.only.values(1, 2, 2, 3, 4)
|
||||
}
|
||||
test("ex-collection-builder-3") {
|
||||
expect(listOf(1, 2, 2, 4)).contains.inAnyOrder.atLeast(1).butAtMost(2).entries({ toBeLessThan(3) })
|
||||
expect(listOf(1, 2, 2, 4)).toContain.inAnyOrder.atLeast(1).butAtMost(2).entries({ toBeLessThan(3) })
|
||||
}
|
||||
test("ex-collection-builder-4") {
|
||||
expect(listOf(1, 2, 2, 4)).contains.inAnyOrder.only.values(1, 2, 3, 4)
|
||||
expect(listOf(1, 2, 2, 4)).toContain.inAnyOrder.only.values(1, 2, 3, 4)
|
||||
}
|
||||
test("ex-collection-builder-5") {
|
||||
expect(listOf(1, 2, 2, 4)).contains.inAnyOrder.only.values(4, 3, 2, 2, 1)
|
||||
expect(listOf(1, 2, 2, 4)).toContain.inAnyOrder.only.values(4, 3, 2, 2, 1)
|
||||
}
|
||||
|
||||
test("ex-map-1") {
|
||||
@@ -207,12 +214,12 @@ class MostExamplesSpec : Spek({
|
||||
}
|
||||
test("ex-map-4") {
|
||||
expect(mapOf("a" to 1, "b" to 2)) {
|
||||
keys { all { toStartWith("a") } }
|
||||
values { none { toBeGreaterThan(1) } }
|
||||
keys { toHaveNextAndAll { toStartWith("a") } }
|
||||
values { toHaveNextAndNone { toBeGreaterThan(1) } }
|
||||
}
|
||||
}
|
||||
test("ex-map-5") {
|
||||
expect(linkedMapOf("a" to 1, "b" to 2)).asEntries().contains.inOrder.only.entries(
|
||||
expect(linkedMapOf("a" to 1, "b" to 2)).asEntries().toContain.inOrder.only.entries(
|
||||
{ isKeyValue("a", 1) },
|
||||
{
|
||||
key.toStartWith("a")
|
||||
@@ -229,7 +236,7 @@ class MostExamplesSpec : Spek({
|
||||
}
|
||||
|
||||
test("exs-add-info-1") {
|
||||
expect(listOf(1, 2, 3)).contains.inOrder.only.values(1, 3)
|
||||
expect(listOf(1, 2, 3)).toContain.inOrder.only.values(1, 3)
|
||||
}
|
||||
test("exs-add-info-2") {
|
||||
expect(9.99f).toEqualWithErrorTolerance(10.0f, 0.01f)
|
||||
|
||||
@@ -79,7 +79,9 @@ object OwnExpectationFunctionsSpec : Spek({
|
||||
//snippet-own-compose-4-start
|
||||
fun Expect<Person>.hasAdultChildren(): Expect<Person> =
|
||||
feature(Person::children) {
|
||||
all { feature(Person::age).toBeGreaterThanOrEqualTo(18) }
|
||||
toHaveNextAndAll {
|
||||
feature(Person::age).toBeGreaterThanOrEqualTo(18)
|
||||
}
|
||||
}
|
||||
|
||||
//snippet-own-compose-4-end
|
||||
@@ -99,13 +101,19 @@ object OwnExpectationFunctionsSpec : Spek({
|
||||
test("ex-own-compose-5"){
|
||||
expect(Person("Susanne", "Whitley", 43, listOf(Person("Petra", "Whitley", 12, listOf()))))
|
||||
.children { // using the fun -> assertion group, ergo sub-assertions don't fail fast
|
||||
none { feature { f(it::firstName) }.toStartWith("Ro") }
|
||||
all { feature { f(it::lastName) }.toEqual("Whitley") }
|
||||
toHaveNextAndNone {
|
||||
feature { f(it::firstName) }.toStartWith("Ro")
|
||||
}
|
||||
toHaveNextAndAll {
|
||||
feature { f(it::lastName) }.toEqual("Whitley")
|
||||
}
|
||||
} // subject is still Person here
|
||||
.apply { // only evaluated because the previous assertion group holds
|
||||
children // using the val -> subsequent assertions are about children and fail fast
|
||||
.toHaveSize(2)
|
||||
.any { feature { f(it::age) }.toBeGreaterThan(18) }
|
||||
.toHaveNextAndAny {
|
||||
feature { f(it::age) }.toBeGreaterThan(18)
|
||||
}
|
||||
} // subject is still Person here due to the `apply`
|
||||
.children // using the val -> subsequent assertions are about children and fail fast
|
||||
.toHaveSize(2)
|
||||
@@ -118,7 +126,7 @@ object OwnExpectationFunctionsSpec : Spek({
|
||||
person: Person, vararg otherPersons: Person
|
||||
): Expect<T> {
|
||||
val (pair, otherPairs) = mapArguments(person, otherPersons) { it.firstName to it.lastName }
|
||||
return contains.inAnyOrder.only.values(pair, *otherPairs)
|
||||
return toContain.inAnyOrder.only.values(pair, *otherPairs)
|
||||
}
|
||||
//snippet-own-compose-6-end
|
||||
|
||||
@@ -135,7 +143,7 @@ object OwnExpectationFunctionsSpec : Spek({
|
||||
first.toStartWith(it.firstName[0].toString())
|
||||
second.toStartWith(it.lastName[0].toString())
|
||||
}
|
||||
return contains.inOrder.only.entries(first, *others)
|
||||
return toContain.inOrder.only.entries(first, *others)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user