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
/*
* Copyright 2009 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.
*/

import groovy.sql.Sql
import spock.lang.Shared
import spock.lang.Specification

class DatabaseDriven extends Specification {
@Shared sql = Sql.newInstance("jdbc:h2:mem:", "org.h2.Driver")

// insert data (usually the database would already contain the data)
def setupSpec() {
sql.execute("create table maxdata (id int primary key, a int, b int, c int)")
sql.execute("insert into maxdata values (1, 3, 7, 7), (2, 5, 4, 5), (3, 9, 9, 9)")
}

def "maximum of two numbers"() {
expect:
Math.max(a, b) == c

where:
[a, b, c] << sql.rows("select a, b, c from maxdata")
}
}

Change log

r1095 by pniederw on Aug 11, 2010   Diff
added @AutoCleanup extension
Go to: 

Older revisions

r656 by pniederw on Oct 28, 2009   Diff
deprecated @Speck
renamed "setupSpeck" to "setupSpec",
and "cleanupSpeck" to "cleanupSpec"
(old names still work for now)
added spec FixtureMethods
r541 by pniederw on Oct 2, 2009   Diff
upgraded to Groovy 1.6.5 and fixed all
problems resulting thereof
r539 by pniederw on Sep 29, 2009   Diff
MainTransform's AST node cache is now
reused across compilations
All revisions of this file

File info

Size: 1219 bytes, 37 lines
Powered by Google Project Hosting