Why does this matter?
Spock's implicit assertions provide an ergonomic way of defining conditions by avoiding repeating invocations of assertion methods:
expect:
expectedValue == actualValue
Furthermore, Spock provides helper methods like with(target, closure), verifyEach(target, closure) and verifyAll(target, closure). These methods allow users to define implicit assertions on more complex objects, such as collections.
The goal of this story is to provide a similar experience with Spockk. In contrast to Spock, Spockk does not implement assertions destructuring itself, but provides it via the power-assert compiler plugin. This behavior should stay.
What should developers be able to write?
class SpecWithImplicitAssertions : Specfication() {
def "feature with implicit assertions"() {
given
val a = 1
val b = 2
expect
a < b
}
def "feature with implicit assertions for custom objects"() {
given
val person = Person(firstname: "A", lastname: "B")
expect
verify(person) { // verify should replace Spock's with(...)
it.firstname == "A"
it.lastname == "B"
}
}
def "feature with implicit assertions for collections"() {
given
val list = listOf(1, 2, 3)
expect
verifyEach(list) {
it % 2 == 0
}
}
}
Acceptance criteria
How does Spock implement this?
No response
Additional context
Users should be able to opt-out of implicit assertions
The plugin should establish the following extension for a Gradle project that applies the plugin:
spockk {
features {
enable(SpockkFeature.IMPLICIT_ASSERTIONS)
disable(SpockkFeature.IMPLICIT_ASSERTIONS)
}
}
The features configuration allows users to determine whether features like implicit assertions should be enabled or disabled. SpockkFeature should be an enum that has a description of the feature and the default boolean value indicating whether it is enabled or not.
Why does this matter?
Spock's implicit assertions provide an ergonomic way of defining conditions by avoiding repeating invocations of assertion methods:
Furthermore, Spock provides helper methods like
with(target, closure),verifyEach(target, closure)andverifyAll(target, closure). These methods allow users to define implicit assertions on more complex objects, such as collections.The goal of this story is to provide a similar experience with Spockk. In contrast to Spock, Spockk does not implement assertions destructuring itself, but provides it via the
power-assertcompiler plugin. This behavior should stay.What should developers be able to write?
Acceptance criteria
verifyhelper instead of awithhelperverifyAllmust be evaluatedverifyEachallows defining implicit conditions for collectionskotlin.test.assertTruekotlin.testdependency is available and notify the user about itHow does Spock implement this?
No response
Additional context
Users should be able to opt-out of implicit assertions
The plugin should establish the following extension for a Gradle project that applies the plugin:
The features configuration allows users to determine whether features like implicit assertions should be enabled or disabled. SpockkFeature should be an enum that has a description of the feature and the default boolean value indicating whether it is enabled or not.