1
+ package com.github.jrubygradle
2
+
3
+ import org.gradle.testfixtures.ProjectBuilder
4
+ import spock.lang.*
5
+
6
+
7
+ /**
8
+ * @author Schalk W. Cronjé
9
+ */
10
+ class GemUtilsSpec extends Specification {
11
+
12
+ static final File TESTROOT = new File (" ${ System.getProperty('TESTROOT') ?: 'build/tmp/test/unittests'} /gus" )
13
+
14
+ def project
15
+ File src = new File (TESTROOT ,' src' )
16
+ File dest = new File (TESTROOT ,' dest' )
17
+ File fakeGem = new File (src,' gems/mygem-1.0' )
18
+
19
+ void setup () {
20
+ project = ProjectBuilder . builder(). build()
21
+ project. buildDir = TESTROOT
22
+
23
+ if (TESTROOT . exists()) {
24
+ TESTROOT . deleteDir()
25
+ }
26
+ src. mkdirs()
27
+ dest. mkdirs()
28
+
29
+ /* Creating a folder structure that should look like
30
+ * src
31
+ * src/cache
32
+ * src/cache/cache.txt
33
+ * src/gems
34
+ * src/gems/mygem-1.0/fake.txt
35
+ * src/gems/mygem-1.0/test
36
+ * src/gems/mygem-1.0/test/test.txt
37
+ */
38
+ new File (fakeGem,' test' ). mkdirs()
39
+ new File (fakeGem,' fake.txt' ). text = ' fake.content'
40
+ new File (fakeGem,' test/test.txt' ). text = ' test.content'
41
+
42
+ new File (src,' cache' ). mkdirs()
43
+ new File (src,' cache/cache.txt' ). text = ' cache.content'
44
+ }
45
+
46
+ def " Attach a fake gem folder to a copy command" () {
47
+ when :
48
+ project. copy {
49
+ into dest
50
+
51
+ with GemUtils . gemCopySpec(project,src)
52
+ }
53
+
54
+ then :
55
+ new File (dest,' gems/mygem-1.0/fake.txt' ). exists()
56
+ ! new File (dest,' gems/mygem-1.0/test/test.txt' ). exists()
57
+ ! new File (dest,' cache' ). exists()
58
+ }
59
+
60
+ def " Attach a fake gem folder to a copy command with fullGem=false" () {
61
+ when :
62
+ project. copy {
63
+ into dest
64
+
65
+ with GemUtils . gemCopySpec(project,src,fullGem :false )
66
+ }
67
+
68
+ then :
69
+ new File (dest,' gems/mygem-1.0/fake.txt' ). exists()
70
+ ! new File (dest,' gems/mygem-1.0/test/test.txt' ). exists()
71
+ ! new File (dest,' cache' ). exists()
72
+ }
73
+
74
+ def " Attach a fake gem folder to a copy command with subfolder" () {
75
+ when :
76
+ project. copy {
77
+ into dest
78
+
79
+ with GemUtils . gemCopySpec(project,src,subfolder :' foo' )
80
+ }
81
+
82
+ then :
83
+ ! new File (dest,' gems/mygem-1.0/fake.txt' ). exists()
84
+ ! new File (dest,' gems/mygem-1.0/test/test.txt' ). exists()
85
+ ! new File (dest,' cache' ). exists()
86
+ new File (dest,' foo/gems/mygem-1.0/fake.txt' ). exists()
87
+ ! new File (dest,' foo/gems/mygem-1.0/test/test.txt' ). exists()
88
+ ! new File (dest,' foo/cache' ). exists()
89
+ }
90
+
91
+ def " Attach a fake gem folder to a copy command with fullGem=true" () {
92
+ when :
93
+ project. copy {
94
+ into dest
95
+
96
+ with GemUtils . gemCopySpec( project, src, fullGem : true )
97
+ }
98
+
99
+ then : " Expecting test and cache folders to be copied"
100
+ new File (dest,' gems/mygem-1.0/fake.txt' ). exists()
101
+ new File (dest,' gems/mygem-1.0/test/test.txt' ). exists()
102
+ new File (dest,' cache/cache.txt' ). exists()
103
+ }
104
+
105
+ def " Attach a fake gem folder to a copy command with subfolder and fullGem=true" () {
106
+ when :
107
+ project. copy {
108
+ into dest
109
+
110
+ with GemUtils . gemCopySpec(project,src,subfolder :' foo' ,fullGem :true )
111
+ }
112
+
113
+ then :
114
+ ! new File (dest,' gems/mygem-1.0/fake.txt' ). exists()
115
+ ! new File (dest,' gems/mygem-1.0/test/test.txt' ). exists()
116
+ ! new File (dest,' cache' ). exists()
117
+ new File (dest,' foo/gems/mygem-1.0/fake.txt' ). exists()
118
+ new File (dest,' foo/gems/mygem-1.0/test/test.txt' ). exists()
119
+ new File (dest,' foo/cache' ). exists()
120
+ }
121
+ }
0 commit comments