Skip to content

Commit eee078a

Browse files
authored
Clarify that only one data provider is combined with one other per combined label (#2118)
1 parent f8109fe commit eee078a

File tree

2 files changed

+148
-0
lines changed

2 files changed

+148
-0
lines changed

docs/data_driven_testing.adoc

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,37 @@ NOTE: If a data table takes part in a cross-multiplication, accessing columns of
342342
data tables would not behave in an intuitive way and thus is currently forbidden. Accessing
343343
previous columns within one data table even works while taking part in a cross-multiplication.
344344

345+
[NOTE]
346+
--
347+
Only the data provider right before the `combined:` label is
348+
combined with the data provider right after the `combined:` label.
349+
350+
So if you execute
351+
[source,groovy,indent=0]
352+
----
353+
include::{sourcedir}/datadriven/DataSpec.groovy[tag=single-data-providers-combined1]
354+
----
355+
it will result in these executed tests:
356+
357+
include::./{sourcedir}/datadriven/DataSpec.groovy[tag=single-data-providers-combined-result1,indent=0]
358+
359+
If you want to combine `a` and `b` with `c` to get this result:
360+
361+
include::./{sourcedir}/datadriven/DataSpec.groovy[tag=single-data-providers-combined-result2,indent=0]
362+
363+
you have to for example use
364+
[source,groovy,indent=0]
365+
----
366+
include::{sourcedir}/datadriven/DataSpec.groovy[tag=single-data-providers-combined2]
367+
----
368+
or
369+
[source,groovy,indent=0]
370+
----
371+
include::{sourcedir}/datadriven/DataSpec.groovy[tag=single-data-providers-combined3]
372+
----
373+
--
374+
375+
345376
== Data Variable Assignment
346377

347378
A data variable can be directly assigned a value:

spock-specs/src/test/groovy/org/spockframework/docs/datadriven/DataSpec.groovy

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,123 @@ class DataSpec extends EmbeddedSpecification {
194194
}`""" == expected
195195
}
196196

197+
def "only single data providers are combined"() {
198+
given:
199+
def expected = '''
200+
tag::single-data-providers-combined-result1[]
201+
- `feature [a: 1, b: 5, c: 7, #0]`
202+
- `feature [a: 2, b: 5, c: 8, #1]`
203+
- `feature [a: 3, b: 6, c: 7, #2]`
204+
- `feature [a: 4, b: 6, c: 8, #3]`
205+
end::single-data-providers-combined-result1[]
206+
'''
207+
.stripIndent(*(GroovyRuntimeUtil.groovy3orNewer ? [true] : []))
208+
.readLines()
209+
.findAll {it.startsWith('-') }
210+
.join('\n')
211+
.trim()
212+
213+
when:
214+
def result = runner.runSpecBody '''
215+
def feature() {
216+
expect:
217+
true
218+
219+
// tag::single-data-providers-combined1[]
220+
where:
221+
a << [1, 2, 3, 4]
222+
b << [5, 6]
223+
combined:
224+
c << [7, 8]
225+
// end::single-data-providers-combined1[]
226+
}
227+
'''
228+
229+
then:
230+
"""- `${
231+
result
232+
.testEvents()
233+
.succeeded()
234+
.list()
235+
*.testDescriptor
236+
.findAll { it.type == TEST }
237+
*.displayName
238+
.join('`\n- `')
239+
}`""" == expected
240+
241+
when:
242+
expected = '''
243+
tag::single-data-providers-combined-result2[]
244+
- `feature [a: 1, b: 3, c: 5, #0]`
245+
- `feature [a: 1, b: 3, c: 6, #1]`
246+
- `feature [a: 2, b: 4, c: 5, #2]`
247+
- `feature [a: 2, b: 4, c: 6, #3]`
248+
end::single-data-providers-combined-result2[]
249+
'''
250+
.stripIndent(*(GroovyRuntimeUtil.groovy3orNewer ? [true] : []))
251+
.readLines()
252+
.findAll {it.startsWith('-') }
253+
.join('\n')
254+
.trim()
255+
result = runner.runSpecBody '''
256+
def feature() {
257+
expect:
258+
true
259+
260+
// tag::single-data-providers-combined2[]
261+
where:
262+
[a, b] << [
263+
[1, 2],
264+
[3, 4]
265+
].transpose()
266+
combined:
267+
c << [5, 6]
268+
// end::single-data-providers-combined2[]
269+
}
270+
'''
271+
272+
then:
273+
"""- `${
274+
result
275+
.testEvents()
276+
.succeeded()
277+
.list()
278+
*.testDescriptor
279+
.findAll { it.type == TEST }
280+
*.displayName
281+
.join('`\n- `')
282+
}`""" == expected
283+
284+
when:
285+
result = runner.runSpecBody '''
286+
def feature() {
287+
expect:
288+
true
289+
290+
// tag::single-data-providers-combined3[]
291+
where:
292+
a | b
293+
1 | 3
294+
2 | 4
295+
combined:
296+
c << [5, 6]
297+
// end::single-data-providers-combined3[]
298+
}
299+
'''
300+
301+
then:
302+
"""- `${
303+
result
304+
.testEvents()
305+
.succeeded()
306+
.list()
307+
*.testDescriptor
308+
.findAll { it.type == TEST }
309+
*.displayName
310+
.join('`\n- `')
311+
}`""" == expected
312+
}
313+
197314
// tag::sql-data-pipe[]
198315
def "maximum of two numbers"() {
199316
expect:

0 commit comments

Comments
 (0)