Skip to content

Commit 5b45a92

Browse files
committed
Introduce ability to override 'build/nebulatest' for projectDir on testkit based specs
1 parent b3de807 commit 5b45a92

File tree

4 files changed

+50
-5
lines changed

4 files changed

+50
-5
lines changed

src/main/groovy/nebula/test/IntegrationBase.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ abstract trait IntegrationBase {
3838

3939
private static final String LOGGING_LEVEL_ENV_VARIABLE = "NEBULA_TEST_LOGGING_LEVEL"
4040

41-
def initialize(Class<?> testClass, String testMethodName) {
42-
projectDir = new File("build/nebulatest/${testClass.canonicalName}/${testMethodName.replaceAll(/\W+/, '-')}").absoluteFile
41+
def initialize(Class<?> testClass, String testMethodName, String baseFolderName = 'nebulatest') {
42+
projectDir = new File("build/${baseFolderName}/${testClass.canonicalName}/${testMethodName.replaceAll(/\W+/, '-')}").absoluteFile
4343
if (projectDir.exists()) {
4444
projectDir.deleteDir()
4545
}

src/main/groovy/nebula/test/IntegrationTestKitBase.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ abstract trait IntegrationTestKitBase extends IntegrationBase {
4949
boolean definePluginOutsideOfPluginBlock = false
5050

5151
@Override
52-
def initialize(Class<?> testClass, String testMethodName) {
53-
super.initialize(testClass, testMethodName)
52+
def initialize(Class<?> testClass, String testMethodName, String baseFolderName = 'nebulatest') {
53+
super.initialize(testClass, testMethodName, baseFolderName)
5454
if (!settingsFile) {
5555
settingsFile = new File(projectDir, "settings.gradle")
5656
settingsFile.text = "rootProject.name='${moduleName}'\n"

src/main/groovy/nebula/test/IntegrationTestKitSpec.groovy

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ abstract class IntegrationTestKitSpec extends Specification implements Integrati
2424
@Rule
2525
TestName testName = new TestName()
2626

27+
String getProjectBaseFolderName() {
28+
return 'nebulatest'
29+
}
30+
2731
void setup() {
28-
IntegrationTestKitBase.super.initialize(getClass(), testName.methodName)
32+
IntegrationTestKitBase.super.initialize(getClass(), testName.methodName, getProjectBaseFolderName())
2933
}
3034

3135
void cleanup() {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
*
3+
* Copyright 2020 Netflix, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
package nebula.test
20+
21+
class IntegrationTestKitSpecCustomBaseFolderSpec extends IntegrationTestKitSpec {
22+
23+
def setup() {
24+
// used to test trait & groovy setup method https://stackoverflow.com/questions/56464191/public-groovy-method-must-be-public-says-the-compiler
25+
}
26+
27+
def cleanup() {
28+
// used to test trait & groovy cleanup method https://stackoverflow.com/questions/56464191/public-groovy-method-must-be-public-says-the-compiler
29+
}
30+
31+
@Override
32+
String getProjectBaseFolderName() {
33+
return 'notnebulatest'
34+
}
35+
36+
def 'can override project dir base folder name'() {
37+
expect:
38+
!projectDir.absolutePath.contains("/build/nebulatest/")
39+
projectDir.absolutePath.contains("/build/notnebulatest/")
40+
}
41+
}

0 commit comments

Comments
 (0)