Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,25 @@ that brings its expressive BDD-style syntax for Groovy to Kotlin.
## Sneak peek

```kotlin
import io.github.pshevche.spockk.lang.and
import io.github.pshevche.spockk.lang.given
import io.github.pshevche.spockk.lang.`when`
import io.github.pshevche.spockk.lang.then

import io.github.pshevche.spockk.lang.`when`
import io.github.pshevche.spockk.lang.where
import spock.lang.Specification
import kotlin.test.assertEquals

class MyFirstSpecification : Specification() {
fun `adding an element to a list`() {
given
val myList = mutableListOf<Int>()

class MathTest : Specification() {
fun `sum of two numbers`(a: Int, b: Int, expectedSum: Int) {
`when`
myList.add(1)

and
myList.add(2)
val sum = a + b

then
assert(myList.size == 2)
assertEquals(expectedSum, sum)

where
a ; b ; expectedSum
1 ; 3 ; 4
7 ; 4 ; 11
0 ; 0 ; 0
}
}
```
Expand Down
10 changes: 9 additions & 1 deletion spockk-docs/docs/changelog.adoc
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
== Changelog

=== v0.2.0

- [Core] Added support for data-driven features
- [Core] Introduced experimental support for Spock extensions
- [Core] Added support for Kotlin 2.3.0
- [IntelliJ Plugin] Added syntax support for Spock’s data-driven features
- [IntelliJ Plugin] Integrated with Spock’s native IntelliJ plugin

=== v0.1.0

- [Core] Implement rich BDD-style syntax for defining test features
- [IntelliJ plugin] Detect Spockk syntax in test sources
- [IntelliJ plugin] Execute Spockk tests with Gradle from IDE
- [IntelliJ plugin] Execute Spockk tests with Gradle from IDE
116 changes: 116 additions & 0 deletions spockk-docs/docs/data_driven_testing.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
== Data Driven Testing

The following section describes how Spock's data-driven features can be defined in Kotlin using the Spockk add-on.
For general information about data-driven features and runtime behavior, consult Spock's https://spockframework.org/spock/docs/2.4/data_driven_testing.html[reference documentation].

[[data-tables]]
=== Data Tables

Data tables are a convenient way to exercise a feature method with a fixed set of data values:

[source,kotlin,indent=0]
----
class MathSpec : Specification() {
fun `maximum of two numbers`(a: Int, b: Int, c: Int) {
expect
assertEquals(c, max(a, b))

where
a ; b ; c
1 ; 3 ; 3
7 ; 4 ; 7
0 ; 0 ; 0
}
}
----

The first line of the table, called the _table header_, declares the data variables.
The subsequent lines, called
_table rows_, hold the corresponding values.
For each row, the feature method will get executed once; we call this an
_iteration_ of the method.
If an iteration fails, the remaining iterations will nevertheless be executed.
All failures will be reported.

[tip]
====
For a seamless formatting experience, install Spockk IntelliJ plugin and set the following ktlint configuration:

[source,indent=0]
----
ktlint_standard_statement-wrapping = disabled
ktlint_standard_no-multi-spaces = disabled
----
====

Data tables must have at least two columns.
A single-column table can be written as:

[source,kotlin,indent=0]
----
where
a ; `_`
1 ; `_`
7 ; `_`
0 ; `_`
----

=== Data Pipes

Data tables aren't the only way to supply values to data variables.
In fact, a data table is just syntactic sugar for one or more _data pipes_:

[source,kotlin,indent=0]
----
...
where
variable(a).from(1, 7, 0)
variables(b, c).from(listOf(3, 4, 0), listOf(3, 7, 0))
----

A data pipe, indicated by the `variable(<feature_var>).from(<var_values>)` construct, connects a data variable to a _data provider_.
The data provider holds all values for the variable, one per iteration.

=== Accessing Other Data Variables

There are only two possibilities to access one data variable from the calculation of another data variable.

The first possibility are derived data variables where the variable is defined to have a single value and it is equal to another variable.
Every data variable that is defined this way can access all previously defined data variables, including the ones defined through data tables or data pipes:

[source,kotlin,indent=0]
----
...
where
variable(a).from(1, 2, 3)
variable(b).from(a)
----

The second possibility is to access previous columns within data tables:

[source,kotlin,indent=0]
----
...
where
a ; b
3 ; a + 1
7 ; a + 2
0 ; a + 3
----

=== Combining Data Tables, Data Pipes, and Variable Assignments

Data tables, data pipes, and variable assignments can be combined as needed:

[source,kotlin,indent=0]
----
...
where
a ; b
1 ; a + 1
7 ; a + 2
0 ; a + 3

variable(c).from(3, 4, 0)
variable(d).from(c)
----
2 changes: 2 additions & 0 deletions spockk-docs/docs/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ include::getting_started.adoc[]

include::writing_tests.adoc[]

include::data_driven_testing.adoc[]

include::changelog.adoc[]
6 changes: 4 additions & 2 deletions spockk-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ gradlePlugin {

val isCI = System.getenv("CI") != null
val isFork = System.getenv("IS_FORK") == "true"
val isSigningRequired = isCI && !isFork

if (isCI && !isFork) {
signing {
signing {
isRequired = isSigningRequired
if (isSigningRequired) {
useInMemoryPgpKeys(
System.getenv("ORG_GRADLE_PROJECT_signingInMemoryKeyId"),
System.getenv("ORG_GRADLE_PROJECT_signingInMemoryKey"),
Expand Down
4 changes: 2 additions & 2 deletions spockk-intellij-plugin/docs/release-notes.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<ul>
<li>[NEW] Detect Spockk syntax in test sources</li>
<li>[NEW] Execute Spockk tests with Gradle from IDE</li>
<li>[NEW] Support syntax for Spockk's data-driven features</li>
<li>[NEW] Integrate with Spock's native IntelliJ plugin</li>
</ul>