Skip to content

Commit 9e3ffe4

Browse files
authored
Merge pull request #165 from matrei/merge-4.2.x-into-5.0.x
Merge 4.2.x into 5.0.x
2 parents fa506ea + 500bc34 commit 9e3ffe4

File tree

4 files changed

+133
-8
lines changed

4 files changed

+133
-8
lines changed

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ Parallel execution of `ContainerGebSpec` specifications is not currently support
5959

6060
#### Custom Host Configuration
6161

62-
The annotation `ContainerGebConfiguration` exists to customize the connection the container will use to access the application under test. The annotation is not required and `ContainerGebSpec` will use the default values in this annotation if it's not present. A traditional `GebConfig.groovy` can be provided to configure non-container specific settings.
62+
The annotation `ContainerGebConfiguration` exists to customize the connection the container will use to access the application under test.
63+
The annotation is not required and `ContainerGebSpec` will use the default values in this annotation if it's not present.
64+
65+
The interface `IContainerGebConfiguration` exists as an inheritable version of the annotation.
6366

6467
#### Reporting
6568

@@ -73,10 +76,12 @@ To configure reporting, enable it using the `recording` property on the annotati
7376

7477
By default, no test recording will be performed. Various system properties exist to change the recording behavior. To set them, you can set them in your `build.gradle` file like so:
7578

76-
tasks.withType(Test) {
77-
useJUnitPlatform()
78-
systemProperty 'grails.geb.recording.mode', 'RECORD_ALL'
79-
}
79+
```groovy
80+
tasks.withType(Test).configureEach {
81+
useJUnitPlatform()
82+
systemProperty('grails.geb.recording.mode', 'RECORD_ALL')
83+
}
84+
```
8085

8186
* `grails.geb.recording.mode`
8287
* purpose: which tests to record
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package org.demo.spock
2+
3+
import grails.plugin.geb.ContainerGebConfiguration
4+
import grails.plugin.geb.IContainerGebConfiguration
5+
import grails.plugin.geb.ContainerGebSpec
6+
import grails.testing.mixin.integration.Integration
7+
8+
/**
9+
* Adaptation of {@link ServerNameControllerSpec}
10+
*/
11+
@Integration
12+
class SuperSpec extends ContainerGebSpec implements IContainerGebConfiguration {
13+
@Override
14+
String hostName() {
15+
return 'super.example.com'
16+
}
17+
}
18+
19+
@Integration
20+
@ContainerGebConfiguration(hostName = 'not.example.com')
21+
class NotSuperSpec extends ContainerGebSpec {}
22+
23+
@Integration
24+
class InheritedConfigSpec extends SuperSpec {
25+
void 'should show the right server name when visiting /serverName'() {
26+
when: 'visiting the server name controller'
27+
go '/serverName'
28+
29+
then: 'the emitted hostname is correct'
30+
$('p').text() == 'Server name: super.example.com'
31+
}
32+
}
33+
34+
@Integration
35+
class NotInheritedConfigSpec extends NotSuperSpec {
36+
void 'should show the right server name when visiting /serverName'() {
37+
when: 'visiting the server name controller'
38+
go '/serverName'
39+
40+
then: 'the emitted hostname is correct'
41+
$('p').text() != 'Server name: not.example.com'
42+
}
43+
}
44+
45+
@Integration
46+
class ChildPreferenceInheritedConfigSpec extends SuperSpec {
47+
@Override
48+
String hostName() {
49+
return 'child.example.com'
50+
}
51+
52+
void 'should show the right server name when visiting /serverName'() {
53+
when: 'visiting the server name controller'
54+
go '/serverName'
55+
56+
then: 'the emitted hostname is correct'
57+
$('p').text() == 'Server name: child.example.com'
58+
59+
when:
60+
report('whatever')
61+
62+
then:
63+
// geb.test.GebTestManager: "Reporting has not been enabled on this GebTestManager yet report() was called"
64+
Throwable t = thrown(Exception)
65+
t.message.contains("not been enabled")
66+
}
67+
}
68+
69+
// No sane person would do this, but lets test anyway
70+
@Integration
71+
class SuperSuperInheritedConfigSpec extends SuperSpec {
72+
@Override
73+
boolean reporting() {
74+
return true
75+
}
76+
}
77+
78+
@Integration
79+
class MultipleInheritanceSpec extends SuperSuperInheritedConfigSpec {
80+
void 'should show the right server name when visiting /serverName'() {
81+
when: 'visiting the server name controller'
82+
go '/serverName'
83+
84+
then: 'the emitted hostname is correct'
85+
$('p').text() == 'Server name: super.example.com'
86+
report('multi inheritance report')
87+
}
88+
}

src/testFixtures/groovy/grails/plugin/geb/ContainerGebConfiguration.groovy

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,27 @@ import java.lang.annotation.Target
6565
*/
6666
Class<? extends ContainerFileDetector> fileDetector() default DefaultContainerFileDetector
6767
}
68+
69+
/**
70+
* Inheritable version of {@link ContainerGebConfiguration}
71+
*
72+
* @since 4.2
73+
*/
74+
interface IContainerGebConfiguration {
75+
76+
default String protocol() {
77+
ContainerGebConfiguration.DEFAULT_PROTOCOL
78+
}
79+
80+
default String hostName() {
81+
ContainerGebConfiguration.DEFAULT_HOSTNAME_FROM_CONTAINER
82+
}
83+
84+
default boolean reporting() {
85+
false
86+
}
87+
88+
default Class<? extends ContainerFileDetector> fileDetector() {
89+
ContainerGebConfiguration.DEFAULT_FILE_DETECTOR
90+
}
91+
}

src/testFixtures/groovy/grails/plugin/geb/WebDriverContainerHolder.groovy

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,17 @@ class WebDriverContainerHolder {
212212
Class<? extends ContainerFileDetector> fileDetector
213213

214214
WebDriverContainerConfiguration(SpecInfo spec) {
215-
ContainerGebConfiguration configuration = spec.annotations.find {
216-
it.annotationType() == ContainerGebConfiguration
217-
} as ContainerGebConfiguration
215+
ContainerGebConfiguration configuration
216+
217+
// Check if the class implements the interface
218+
if (IContainerGebConfiguration.isAssignableFrom(spec.reflection)) {
219+
configuration = spec.reflection.getConstructor().newInstance() as ContainerGebConfiguration
220+
} else {
221+
// Check for the annotation
222+
configuration = spec.annotations.find {
223+
it.annotationType() == ContainerGebConfiguration
224+
} as ContainerGebConfiguration
225+
}
218226

219227
protocol = configuration?.protocol() ?: ContainerGebConfiguration.DEFAULT_PROTOCOL
220228
hostName = configuration?.hostName() ?: ContainerGebConfiguration.DEFAULT_HOSTNAME_FROM_CONTAINER

0 commit comments

Comments
 (0)