
commonMain.ch.tutteli.atrium.specs.reporting.EmptyNameAndSubjectAssertionGroupFormatterSpec.kt Maven / Gradle / Ivy
//TODO 1.4.0 remove file
@file:Suppress("DEPRECATION")
package ch.tutteli.atrium.specs.reporting
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
import ch.tutteli.atrium.assertions.AssertionGroup
import ch.tutteli.atrium.assertions.AssertionGroupType
import ch.tutteli.atrium.assertions.builders.assertionBuilder
import ch.tutteli.atrium.reporting.AssertionFormatter
import ch.tutteli.atrium.reporting.AssertionFormatterController
import ch.tutteli.atrium.reporting.AssertionFormatterParameterObject
import ch.tutteli.atrium.reporting.impl.DefaultAssertionFormatterController
import ch.tutteli.atrium.reporting.translating.StringBasedTranslatable
import ch.tutteli.atrium.specs.describeFunTemplate
import org.spekframework.spek2.Spek
import org.spekframework.spek2.style.specification.Suite
import kotlin.reflect.KClass
abstract class EmptyNameAndSubjectAssertionGroupFormatterSpec(
testeeFactory: (AssertionFormatterController) -> AssertionFormatter,
assertionGroupClass: KClass,
assertionGroupType: T,
anonymousAssertionGroupType: T,
describePrefix: String = "[Atrium] "
) : Spek({
fun describeFun(vararg funName: String, body: Suite.() -> Unit) =
describeFunTemplate(describePrefix, funName, body = body)
val testee = testeeFactory(DefaultAssertionFormatterController())
var sb = StringBuilder()
afterEachTest {
sb = StringBuilder()
}
val testString = "bla blu"
val testSubject = "testSubject"
describeFun(AssertionFormatter::formatGroup.name) {
context("has ${AssertionGroup::description.name} and ${AssertionGroup::representation.name}") {
mapOf(
"object: ${assertionGroupClass.simpleName}" to anonymousAssertionGroupType,
"${assertionGroupType::class.simpleName}" to assertionGroupType
).forEach { (typeRepresentation, type) ->
context("formatting an ${AssertionGroup::class.simpleName} of type $typeRepresentation") {
it("does not include ${AssertionGroup::description.name} nor ${AssertionGroup::representation.name}") {
val assertionGroup = assertionBuilder.customType(type)
.withDescriptionAndRepresentation(TestDescription.TEST_NAME, testSubject)
.withAssertions(emptyList())
.build()
val parameterObject = AssertionFormatterParameterObject.new(
sb,
alwaysTrueAssertionFilter
)
testee.formatGroup(assertionGroup, parameterObject) { _, _ -> sb.append(testString) }
expect(sb.toString())
.notToContain(TestDescription.TEST_NAME.getDefault())
.notToContain(testSubject)
.toContain(testString)
}
}
}
}
}
}) {
enum class TestDescription(override val value: String) : StringBasedTranslatable {
TEST_NAME("testName"),
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy