Skip to content

Commit 4abeb5b

Browse files
committed
Migrated tests from JRubyJarIntegrationSpec and deleted the latter
1 parent 0c0fe93 commit 4abeb5b

File tree

2 files changed

+60
-107
lines changed

2 files changed

+60
-107
lines changed

jar-plugin/src/integTest/groovy/com/github/jrubygradle/jar/JRubyJarIntegrationSpec.groovy

Lines changed: 0 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -46,104 +46,5 @@ class JRubyJarIntegrationSpec extends Specification {
4646
}
4747
}
4848

49-
def "Building a Jar with a custom configuration and 'java' plugin is applied"() {
50-
given: "Java plugin applied before JRuby Jar plugin"
51-
project.apply plugin : 'java'
52-
Task jrubyJar = project.tasks.getByName('jrubyJar')
53-
File expectedDir = new File(TESTROOT, 'libs/')
54-
File expectedJar = new File(expectedDir, 'test-jruby.jar')
55-
56-
when: "I set the main class"
57-
project.configure(jrubyJar) {
58-
mainClass 'bogus.does.not.exist'
59-
}
60-
project.evaluate()
61-
62-
and: "I actually build the JAR"
63-
jrubyJar.execute()
64-
def builtJar = fileNames(project.zipTree(expectedJar))
65-
66-
then: "I expect to see jruby.home unpacked "
67-
builtJar.contains("META-INF/jruby.home/lib/ruby".toString())
68-
69-
and: "I expect the new main class to be listed in the manifest"
70-
jrubyJar.manifest.effectiveManifest.attributes['Main-Class']?.contains('bogus.does.not.exist')
71-
}
72-
73-
def "Setting the jrubyVersion to an older version of JRuby should update jar-dependencies"() {
74-
given: "a version of JRuby which doesn't bundle jar-dependencies"
75-
Configuration config = project.configurations.create('spockConfig')
76-
final String version = '1.7.11'
77-
JRubyJar task = project.task('spock-jar', type: JRubyJar) {
78-
configuration config.name
79-
jrubyVersion version
80-
}
81-
82-
when:
83-
project.evaluate()
84-
85-
then: "the JRuby version and jar-dependencies versions should be set"
86-
config.dependencies.find { it.name == 'jar-dependencies' }
87-
}
88-
89-
@Issue("https://github.com/jruby-gradle/jruby-gradle-plugin/issues/168")
90-
def "configuring a new jrubyMainsVersion should update the dependency graph properly"() {
91-
Configuration config = project.configurations.create('spockConfig')
92-
final String version = '0.3.0'
93-
JRubyJar task = project.task('spock-jar', type: JRubyJar) {
94-
configuration config.name
95-
jrubyMainsVersion version
96-
}
97-
98-
when:
99-
project.evaluate()
100-
101-
then: "the custom version should be included in the custom config"
102-
config.dependencies.find { it.name == 'jruby-mains' && it.version == version }
103-
config.dependencies.findAll({ it.name == 'jruby-mains' }).size() == 1
104-
}
105-
106-
/*
107-
@Ignore('should be an integration test since we add jar-dependencies')
108-
def "prepareTask should have its configuration lazily set"() {
109-
given:
110-
Task prepareTask = jarTask.dependsOn.find { it instanceof JRubyPrepare }
111-
112-
when:
113-
project.evaluate()
114-
115-
then:
116-
prepareTask.dependencies.find { (it instanceof Configuration) && (it.name == jarTask.configuration) }
117-
}
118-
119-
def "Adding a default main class"() {
120-
when: "Setting a default main class"
121-
project.configure(jarTask) {
122-
defaultMainClass()
123-
}
124-
jarTask.addJRubyDependency()
125-
jarTask.applyConfig()
126-
127-
then: "Then the attribute should be set to the default in the manifest"
128-
jarTask.manifest.attributes.'Main-Class' == DEFAULT_MAIN_CLASS
129-
}
130-
131-
@Ignore('should be an integration test since we add jar-dependencies')
132-
@Issue('https://github.com/jruby-gradle/jruby-gradle-plugin/issues/115')
133-
def "jrubyVersion is lazily evaluated"() {
134-
given:
135-
final String version = '1.7.11'
136-
137-
when:
138-
project.jruby {
139-
defaultVersion version
140-
}
141-
project.evaluate()
142-
143-
then:
144-
project.tasks.findByName('jrubyJar').jrubyVersion == version
145-
}
146-
147-
*/
14849
}
14950

jar-plugin/src/integTest/groovy/com/github/jrubygradle/jar/JRubyJarTestKitSpec.groovy

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import spock.lang.Issue
99
import java.util.zip.ZipEntry
1010
import java.util.zip.ZipFile
1111

12+
import static com.github.jrubygradle.jar.JRubyJar.DEFAULT_MAIN_CLASS
13+
1214
class JRubyJarTestKitSpec extends IntegrationSpecification {
1315

1416
public static final String DEFAULT_TASK_NAME = 'jrubyJar'
@@ -17,6 +19,7 @@ class JRubyJarTestKitSpec extends IntegrationSpecification {
1719
String jrubyJarConfig
1820
String repoSetup
1921
String deps
22+
String preamble
2023
String additionalContent
2124

2225
def setup() {
@@ -36,8 +39,8 @@ class JRubyJarTestKitSpec extends IntegrationSpecification {
3639
}
3740

3841
void "executing the jrubyJar task produces an executable artifact"() {
39-
given:
40-
withJRubyConfig """
42+
setup:
43+
withJRubyJarConfig """
4144
initScript 'main.rb'
4245
"""
4346

@@ -59,8 +62,7 @@ class JRubyJarTestKitSpec extends IntegrationSpecification {
5962
result.task(":validateJar").outcome == TaskOutcome.SUCCESS
6063

6164
and: "the should not be a jruby-mains.jar or jruby-complete.jar inside the archive"
62-
ZipFile zip = new ZipFile("${projectDir}/build/libs/testproject-jruby.jar")
63-
!zip.entries().findAll { ZipEntry entry ->
65+
!jarEntries.findAll { ZipEntry entry ->
6466
entry.name.matches(/(.*)jruby-complete-(.*).jar/) || entry.name.matches(/(.*)jruby-mains-(.*).jar/)
6567
}
6668

@@ -70,7 +72,7 @@ class JRubyJarTestKitSpec extends IntegrationSpecification {
7072

7173
@Issue("https://github.com/jruby-gradle/jruby-gradle-plugin/issues/183")
7274
void "creating a new task based on JRubyJar produces a jar artifact"() {
73-
given:
75+
setup:
7476
withAdditionalContent '''
7577
task someDifferentJar(type: JRubyJar) {
7678
initScript 'main.rb'
@@ -96,13 +98,13 @@ class JRubyJarTestKitSpec extends IntegrationSpecification {
9698
@IgnoreIf({ IntegrationSpecification.OFFLINE })
9799
@Issue('https://github.com/jruby-gradle/jruby-gradle-plugin/pull/271')
98100
def 'using a more recent jar-dependencies should work'() {
99-
given:
101+
setup:
100102
withRepoSetup """
101103
maven { url 'http://rubygems-proxy.torquebox.org/releases' }
102104
mavenCentral()
103105
"""
104106
withDependencies "jrubyJar 'rubygems:jar-dependencies:0.2.3'"
105-
withJRubyConfig "initScript 'main.rb'"
107+
withJRubyJarConfig "initScript 'main.rb'"
106108

107109
withAdditionalContent '''
108110
task validateJar(type: JavaExec) {
@@ -122,7 +124,36 @@ class JRubyJarTestKitSpec extends IntegrationSpecification {
122124
result.output.contains("Hello from JRuby")
123125
}
124126

125-
private void withJRubyConfig(String content) {
127+
void "Building a Jar with a custom configuration and 'java' plugin is applied"() {
128+
setup:
129+
withPreamble 'apply plugin: "java"'
130+
withJRubyJarConfig "mainClass 'bogus.does.not.exist'"
131+
132+
when:
133+
build()
134+
135+
then: "I expect to see jruby.home unpacked inside the jar"
136+
jarEntries.find { entry ->
137+
entry.name == 'META-INF/jruby.home/bin/'
138+
}
139+
140+
and: "I expect the new main class to be listed in the manifest"
141+
jarManifestContent.contains 'Main-Class: bogus.does.not.exist'
142+
}
143+
144+
void "Adding a default main class"() {
145+
setup:
146+
withPreamble 'apply plugin: "java"'
147+
withJRubyJarConfig "defaultMainClass()"
148+
149+
when:
150+
build()
151+
152+
then: "Then the attribute should be set to the default in the manifest"
153+
jarManifestContent.contains "Main-Class: ${DEFAULT_MAIN_CLASS}"
154+
}
155+
156+
private void withJRubyJarConfig(String content) {
126157
jrubyJarConfig = """
127158
jrubyJar {
128159
${content}
@@ -159,6 +190,10 @@ class JRubyJarTestKitSpec extends IntegrationSpecification {
159190
"""
160191
}
161192

193+
private void withPreamble(String content) {
194+
this.preamble = content
195+
}
196+
162197
private void writeBuildFile() {
163198
buildFile.text = """
164199
import com.github.jrubygradle.jar.JRubyJar
@@ -167,6 +202,8 @@ class JRubyJarTestKitSpec extends IntegrationSpecification {
167202
id 'com.github.jruby-gradle.jar'
168203
}
169204
205+
${preamble ?: ''}
206+
170207
jruby.defaultRepositories = false
171208
172209
${repoSetup ?: ''}
@@ -195,4 +232,19 @@ class JRubyJarTestKitSpec extends IntegrationSpecification {
195232
tasks.addAll(additionalTasks)
196233
gradleRunner(tasks).build()
197234
}
235+
236+
private def getJarEntries() {
237+
ZipFile zip = new ZipFile("${projectDir}/build/libs/testproject-jruby.jar")
238+
zip.entries()
239+
}
240+
241+
private String getJarManifestContent() {
242+
ZipFile zip = new ZipFile("${projectDir}/build/libs/testproject-jruby.jar")
243+
244+
ZipEntry entry = zip.entries().find { entry ->
245+
entry.name == 'META-INF/MANIFEST.MF'
246+
}
247+
248+
zip.getInputStream(entry).text
249+
}
198250
}

0 commit comments

Comments
 (0)