git_cloner 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,20 +2,21 @@
2
2
  require 'git_cloner_dsl_model'
3
3
 
4
4
  module GitCloner
5
+ # Dsl
5
6
  class Dsl
6
7
  attr_accessor :git_cloner
7
8
 
8
9
  # String Define
9
10
  [:default_output].each do |f|
10
11
  define_method f do |value|
11
- eval "@git_cloner.#{f.to_s} = '#{value}'", binding
12
+ @git_cloner.send("#{f}=", value)
12
13
  end
13
14
  end
14
15
 
15
16
  # Array/Hash/Boolean Define
16
17
  [:repos].each do |f|
17
18
  define_method f do |value|
18
- eval "@git_cloner.#{f.to_s} = #{value}", binding
19
+ @git_cloner.send("#{f}=", value)
19
20
  end
20
21
  end
21
22
 
@@ -2,6 +2,7 @@
2
2
  require 'active_model'
3
3
 
4
4
  module GitCloner
5
+ # DslModel
5
6
  class DslModel
6
7
  include ActiveModel::Model
7
8
 
@@ -11,6 +12,5 @@ module GitCloner
11
12
 
12
13
  # git repositries
13
14
  attr_accessor :repos
14
-
15
15
  end
16
16
  end
@@ -0,0 +1,83 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'copier'
4
+
5
+ describe GitCloner::Copier do
6
+ context :copy do
7
+ TMP_COPY = 'tmp_copy'
8
+ cases = [
9
+ {
10
+ case_no: 1,
11
+ case_title: 'valid case',
12
+ prepare_files: ['from/hoge1.txt', 'from/hoge2.txt'],
13
+ copies: [
14
+ {
15
+ from: 'from',
16
+ to: 'to'
17
+ }
18
+ ],
19
+ expected_files: ['to/hoge1.txt', 'to/hoge2.txt']
20
+ },
21
+ {
22
+ case_no: 2,
23
+ case_title: 'not have from key case',
24
+ prepare_files: ['from/hoge1.txt', 'from/hoge2.txt'],
25
+ copies: [
26
+ {
27
+ to: 'to'
28
+ }
29
+ ],
30
+ expect_error: true
31
+ },
32
+ {
33
+ case_no: 3,
34
+ case_title: 'not have to key case',
35
+ prepare_files: ['from/hoge1.txt', 'from/hoge2.txt'],
36
+ copies: [
37
+ {
38
+ from: 'from'
39
+ }
40
+ ],
41
+ expect_error: true
42
+ }
43
+ ]
44
+
45
+ cases.each do |c|
46
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
47
+ begin
48
+ case_before c
49
+
50
+ # -- given --
51
+ # nothing
52
+
53
+ # -- when --
54
+ if c[:expect_error]
55
+ -> { GitCloner::Copier.copy(c[:copies]) }.should raise_error(ArgumentError)
56
+ next
57
+ end
58
+ GitCloner::Copier.copy(c[:copies])
59
+
60
+ # -- then --
61
+ c[:expected_files].each { |file|expect(File.exist?(file)).to be_true }
62
+ ensure
63
+ case_after c
64
+ end
65
+ end
66
+
67
+ def case_before(c) # rubocop:disable UnusedMethodArgument
68
+ Dir.mkdir(TMP_COPY) unless Dir.exist?(TMP_COPY)
69
+ Dir.chdir(TMP_COPY)
70
+ c[:prepare_files].each do |file|
71
+ dir = File.dirname(file)
72
+ FileUtils.mkdir_p(dir)
73
+ File.open(file, 'w') { |f|f.print file }
74
+ end
75
+ end
76
+
77
+ def case_after(c) # rubocop:disable UnusedMethodArgument
78
+ Dir.chdir('../')
79
+ FileUtils.rm_rf(TMP_COPY) if Dir.exist?(TMP_COPY)
80
+ end
81
+ end
82
+ end
83
+ end
@@ -1,339 +1,195 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
- require 'git_cloner_core'
4
-
5
- describe GitCloner::Core do
6
- context :init do
7
- OUTPUT_DSL_TMP_DIR = 'generate_dsl'
8
- cases = [
9
- {
10
- case_no: 1,
11
- case_title: 'valid case',
12
- expected_file: GitCloner::Core::GIT_CLONER_FILE,
13
- expected_content: GitCloner::Core::GIT_CLONER_TEMPLATE,
14
- },
15
- ]
16
-
17
- cases.each do |c|
18
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
19
- begin
20
- case_before c
21
-
22
- # -- given --
23
- git_cloner_core = GitCloner::Core.new
24
-
25
- # -- when --
26
- git_cloner_core.init
27
-
28
- # -- then --
29
- actual = File.read("./#{c[:expected_file]}")
30
- expect(actual).to eq(c[:expected_content])
31
- ensure
32
- case_after c
33
- end
34
- end
35
-
36
- def case_before(c)
37
- Dir.mkdir(OUTPUT_DSL_TMP_DIR) unless Dir.exists? OUTPUT_DSL_TMP_DIR
38
- Dir.chdir(OUTPUT_DSL_TMP_DIR)
39
- end
40
-
41
- def case_after(c)
42
- Dir.chdir('../')
43
- FileUtils.rm_rf(OUTPUT_DSL_TMP_DIR) if Dir.exists? OUTPUT_DSL_TMP_DIR
44
- end
45
- end
46
- end
47
-
48
- context :execute do
49
- OUTPUT_GIT_CLONER_TMP_DIR = 'tmp_git_cloner'
50
- GIT_CLONER_CASE1 = <<-EOF
51
- # encoding: utf-8
52
- default_output "./"
53
- repos [
54
- {
55
- place: "https://github.com/tbpgr/rspec_piccolo.git",
56
- output: "./tmp",
57
- },
58
- {
59
- place: "https://github.com/tbpgr/tbpgr_utils.git",
60
- }
61
- ]
62
- EOF
63
-
64
- RESULT_CASE1 = <<-EOF
65
- # encoding: utf-8
66
- require 'templatable'
67
-
68
- class SampleUse
69
- include Templatable
70
- template <<-EOS
71
- line1:<%=placeholders[:param1]%>
72
- line2:<%=placeholders[:param2]%>
73
- EOS
74
-
75
- def manufactured_param1
76
- # TODO: implement your logic
77
- end
78
-
79
- def manufactured_param2
80
- # TODO: implement your logic
81
- end
82
- end
83
- EOF
84
-
85
- GIT_CLONER_CASE2 = <<-EOF
86
- # encoding: utf-8
87
- default_output "./"
88
- repos "invalid"
89
- EOF
90
-
91
- GIT_CLONER_CASE3 = <<-EOF
92
- # encoding: utf-8
93
- default_output "./"
94
- repos ["invalid"]
95
- EOF
96
-
97
- GIT_CLONER_CASE4 = <<-EOF
98
- # encoding: utf-8
99
- default_output "./"
100
- repos [
101
- {
102
- plase: "typo"
103
- }
104
- ]
105
- EOF
106
-
107
- GIT_CLONER_CASE5 = <<-EOF
108
- # encoding: utf-8
109
- default_output "./"
110
- repos [
111
- {
112
- place: "https://github.com/tbpgr/rspec_piccolo.git",
113
- output: "./tmp",
114
- copies: [
115
- {from: "./tmp/rspec_piccolo/lib/rspec_piccolo", to: "./"},
116
- {from: "./tmp/rspec_piccolo/spec", to: "./sample"}
117
- ]
118
- },
119
- {
120
- place: "https://github.com/tbpgr/tbpgr_utils.git",
121
- }
122
- ]
123
- EOF
124
-
125
- cases = [
126
- {
127
- case_no: 1,
128
- case_title: 'valid case',
129
- input: GIT_CLONER_CASE1,
130
- expecteds: ['./tmp/rspec_piccolo', './tbpgr_utils'],
131
- },
132
- {
133
- case_no: 2,
134
- case_title: 'invalid repos case(String)',
135
- input: GIT_CLONER_CASE2,
136
- has_error: true,
137
- },
138
- {
139
- case_no: 3,
140
- case_title: 'invalid repos case(Array[Not Hash])',
141
- input: GIT_CLONER_CASE3,
142
- has_error: true,
143
- },
144
- {
145
- case_no: 4,
146
- case_title: 'invalid repos case(Array[Hash] but invalid hash key)',
147
- input: GIT_CLONER_CASE4,
148
- has_error: true,
149
- },
150
- {
151
- case_no: 5,
152
- case_title: 'clone git and copy directories case',
153
- input: GIT_CLONER_CASE5,
154
- expecteds: ['./tmp/rspec_piccolo', './tbpgr_utils', './sample/rspec_piccolo_spec.rb', './sample/spec_helper.rb', './rspec_piccolo'],
155
- },
156
- ]
157
-
158
- cases.each do |c|
159
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
160
- begin
161
- case_before c
162
-
163
- # -- given --
164
- git_cloner_core = GitCloner::Core.new
165
-
166
- # -- when --
167
- if c[:has_error]
168
- lambda { git_cloner_core.execute }.should raise_error(StandardError)
169
- next
170
- end
171
- git_cloner_core.execute
172
-
173
- # -- then --
174
- c[:expecteds].each do |expected|
175
- actual_exists = File.exists? expected
176
- expect(actual_exists).to be_true
177
- end
178
- ensure
179
- case_after c
180
- end
181
- end
182
-
183
- def case_before(c)
184
- Dir.mkdir(OUTPUT_GIT_CLONER_TMP_DIR) unless Dir.exists? OUTPUT_GIT_CLONER_TMP_DIR
185
- Dir.chdir(OUTPUT_GIT_CLONER_TMP_DIR)
186
- File.open(GitCloner::Core::GIT_CLONER_FILE, 'w:UTF-8') { |f|f.print c[:input] }
187
- end
188
-
189
- def case_after(c)
190
- Dir.chdir('../')
191
- FileUtils.rm_rf(OUTPUT_GIT_CLONER_TMP_DIR) if Dir.exists? OUTPUT_GIT_CLONER_TMP_DIR
192
- end
193
- end
194
- end
195
-
196
- context :init do
197
- OUTPUT_DSL_TMP_DIR = 'generate_dsl'
198
- cases = [
199
- {
200
- case_no: 1,
201
- case_title: 'valid case',
202
- expected_file: GitCloner::Core::GIT_CLONER_FILE,
203
- expected_content: GitCloner::Core::GIT_CLONER_TEMPLATE,
204
- },
205
- ]
206
-
207
- cases.each do |c|
208
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
209
- begin
210
- case_before c
211
-
212
- # -- given --
213
- git_cloner_core = GitCloner::Core.new
214
-
215
- # -- when --
216
- git_cloner_core.init
217
-
218
- # -- then --
219
- actual = File.read("./#{c[:expected_file]}")
220
- expect(actual).to eq(c[:expected_content])
221
- ensure
222
- case_after c
223
- end
224
- end
225
-
226
- def case_before(c)
227
- Dir.mkdir(OUTPUT_DSL_TMP_DIR) unless Dir.exists? OUTPUT_DSL_TMP_DIR
228
- Dir.chdir(OUTPUT_DSL_TMP_DIR)
229
- end
230
-
231
- def case_after(c)
232
- Dir.chdir('../')
233
- FileUtils.rm_rf(OUTPUT_DSL_TMP_DIR) if Dir.exists? OUTPUT_DSL_TMP_DIR
234
- end
235
- end
236
- end
237
-
238
- context :clone do
239
- OUTPUT_GIT_CLONER_CLONE_TMP_DIR = 'tmp_git_cloner_clone'
240
-
241
- cases = [
242
- {
243
- case_no: 1,
244
- case_title: 'valid case',
245
- default_output: "./",
246
- repos: [
247
- {
248
- place: "https://github.com/tbpgr/rspec_piccolo.git",
249
- output: "./tmp",
250
- },
251
- {
252
- place: "https://github.com/tbpgr/tbpgr_utils.git",
253
- }
254
- ],
255
- expecteds: ['./tmp/rspec_piccolo', './tbpgr_utils'],
256
- },
257
- {
258
- case_no: 2,
259
- case_title: 'invalid repos case(String)',
260
- default_output: "./",
261
- repos: "invalid",
262
- has_error: true,
263
- },
264
- {
265
- case_no: 3,
266
- case_title: 'invalid repos case(Array[Not Hash])',
267
- default_output: "./",
268
- repos: ["invalid"],
269
- has_error: true,
270
- },
271
- {
272
- case_no: 4,
273
- default_output: "./",
274
- repos: [
275
- {
276
- plase: "typo"
277
- }
278
- ],
279
- has_error: true,
280
- },
281
- {
282
- case_no: 5,
283
- case_title: 'clone git and copy directories case',
284
- default_output: "./",
285
- repos: [
286
- {
287
- place: "https://github.com/tbpgr/rspec_piccolo.git",
288
- output: "./tmp",
289
- copies: [
290
- {from: "./tmp/rspec_piccolo/lib/rspec_piccolo", to: "./"},
291
- {from: "./tmp/rspec_piccolo/spec", to: "./sample"}
292
- ]
293
- },
294
- {
295
- place: "https://github.com/tbpgr/tbpgr_utils.git",
296
- }
297
- ],
298
- expecteds: ['./tmp/rspec_piccolo', './tbpgr_utils', './sample/rspec_piccolo_spec.rb', './sample/spec_helper.rb', './rspec_piccolo'],
299
- },
300
- ]
301
-
302
- cases.each do |c|
303
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
304
- begin
305
- case_before c
306
-
307
- # -- given --
308
- git_cloner_core = GitCloner::Core.new
309
-
310
- # -- when --
311
- if c[:has_error]
312
- lambda { git_cloner_core.clone(c[:default_output], c[:repos]) }.should raise_error(StandardError)
313
- next
314
- end
315
- git_cloner_core.clone(c[:default_output], c[:repos])
316
-
317
- # -- then --
318
- c[:expecteds].each do |expected|
319
- actual_exists = File.exists? expected
320
- expect(actual_exists).to be_true
321
- end
322
- ensure
323
- case_after c
324
- end
325
- end
326
-
327
- def case_before(c)
328
- Dir.mkdir(OUTPUT_GIT_CLONER_CLONE_TMP_DIR) unless Dir.exists? OUTPUT_GIT_CLONER_CLONE_TMP_DIR
329
- Dir.chdir(OUTPUT_GIT_CLONER_CLONE_TMP_DIR)
330
- File.open(GitCloner::Core::GIT_CLONER_FILE, 'w:UTF-8') { |f|f.print c[:input] }
331
- end
332
-
333
- def case_after(c)
334
- Dir.chdir('../')
335
- FileUtils.rm_rf(OUTPUT_GIT_CLONER_CLONE_TMP_DIR) if Dir.exists? OUTPUT_GIT_CLONER_CLONE_TMP_DIR
336
- end
337
- end
338
- end
339
- end
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'git_cloner_core'
4
+
5
+ describe GitCloner::Core do
6
+ context :init do
7
+ OUTPUT_DSL_TMP_DIR = 'generate_dsl'
8
+ cases = [
9
+ {
10
+ case_no: 1,
11
+ case_title: 'valid case',
12
+ expected_file: GitCloner::Core::GIT_CLONER_FILE,
13
+ expected_content: GitCloner::Core::GIT_CLONER_TEMPLATE
14
+ }
15
+ ]
16
+
17
+ cases.each do |c|
18
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
19
+ begin
20
+ case_before c
21
+
22
+ # -- given --
23
+ git_cloner_core = GitCloner::Core.new
24
+
25
+ # -- when --
26
+ git_cloner_core.init
27
+
28
+ # -- then --
29
+ actual = File.read("./#{c[:expected_file]}")
30
+ expect(actual).to eq(c[:expected_content])
31
+ ensure
32
+ case_after c
33
+ end
34
+ end
35
+
36
+ def case_before(c) # rubocop:disable UnusedMethodArgument
37
+ Dir.mkdir(OUTPUT_DSL_TMP_DIR) unless Dir.exist? OUTPUT_DSL_TMP_DIR
38
+ Dir.chdir(OUTPUT_DSL_TMP_DIR)
39
+ end
40
+
41
+ def case_after(c) # rubocop:disable UnusedMethodArgument
42
+ Dir.chdir('../')
43
+ FileUtils.rm_rf(OUTPUT_DSL_TMP_DIR) if Dir.exist? OUTPUT_DSL_TMP_DIR
44
+ end
45
+ end
46
+ end
47
+
48
+ context :clone do
49
+ OUTPUT_GIT_CLONER_TMP_DIR = 'tmp_git_cloner'
50
+ GIT_CLONER_CASE1 = <<-EOF
51
+ # encoding: utf-8
52
+ default_output "./"
53
+ repos [
54
+ {
55
+ place: "https://github.com/tbpgr/rspec_piccolo.git",
56
+ output: "./tmp",
57
+ },
58
+ {
59
+ place: "https://github.com/tbpgr/denrei.git",
60
+ }
61
+ ]
62
+ EOF
63
+
64
+ RESULT_CASE1 = <<-EOF
65
+ # encoding: utf-8
66
+ require 'templatable'
67
+
68
+ class SampleUse
69
+ include Templatable
70
+ template <<-EOS
71
+ line1:<%=placeholders[:param1]%>
72
+ line2:<%=placeholders[:param2]%>
73
+ EOS
74
+
75
+ def manufactured_param1
76
+ # TODO: implement your logic
77
+ end
78
+
79
+ def manufactured_param2
80
+ # TODO: implement your logic
81
+ end
82
+ end
83
+ EOF
84
+
85
+ GIT_CLONER_CASE2 = <<-EOF
86
+ # encoding: utf-8
87
+ default_output "./"
88
+ repos "invalid"
89
+ EOF
90
+
91
+ GIT_CLONER_CASE3 = <<-EOF
92
+ # encoding: utf-8
93
+ default_output "./"
94
+ repos ["invalid"]
95
+ EOF
96
+
97
+ GIT_CLONER_CASE4 = <<-EOF
98
+ # encoding: utf-8
99
+ default_output "./"
100
+ repos [
101
+ {
102
+ plase: "typo"
103
+ }
104
+ ]
105
+ EOF
106
+
107
+ GIT_CLONER_CASE5 = <<-EOF
108
+ # encoding: utf-8
109
+ default_output "./"
110
+ repos [
111
+ {
112
+ place: "https://github.com/tbpgr/rspec_piccolo.git",
113
+ output: "./tmp",
114
+ copies: [
115
+ {from: "./tmp/rspec_piccolo/lib/rspec_piccolo", to: "./"},
116
+ {from: "./tmp/rspec_piccolo/spec", to: "./sample"}
117
+ ]
118
+ },
119
+ {
120
+ place: "https://github.com/tbpgr/denrei.git",
121
+ }
122
+ ]
123
+ EOF
124
+
125
+ cases = [
126
+ {
127
+ case_no: 1,
128
+ case_title: 'valid case',
129
+ input: GIT_CLONER_CASE1,
130
+ expecteds: ['./tmp/rspec_piccolo', './denrei']
131
+ },
132
+ {
133
+ case_no: 2,
134
+ case_title: 'invalid repos case(String)',
135
+ input: GIT_CLONER_CASE2,
136
+ has_error: true
137
+ },
138
+ {
139
+ case_no: 3,
140
+ case_title: 'invalid repos case(Array[Not Hash])',
141
+ input: GIT_CLONER_CASE3,
142
+ has_error: true
143
+ },
144
+ {
145
+ case_no: 4,
146
+ case_title: 'invalid repos case(Array[Hash] but invalid hash key)',
147
+ input: GIT_CLONER_CASE4,
148
+ has_error: true
149
+ },
150
+ {
151
+ case_no: 5,
152
+ case_title: 'clone git and copy directories case',
153
+ input: GIT_CLONER_CASE5,
154
+ expecteds: ['./tmp/rspec_piccolo', './denrei', './sample/rspec_piccolo_spec.rb', './sample/spec_helper.rb', './rspec_piccolo']
155
+ }
156
+ ]
157
+
158
+ cases.each do |c|
159
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
160
+ begin
161
+ case_before c
162
+
163
+ # -- given --
164
+ git_cloner_core = GitCloner::Core.new
165
+
166
+ # -- when --
167
+ if c[:has_error]
168
+ -> { git_cloner_core.clone }.should raise_error(StandardError)
169
+ next
170
+ end
171
+ git_cloner_core.clone
172
+
173
+ # -- then --
174
+ c[:expecteds].each do |expected|
175
+ actual_exists = File.exist? expected
176
+ expect(actual_exists).to be_true
177
+ end
178
+ ensure
179
+ case_after c
180
+ end
181
+ end
182
+
183
+ def case_before(c)
184
+ Dir.mkdir(OUTPUT_GIT_CLONER_TMP_DIR) unless Dir.exist? OUTPUT_GIT_CLONER_TMP_DIR
185
+ Dir.chdir(OUTPUT_GIT_CLONER_TMP_DIR)
186
+ File.open(GitCloner::Core::GIT_CLONER_FILE, 'w:UTF-8') { |f|f.print c[:input] }
187
+ end
188
+
189
+ def case_after(c) # rubocop:disable UnusedMethodArgument
190
+ Dir.chdir('../')
191
+ FileUtils.rm_rf(OUTPUT_GIT_CLONER_TMP_DIR) if Dir.exist? OUTPUT_GIT_CLONER_TMP_DIR
192
+ end
193
+ end
194
+ end
195
+ end