Skip to content

Commit

Permalink
start fixing CharSequenceNotToContainExpectationsSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
robstoll committed Nov 2, 2024
1 parent f9bc1c1 commit 612d6e7
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ enum class DescriptionCharSequenceProof(override val string: String) : Descripti
/** @since 1.3.0 (but was since 0.18.0 in atrium-translations DescriptionCharSequenceExpectation) */
EXACTLY("is exactly"),

//TODO 1.3.0 think about if you want to support placeholders like that
/** @since 1.3.0 (but was since 0.18.0 in atrium-translations DescriptionCharSequenceExpectation) */
IGNORING_CASE("%s, ignoring case"),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ abstract class AnyExpectationsSpec(
expect(null as Int?).notToEqualNullFun { toEqual(1) }
}.toThrow<AssertionError> {
message {
toContainDescr(notToEqualNullButToBeInstanceOfDescr, "In2t (kotlin.Int)")
toContainDescr(notToEqualNullButToBeInstanceOfDescr, "Int (kotlin.Int)")
if (hasExtraHint) toContainToEqualDescr(1)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package ch.tutteli.atrium.specs.integration

import ch.tutteli.atrium.api.fluent.en_GB.message
import ch.tutteli.atrium.api.fluent.en_GB.messageToContain
import ch.tutteli.atrium.api.fluent.en_GB.notToContain
import ch.tutteli.atrium.api.fluent.en_GB.toThrow
import ch.tutteli.atrium.api.verbs.internal.expect
import ch.tutteli.atrium.core.polyfills.format
import ch.tutteli.atrium.creating.Expect
import ch.tutteli.atrium.reporting.Text
import ch.tutteli.atrium.reporting.reportables.Description
import ch.tutteli.atrium.reporting.reportables.descriptions.DescriptionCharSequenceProof
import ch.tutteli.atrium.specs.*
import org.spekframework.spek2.style.specification.Suite
Expand All @@ -18,21 +17,22 @@ abstract class CharSequenceNotToContainExpectationsSpec(
describePrefix: String = "[Atrium] "
) : CharSequenceToContainSpecBase({

val notToContain = notToContainPair.second
val notToContainIgnoringCase = notToContainIgnoringCasePair.second
val notToContainFunArr = notToContainPair.second
val notToContainIgnoringCaseFunArr = notToContainIgnoringCasePair.second

include(object : SubjectLessSpec<CharSequence>(
describePrefix,
notToContain.forSubjectLess(2.3, arrayOf()),
notToContainIgnoringCase.forSubjectLess(2.3, arrayOf())
notToContainFunArr.forSubjectLess(2.3, arrayOf()),
notToContainIgnoringCaseFunArr.forSubjectLess(2.3, arrayOf())
) {})

fun describeFun(vararg funName: String, body: Suite.() -> Unit) =
describeFunTemplate(describePrefix, funName, body = body)

fun Expect<CharSequence>.notToContainFun(a: Any, vararg aX: Any) = notToContain(this, a, aX)
fun Expect<CharSequence>.notToContainFun(a: Any, vararg aX: Any) = notToContainFunArr(this, a, aX)

fun Expect<CharSequence>.notToContainIgnoringCaseFun(a: Any, vararg aX: Any) = notToContainIgnoringCase(this, a, aX)
fun Expect<CharSequence>.notToContainIgnoringCaseFun(a: Any, vararg aX: Any) =
notToContainIgnoringCaseFunArr(this, a, aX)

val notToContainDescr = DescriptionCharSequenceProof.NOT_TO_CONTAIN.string
val notToContainIgnoringCaseDescr =
Expand All @@ -47,7 +47,7 @@ abstract class CharSequenceNotToContainExpectationsSpec(
toContainDescr(DescriptionCharSequenceProof.NUMBER_OF_MATCHES, representation)


describeFun(notToContain.name, notToContainIgnoringCase.name) {
describeFun(notToContainFunArr.name, notToContainIgnoringCaseFunArr.name) {

context("throws an $illegalArgumentException") {

Expand All @@ -74,7 +74,7 @@ abstract class CharSequenceNotToContainExpectationsSpec(
}

context("text '$helloWorld'") {
context("happy case with $notToContain once") {
context("happy case with $notToContainFunArr once") {
it("${notToContainPair.first("'h'")} does not throw") {
expect(helloWorld).notToContainFun('h')
}
Expand All @@ -90,33 +90,54 @@ abstract class CharSequenceNotToContainExpectationsSpec(
}

context("failing cases; search string at different positions") {
it("${notToContainPair.first("'l'")} throws AssertionError") {
it("${notToContainPair.first("'l', 'A'")} throws AssertionError") {
expect {
expect(helloWorld).notToContainFun('l')
}.toThrow<AssertionError> {
message {
toContainSubject(helloWorld)
toContainDescr(DescriptionCharSequenceProof.NOT_TO_CONTAIN, Text.EMPTY)
toContainValue('l')
toContainSubject("\"$helloWorld\"")
toContainDescr(DescriptionCharSequenceProof.NOT_TO_CONTAIN, "")
toContainValue("'l'")
toContainNumberOfMatches(3)
toContainToEqualDescr(0)
notToContain("'A'")
}
}
}
it("${notToContainPair.first("'H', 'l'")} throws AssertionError") {
expect {
expect(helloWorld).notToContainFun('H', 'l')
}.toThrow<AssertionError> { messageToContain("$valueWithIndent: 'l'") }
}.toThrow<AssertionError> {
message {
toContainValue("'H'")
toContainValue("'l'")
}
}
}
it("${notToContainPair.first("'l', 'H'")} once throws AssertionError") {
expect {
expect(helloWorld).notToContainFun('l', 'H')
}.toThrow<AssertionError> { messageToContain("$valueWithIndent: 'l'") }
}.toThrow<AssertionError> {
message {
toContainValue("'H'")
toContainValue("'l'")
}
}
}
it("${notToContainIgnoringCasePair.first("'H', 'l'")} throws AssertionError") {
expect {
expect(helloWorld).notToContainIgnoringCaseFun('H', 'l')
}.toThrow<AssertionError> {
message {
toContainSubject("\"$helloWorld\"")
toContainDescr(DescriptionCharSequenceProof.NOT_TO_CONTAIN, "")
toContainValue("'l'")
toContainNumberOfMatches(3)
toContainToEqualDescr(0)
notToContain("'A'")
toContainValue("'H'")
toContainValue("'l'")
}
messageToContain(
"$rootBulletPoint$notToContainIgnoringCaseDescr: $separator" +
"$valueWithIndent: 'H'",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ fun Expect<String>.toContainDescr(description: Description, representation: Any?
fun Expect<String>.toContainDescr(description: String, representation: Any?) =
toContain.exactly(1).matchFor(Regex("\\Q$description\\E\\s+: \\Q$representation\\E"))

fun Expect<String>.notToContainDescr(description: String, representation: Any?) =
toContain.exactly(1).matchFor(Regex("\\Q$description\\E\\s+: \\Q$representation\\E"))

0 comments on commit 612d6e7

Please sign in to comment.