mirror of
https://github.com/jlengrand/atrium.git
synced 2026-03-10 08:01:19 +00:00
Fuse collection and iterable specs (#602)
This commit is contained in:
committed by
GitHub
parent
c73eccb622
commit
176b02fdf0
@@ -1,8 +1,8 @@
|
||||
package ch.tutteli.atrium.specs.integration
|
||||
|
||||
import ch.tutteli.atrium.api.fluent.en_GB.messageContains
|
||||
import ch.tutteli.atrium.api.fluent.en_GB.toThrow
|
||||
import ch.tutteli.atrium.api.fluent.en_GB.*
|
||||
import ch.tutteli.atrium.api.verbs.internal.expect
|
||||
import ch.tutteli.atrium.creating.Expect
|
||||
import ch.tutteli.atrium.specs.*
|
||||
import ch.tutteli.atrium.translations.DescriptionBasic
|
||||
import ch.tutteli.atrium.translations.DescriptionCollectionAssertion
|
||||
@@ -12,13 +12,22 @@ import org.spekframework.spek2.style.specification.Suite
|
||||
abstract class CollectionAssertionsSpec(
|
||||
isEmpty: Fun0<Collection<Int>>,
|
||||
isNotEmpty: Fun0<Collection<Int>>,
|
||||
sizeFeature: Feature0<Collection<Int>, Int>,
|
||||
size: Fun1<Collection<Int>, Expect<Int>.() -> Unit>,
|
||||
describePrefix: String = "[Atrium] "
|
||||
) : Spek({
|
||||
|
||||
include(object : SubjectLessSpec<Collection<Int>>(
|
||||
describePrefix,
|
||||
isEmpty.forSubjectLess(),
|
||||
isNotEmpty.forSubjectLess()
|
||||
isNotEmpty.forSubjectLess(),
|
||||
sizeFeature.forSubjectLess().adjustName { "$it feature" },
|
||||
size.forSubjectLess { isGreaterThan(2) }
|
||||
) {})
|
||||
|
||||
include(object : AssertionCreatorSpec<Collection<Int>>(
|
||||
describePrefix, listOf(999),
|
||||
size.forAssertionCreatorSpec("$toBeDescr: 1") { toBe(1) }
|
||||
) {})
|
||||
|
||||
fun describeFun(vararg pairs: SpecPair<*>, body: Suite.() -> Unit) =
|
||||
@@ -27,6 +36,8 @@ abstract class CollectionAssertionsSpec(
|
||||
val isDescr = DescriptionBasic.IS.getDefault()
|
||||
val isNotDescr = DescriptionBasic.IS_NOT.getDefault()
|
||||
val empty = DescriptionCollectionAssertion.EMPTY.getDefault()
|
||||
val fluent = expect(listOf(1, 2) as Collection<Int>)
|
||||
val sizeDescr = DescriptionCollectionAssertion.SIZE.getDefault()
|
||||
|
||||
describeFun(isEmpty, isNotEmpty) {
|
||||
val isEmptyFun = isEmpty.lambda
|
||||
@@ -54,4 +65,24 @@ abstract class CollectionAssertionsSpec(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
describeFun(sizeFeature, size) {
|
||||
val sizeFunctions = unifySignatures(sizeFeature, size)
|
||||
|
||||
context("list with two entries") {
|
||||
sizeFunctions.forEach { (name, sizeFun, _) ->
|
||||
it("$name - is greater than 1 holds") {
|
||||
fluent.sizeFun { isGreaterThan(1) }
|
||||
}
|
||||
it("$name - is less than 1 fails") {
|
||||
expect {
|
||||
fluent.sizeFun { isLessThan(1) }
|
||||
}.toThrow<AssertionError> {
|
||||
messageContains("$sizeDescr: 2")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
package ch.tutteli.atrium.specs.integration
|
||||
|
||||
import ch.tutteli.atrium.api.fluent.en_GB.*
|
||||
import ch.tutteli.atrium.api.verbs.internal.expect
|
||||
import ch.tutteli.atrium.creating.Expect
|
||||
import ch.tutteli.atrium.specs.*
|
||||
import ch.tutteli.atrium.translations.DescriptionCollectionAssertion
|
||||
import org.spekframework.spek2.Spek
|
||||
import org.spekframework.spek2.style.specification.Suite
|
||||
|
||||
abstract class CollectionFeatureAssertionsSpec(
|
||||
sizeFeature: Feature0<Collection<String>, Int>,
|
||||
size: Fun1<Collection<String>, Expect<Int>.() -> Unit>,
|
||||
describePrefix: String = "[Atrium] "
|
||||
) : Spek({
|
||||
|
||||
include(object : SubjectLessSpec<Collection<String>>(describePrefix,
|
||||
sizeFeature.forSubjectLess().adjustName { "$it feature" },
|
||||
size.forSubjectLess { isGreaterThan(2) }
|
||||
) {})
|
||||
|
||||
include(object : AssertionCreatorSpec<Collection<String>>(
|
||||
describePrefix, listOf("hello"),
|
||||
size.forAssertionCreatorSpec("$toBeDescr: 1") { toBe(1) }
|
||||
) {})
|
||||
|
||||
fun describeFun(vararg pairs: SpecPair<*>, body: Suite.() -> Unit) =
|
||||
describeFunTemplate(describePrefix, pairs.map { it.name }.toTypedArray(), body = body)
|
||||
|
||||
val fluent = expect(listOf("a", "b") as Collection<String>)
|
||||
val sizeDescr = DescriptionCollectionAssertion.SIZE.getDefault()
|
||||
|
||||
describeFun(sizeFeature, size) {
|
||||
val sizeFunctions = unifySignatures(sizeFeature, size)
|
||||
|
||||
context("list with two entries") {
|
||||
sizeFunctions.forEach { (name, sizeFun, _) ->
|
||||
it("$name - is greater than 1 holds") {
|
||||
fluent.sizeFun { isGreaterThan(1) }
|
||||
}
|
||||
it("$name - is less than 1 fails") {
|
||||
expect {
|
||||
fluent.sizeFun { isLessThan(1) }
|
||||
}.toThrow<AssertionError> {
|
||||
messageContains("$sizeDescr: 2")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -1,8 +1,8 @@
|
||||
package ch.tutteli.atrium.specs.integration
|
||||
|
||||
import ch.tutteli.atrium.api.fluent.en_GB.messageContains
|
||||
import ch.tutteli.atrium.api.fluent.en_GB.toThrow
|
||||
import ch.tutteli.atrium.api.fluent.en_GB.*
|
||||
import ch.tutteli.atrium.api.verbs.internal.expect
|
||||
import ch.tutteli.atrium.creating.Expect
|
||||
import ch.tutteli.atrium.specs.*
|
||||
import ch.tutteli.atrium.translations.DescriptionBasic
|
||||
import ch.tutteli.atrium.translations.DescriptionIterableAssertion
|
||||
@@ -12,12 +12,26 @@ import org.spekframework.spek2.style.specification.Suite
|
||||
abstract class IterableAssertionsSpec(
|
||||
hasNext: Fun0<Iterable<Int>>,
|
||||
hasNotNext: Fun0<Iterable<Int>>,
|
||||
minFeature: Feature0<Iterable<Int>,Int>,
|
||||
min: Fun1<Iterable<Int>, Expect<Int>.() -> Unit>,
|
||||
maxFeature: Feature0<Iterable<Int>, Int>,
|
||||
max: Fun1<Iterable<Int>, Expect<Int>.() -> Unit>,
|
||||
describePrefix: String = "[Atrium] "
|
||||
) : Spek({
|
||||
|
||||
include(object : SubjectLessSpec<Iterable<Int>>(
|
||||
describePrefix,
|
||||
hasNext.forSubjectLess()
|
||||
hasNext.forSubjectLess(),
|
||||
minFeature.forSubjectLess(),
|
||||
min.forSubjectLess { isGreaterThan(-100) },
|
||||
maxFeature.forSubjectLess(),
|
||||
max.forSubjectLess { toBe(1) }
|
||||
) {})
|
||||
|
||||
include(object : AssertionCreatorSpec<Iterable<Int>>(
|
||||
describePrefix, listOf(-20,20,0),
|
||||
min.forAssertionCreatorSpec("$toBeDescr: -20") { toBe(-20) },
|
||||
max.forAssertionCreatorSpec("$toBeDescr: 20") { toBe(20) }
|
||||
) {})
|
||||
|
||||
fun describeFun(vararg pairs: SpecPair<*>, body: Suite.() -> Unit) =
|
||||
@@ -54,4 +68,62 @@ abstract class IterableAssertionsSpec(
|
||||
}.toThrow<AssertionError> { messageContains("$hasNotDescriptionBasic: $nextElement") }
|
||||
}
|
||||
}
|
||||
|
||||
describeFun(minFeature, min, maxFeature, max) {
|
||||
val minFunctions = unifySignatures(minFeature, min)
|
||||
val maxFunctions = unifySignatures(maxFeature, max)
|
||||
|
||||
context("list with 4 and 3") {
|
||||
val fluent = expect(listOf(4, 3) as Iterable<Int>)
|
||||
minFunctions.forEach { (name, minFun, _) ->
|
||||
it("$name - is greater than 2 holds") {
|
||||
fluent.minFun { isGreaterThan(2) }
|
||||
}
|
||||
it("$name - is less than 2 fails") {
|
||||
expect {
|
||||
fluent.minFun { isLessThan(2) }
|
||||
}.toThrow<AssertionError> {
|
||||
messageContains("min(): 3")
|
||||
}
|
||||
}
|
||||
}
|
||||
maxFunctions.forEach { (name, maxFun, _) ->
|
||||
it("$name - toBe(4) holds") {
|
||||
fluent.maxFun { toBe(4) }
|
||||
}
|
||||
it("$name - toBe(3) fails") {
|
||||
expect {
|
||||
fluent.maxFun { toBe(3) }
|
||||
}.toThrow<AssertionError> {
|
||||
messageContains("max(): 4")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
context("empty list") {
|
||||
val emptyIterable = expect(emptyList<Int>() as Iterable<Int>)
|
||||
val noElementsDescr = DescriptionIterableAssertion.NO_ELEMENTS.getDefault()
|
||||
|
||||
minFunctions.forEach { (name, minFun, _) ->
|
||||
it("$name - fails warning about empty iterable") {
|
||||
expect {
|
||||
emptyIterable.minFun { toBe(1) }
|
||||
}.toThrow<AssertionError> {
|
||||
messageContains(noElementsDescr)
|
||||
}
|
||||
}
|
||||
}
|
||||
maxFunctions.forEach { (name, maxFun, _) ->
|
||||
it("$name - fails warning about empty iterable") {
|
||||
expect {
|
||||
emptyIterable.maxFun { toBe(1) }
|
||||
}.toThrow<AssertionError> {
|
||||
messageContains(noElementsDescr)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user