My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/*
* Copyright 2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.spockframework.smoke.parameterization

import org.junit.internal.runners.model.MultipleFailureException

import org.spockframework.EmbeddedSpecification
import org.spockframework.compiler.InvalidSpecCompileException
import org.spockframework.runtime.SpockExecutionException

import spock.lang.*

class DataTables extends EmbeddedSpecification {
static staticField = 42

@Shared
def sharedField = 42

def instanceField = 42

def "basic usage"() {
expect:
Math.max(a, b) == c

where:
a | b | c
5 | 7 | 7
3 | 1 | 3
9 | 9 | 9
}

def "table must have at least two columns"() {
when:
compiler.compileFeatureBody """
expect:
true

where:
a
1
"""

then:
MultipleFailureException e = thrown()
e.failures*.class == [InvalidSpecCompileException] * 2
}

def "can use wildcards to effectively turn one-column table into two-column"() {
expect:
a == 1
_ == _ // won't use this in practice

where:
a | _
1 | _
}

def "table with just a header are not allowed"() {
when:
runner.runFeatureBody """
expect:
true

where:
a | b
"""

then:
thrown(SpockExecutionException)
}

def "header may only contain variable names"() {
when:
compiler.compileFeatureBody """
expect:
true

where:
a | 1 | b
1 | 1 | 1
"""

then:
thrown(InvalidSpecCompileException)
}

def "header variable names must not clash with local variables"() {
when:
compiler.compileFeatureBody """
def local = 1

expect:
true

where:
a | local
1 | 1
"""

then:
thrown(InvalidSpecCompileException)
}

def "header variable names must not clash with each other"() {
when:
compiler.compileFeatureBody """
expect:
true

where:
a | a
1 | 1
"""

then:
thrown(InvalidSpecCompileException)
}

def "columns may be declared as parameters"(a, String b) {
expect:
a == 3
b == "wow"

where:
a | b
3 | "wow"
}

def "tables can be mixed with other parameterizations"() {
expect:
[a, b, c, d] == [1, 2, 3, 4]

where:
a << [1]
b | c
2 | 3
d = c + 1
}

def "cells may contain arbitrary expressions"() {
expect:
a == "oo"
b.age == 23
c == 5

where:
a | b | c
"foo"[1..2] | new Person(age: 23) | Math.max(4, 5)
}

def "cells can reference shared and static fields"() {
expect:
a == 42
b == 42

where:
a | b
staticField | sharedField
}

@Issue("http://issues.spockframework.org/detail?id=139")
def "cells cannot reference instance fields (only @Shared and static fields)"() {
when:
compiler.compileSpecBody """
def instanceField

def foo() {
expect:
true

where:
a | b
instanceField | 1
}
"""

then:
InvalidSpecCompileException e = thrown()
e.message.contains("@Shared")
}

def "cells cannot reference local variables (won't be found)"() {
when:
runner.runFeatureBody """
def local = 42

expect:
true

where:
a | b
local | 1
"""

then:
thrown(MissingPropertyException)
}

def "cells cannot reference other cells"() {
when:
runner.runFeatureBody """
expect:
true

where:
a | b
1 | a
"""

then:
thrown(MissingPropertyException)
}

def "rows must have same number of elements as header"() {
when:
compiler.compileFeatureBody """
expect:
true

where:
a | b | c
1 | 2 | 3
4 | 5
"""

then:
thrown(InvalidSpecCompileException)
}
}

private class Person {
def age
}

Change log

r1204 by pniederw on Nov 3, 2010   Diff
fixed  Issue 139 :        The fixture
methods setupSpec(), cleanupSpec() don't
prevent direct access to instance fields
Go to: 

Older revisions

r1199 by pniederw on Oct 30, 2010   Diff
fixed  Issue 105 :        Disallow
assignments in expect- and then-blocks
fixed some spec bugs revealed by the
new check
r877 by pniederw on Mar 10, 2010   Diff
augmented spec for data tables
simplified accessing multiple compile
exceptions when working with
EmbeddedSpecCompiler
r874 by pniederw on Mar 9, 2010   Diff
first support for table-like
parameterizations
All revisions of this file

File info

Size: 4179 bytes, 245 lines
Powered by Google Project Hosting