Skip to content

Commit 3f64d0c

Browse files
authored
Convert Docs for the Spock Testframework (#2928)
Convert inline example code to use codeinclude macro for the Spock Testframework documentation See #1158 for more details.
1 parent fc03c21 commit 3f64d0c

File tree

2 files changed

+5
-31
lines changed

2 files changed

+5
-31
lines changed

docs/test_framework_integration/spock.md

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,9 @@
99
Specifying the `@Testcontainers` annotation will instruct Spock to start and stop all testcontainers accordingly. This annotation
1010
can be mixed with Spock's `@Shared` annotation to indicate, that containers shouldn't be restarted between tests.
1111

12-
```groovy
13-
@Testcontainers
14-
class DatabaseTest extends Specification {
15-
16-
@Shared
17-
PostgreSQLContainer postgreSQLContainer = new PostgreSQLContainer()
18-
.withDatabaseName("foo")
19-
.withUsername("foo")
20-
.withPassword("secret")
21-
22-
def "database is accessible"() {
23-
24-
given: "a jdbc connection"
25-
HikariConfig hikariConfig = new HikariConfig()
26-
hikariConfig.setJdbcUrl(postgreSQLContainer.jdbcUrl)
27-
hikariConfig.setUsername("foo")
28-
hikariConfig.setPassword("secret")
29-
HikariDataSource ds = new HikariDataSource(hikariConfig)
30-
31-
when: "querying the database"
32-
Statement statement = ds.getConnection().createStatement()
33-
statement.execute("SELECT 1")
34-
ResultSet resultSet = statement.getResultSet()
35-
resultSet.next()
36-
37-
then: "result is returned"
38-
int resultSetInt = resultSet.getInt(1)
39-
resultSetInt == 1
40-
}
41-
}
42-
```
12+
<!--codeinclude-->
13+
[PostgresContainerIT](../../modules/spock/src/test/groovy/org/testcontainers/spock/PostgresContainerIT.groovy) inside_block:PostgresContainerIT
14+
<!--/codeinclude-->
4315

4416
## Adding Testcontainers Spock support to your project dependencies
4517

modules/spock/src/test/groovy/org/testcontainers/spock/PostgresContainerIT.groovy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import spock.lang.Specification
99
import java.sql.ResultSet
1010
import java.sql.Statement
1111

12+
// PostgresContainerIT {
1213
@Testcontainers
1314
class PostgresContainerIT extends Specification {
1415

@@ -42,3 +43,4 @@ class PostgresContainerIT extends Specification {
4243
}
4344

4445
}
46+
// }

0 commit comments

Comments
 (0)