1
1
package com.github.jrubygradle.jar
2
2
3
- import com.github.jrubygradle.JRubyPlugin
4
3
import com.github.jrubygradle.JRubyPrepare
5
4
import org.gradle.api.InvalidUserDataException
6
5
import org.gradle.api.Project
7
6
import org.gradle.api.Task
8
- import org.gradle.api.artifacts.Configuration
9
7
import org.gradle.api.file.FileCollection
10
8
import org.gradle.testfixtures.ProjectBuilder
11
- import spock.lang.*
9
+ import spock.lang.Specification
12
10
13
- import static org.gradle.api.logging.LogLevel.LIFECYCLE
11
+ import static com.github.jrubygradle.jar.JRubyJar.DEFAULT_MAIN_CLASS
14
12
15
13
/**
16
14
* @author R. Tyler Croy
@@ -19,8 +17,6 @@ import static org.gradle.api.logging.LogLevel.LIFECYCLE
19
17
*
20
18
*/
21
19
class JRubyJarPluginSpec extends Specification {
22
- static final File TESTROOT = new File (" ${ System.getProperty('TESTROOT') ?: 'build/tmp/test/unittests'} /jrjps" )
23
- static final File TESTREPO_LOCATION = new File (" ${ System.getProperty('TESTREPO_LOCATION') ?: 'build/tmp/test/repo'} " )
24
20
25
21
Project project
26
22
JRubyJar jarTask
@@ -36,18 +32,15 @@ class JRubyJarPluginSpec extends Specification {
36
32
static Project setupProject () {
37
33
Project project = ProjectBuilder . builder(). build()
38
34
project. gradle. startParameter. offline = true
39
- File repo = project. file(" ${ TESTREPO_LOCATION} /../../../../../jruby-gradle-base-plugin/src/integTest/mavenrepo" )
40
-
41
- project. buildDir = TESTROOT
42
35
43
36
project. with {
44
37
apply plugin : ' com.github.jruby-gradle.jar'
45
38
jruby. defaultRepositories = false
46
39
47
40
repositories {
48
- flatDir dirs : TESTREPO_LOCATION . absolutePath
41
+ flatDir dirs : project . file( ' fakerepo ' )
49
42
maven {
50
- url " file://" + repo . absolutePath
43
+ url " file://" + project . file( ' fakerepo ' ) . absolutePath
51
44
}
52
45
}
53
46
}
@@ -56,30 +49,26 @@ class JRubyJarPluginSpec extends Specification {
56
49
}
57
50
58
51
void setup () {
59
- if (TESTROOT . exists()) {
60
- TESTROOT . deleteDir()
61
- }
62
- TESTROOT . mkdirs()
63
-
64
52
project = setupProject()
65
53
jarTask = project. tasks. getByName(' jrubyJar' )
66
54
}
67
55
68
- def ' Checking tasks exist' () {
56
+ void ' Checking tasks exist' () {
69
57
expect :
70
58
project. tasks. getByName(' jrubyJar' )
71
59
}
72
60
73
- def ' Checking appendix' () {
61
+ void ' Checking appendix' () {
74
62
expect :
75
63
project. tasks. getByName(' jrubyJar' ). appendix == ' jruby'
76
64
}
77
65
78
- def " Fails on adding non-existing initScript" () {
66
+ void " Fails on adding non-existing initScript" () {
79
67
given :
68
+ def TESTROOT = new File (project. projectDir, ' fake' )
80
69
project. jruby. gemInstallDir = TESTROOT . absolutePath
81
- new File (TESTROOT ,' gems' ). mkdirs()
82
- new File (TESTROOT ,' gems/fake.txt' ). text = ' fake.content'
70
+ new File (TESTROOT , ' gems' ). mkdirs()
71
+ new File (TESTROOT , ' gems/fake.txt' ). text = ' fake.content'
83
72
84
73
when : " Setting a default main class"
85
74
project. configure(jarTask) {
@@ -91,19 +80,7 @@ class JRubyJarPluginSpec extends Specification {
91
80
thrown(InvalidUserDataException )
92
81
}
93
82
94
- def " Adding a default main class" () {
95
- when : " Setting a default main class"
96
- project. configure(jarTask) {
97
- defaultMainClass()
98
- }
99
- jarTask. addJRubyDependency()
100
- jarTask. applyConfig()
101
-
102
- then : " Then the attribute should be set to the default in the manifest"
103
- jarTask. manifest. attributes. ' Main-Class' == JRubyJar . DEFAULT_MAIN_CLASS
104
- }
105
-
106
- def " Adding a default extracting main class" () {
83
+ void " Adding a default extracting main class" () {
107
84
when : " Setting a default extracting main class"
108
85
project. configure(jarTask) {
109
86
extractingMainClass()
@@ -114,7 +91,7 @@ class JRubyJarPluginSpec extends Specification {
114
91
jarTask. manifest. attributes. ' Main-Class' == JRubyJar . EXTRACTING_MAIN_CLASS
115
92
}
116
93
117
- def " Adding a custom main class" () {
94
+ void " Adding a custom main class" () {
118
95
when : " Setting a default main class"
119
96
project. configure(jarTask) {
120
97
mainClass ' org.scooby.doo.snackMain'
@@ -125,7 +102,7 @@ class JRubyJarPluginSpec extends Specification {
125
102
jarTask. manifest. attributes. ' Main-Class' == ' org.scooby.doo.snackMain'
126
103
}
127
104
128
- def " Adding a main class and additional manifest attributes" () {
105
+ void " Adding a main class and additional manifest attributes" () {
129
106
when : " Setting a main class"
130
107
project. configure(jarTask) {
131
108
mainClass ' org.scooby.doo.snackMain'
@@ -137,14 +114,15 @@ class JRubyJarPluginSpec extends Specification {
137
114
jarTask. manifest. attributes. ' Class-Path' == ' gangway.jar zoinks.jar'
138
115
}
139
116
140
- def " Setting up a java project" () {
117
+ void " Setting up a java project" () {
141
118
given : " All jar, java plugins have been applied"
119
+ def TESTROOT = new File (project. projectDir, ' TESTROOT' )
142
120
project = setupProject()
143
- project. apply plugin : ' java'
121
+ project. apply plugin : ' java'
144
122
Task jar = project. tasks. getByName(' jrubyJar' )
145
123
146
124
and : " A local repository"
147
- File expectedDir= new File (TESTROOT ,' libs/' )
125
+ File expectedDir = new File (TESTROOT , ' libs/' )
148
126
expectedDir. mkdirs()
149
127
project. configure(jar) {
150
128
initScript library()
@@ -155,19 +133,19 @@ class JRubyJarPluginSpec extends Specification {
155
133
jar. taskDependencies. getDependencies(jar). contains(project. tasks. getByName(' prepareJRubyJar' ))
156
134
}
157
135
158
- def ' Checking setting no mainClass' () {
136
+ void ' Checking setting no mainClass' () {
159
137
when :
160
- project. file( ' app.rb' ) << ' '
138
+ project. file(' app.rb' ) << ' '
161
139
jarTask. initScript(' app.rb' )
162
140
jarTask. applyConfig()
163
141
164
142
then :
165
- jarTask. manifest. attributes[' Main-Class' ] == JRubyJar . DEFAULT_MAIN_CLASS
143
+ jarTask. manifest. attributes[' Main-Class' ] == DEFAULT_MAIN_CLASS
166
144
}
167
145
168
- def ' Checking setting of mainClass once' () {
146
+ void ' Checking setting of mainClass once' () {
169
147
when :
170
- project. file( ' app.rb' ) << ' '
148
+ project. file(' app.rb' ) << ' '
171
149
jarTask. initScript(' app.rb' )
172
150
jarTask. mainClass(' org.example.Main' )
173
151
jarTask. applyConfig()
@@ -176,7 +154,7 @@ class JRubyJarPluginSpec extends Specification {
176
154
jarTask. manifest. attributes[' Main-Class' ] == ' org.example.Main'
177
155
}
178
156
179
- def ' Checking setup runnable jrubyJar task' () {
157
+ void ' Checking setup runnable jrubyJar task' () {
180
158
when :
181
159
jarTask. initScript(jarTask. runnable())
182
160
jarTask. applyConfig()
@@ -185,7 +163,7 @@ class JRubyJarPluginSpec extends Specification {
185
163
jarTask. manifest. attributes. containsKey(' Main-Class' )
186
164
}
187
165
188
- def ' Checking valid library config' () {
166
+ void ' Checking valid library config' () {
189
167
when :
190
168
jarTask. initScript(jarTask. library())
191
169
jarTask. applyConfig()
@@ -194,7 +172,7 @@ class JRubyJarPluginSpec extends Specification {
194
172
! jarTask. manifest. attributes. containsKey(' Main-Class' )
195
173
}
196
174
197
- def ' Checking invalid library config' () {
175
+ void ' Checking invalid library config' () {
198
176
when :
199
177
jarTask. initScript(jarTask. library())
200
178
jarTask. extractingMainClass()
@@ -205,37 +183,8 @@ class JRubyJarPluginSpec extends Specification {
205
183
e. message == ' can not have mainClass for library'
206
184
}
207
185
208
- @Ignore (' should be an integration test since we add jar-dependencies' )
209
- @Issue (' https://github.com/jruby-gradle/jruby-gradle-plugin/issues/115' )
210
- def " jrubyVersion is lazily evaluated" () {
211
- given :
212
- final String version = ' 1.7.11'
213
-
214
- when :
215
- project. jruby {
216
- defaultVersion version
217
- }
218
- project. evaluate()
219
-
220
- then :
221
- project. tasks. findByName(' jrubyJar' ). jrubyVersion == version
222
- }
223
-
224
- def " prepareTask should be an instance of JRubyPrepare" () {
186
+ void " prepareTask should be an instance of JRubyPrepare" () {
225
187
expect :
226
188
jarTask. dependsOn. find { (it instanceof JRubyPrepare ) && (it. name == ' prepareJRubyJar' ) }
227
189
}
228
-
229
- @Ignore (' should be an integration test since we add jar-dependencies' )
230
- def " prepareTask should have its configuration lazily set" () {
231
- given :
232
- Task prepareTask = jarTask. dependsOn. find { it instanceof JRubyPrepare }
233
-
234
- when :
235
- project. evaluate()
236
-
237
- then :
238
- prepareTask. dependencies. find { (it instanceof Configuration ) && (it. name == jarTask. configuration) }
239
- }
240
- }
241
-
190
+ }
0 commit comments