cukedep 0.1.11 → 0.2.00
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/.ruby-version +1 -1
- data/.travis.yml +10 -10
- data/CHANGELOG.md +6 -0
- data/Gemfile +5 -5
- data/LICENSE.txt +1 -1
- data/README.md +1 -1
- data/Rakefile +30 -30
- data/bin/cukedep +15 -15
- data/lib/cukedep/application.rb +105 -112
- data/lib/cukedep/cli/cmd-line.rb +11 -13
- data/lib/cukedep/config.rb +85 -89
- data/lib/cukedep/constants.rb +5 -5
- data/lib/cukedep/cuke-runner.rb +191 -198
- data/lib/cukedep/customization.rb +30 -30
- data/lib/cukedep/feature-model.rb +43 -46
- data/lib/cukedep/feature-rep.rb +9 -11
- data/lib/cukedep/file-action.rb +11 -18
- data/lib/cukedep/gherkin-facade.rb +11 -6
- data/lib/cukedep/gherkin-listener.rb +12 -42
- data/lib/cukedep/hook-dsl.rb +78 -78
- data/lib/cukedep/sandbox.rb +15 -16
- data/lib/cukedep.rb +1 -2
- data/sample/features/step_definitions/steps.rb +2 -2
- data/sample/model/model.rb +19 -20
- data/spec/cukedep/application_spec.rb +80 -80
- data/spec/cukedep/cli/cmd-line_spec.rb +88 -88
- data/spec/cukedep/cuke-runner_spec.rb +74 -74
- data/spec/cukedep/customization_spec.rb +31 -31
- data/spec/cukedep/debug-file-action.rb +29 -29
- data/spec/cukedep/feature-model_spec.rb +100 -100
- data/spec/cukedep/feature-rep_spec.rb +2 -1
- data/spec/cukedep/file-action_spec.rb +365 -366
- data/spec/cukedep/file-parsing.rb +39 -41
- data/spec/cukedep/gherkin-facade_spec.rb +48 -49
- data/spec/cukedep/gherkin-listener_spec.rb +55 -57
- data/spec/cukedep/hook-dsl_spec.rb +182 -182
- data/spec/cukedep/sample_features/cukedep_hooks.rb +30 -30
- data/spec/cukedep/sample_features/standalone.feature +1 -1
- data/templates/rake.erb +12 -21
- metadata +80 -58
- data/sample/result.html +0 -472
- data/spec/cukedep/sample_features/cukedep.rake +0 -215
- data/spec/cukedep/sample_features/dependencies.dot +0 -38
- data/spec/cukedep/sample_features/feature2id.csv +0 -7
@@ -1,366 +1,365 @@
|
|
1
|
-
# File: file-action_spec.rb
|
2
|
-
require_relative '../spec_helper'
|
3
|
-
|
4
|
-
# Load the class under testing
|
5
|
-
require_relative '../../lib/cukedep/file-action'
|
6
|
-
|
7
|
-
module Cukedep # Open module to get rid of long qualified names
|
8
|
-
# Test the behaviour of the superclass
|
9
|
-
describe FileAction do
|
10
|
-
let(:some_patterns) { %w(README.* *tests.feature) }
|
11
|
-
let(:subpath) { './some-dir' }
|
12
|
-
|
13
|
-
subject { FileAction.new(some_patterns, subpath) }
|
14
|
-
|
15
|
-
context 'Creation & initialization:' do
|
16
|
-
it 'should be created with file patterns and a subdirectory argument' do
|
17
|
-
# Case 1: empty instance
|
18
|
-
expect { FileAction.new([], '') }.not_to raise_error
|
19
|
-
|
20
|
-
# Case 2: stuffed instance
|
21
|
-
expect { FileAction.new(some_patterns, subpath) }.not_to raise_error
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'should know its file patterns' do
|
25
|
-
expect(subject.patterns).to eq(some_patterns)
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should know the target's subdirectory" do
|
29
|
-
expect(subject.delta).to eq(subpath)
|
30
|
-
end
|
31
|
-
end # context
|
32
|
-
|
33
|
-
|
34
|
-
context 'Basic services:' do
|
35
|
-
it 'should know whether it is equal to another instance' do
|
36
|
-
# Case 1: comparing with itself
|
37
|
-
expect(subject).to eq(subject)
|
38
|
-
|
39
|
-
# Case 2: comparing with instance with same attribute values
|
40
|
-
expect(subject).to eq(subject.dup)
|
41
|
-
|
42
|
-
# Case 3: comparing with instances having different attribute values
|
43
|
-
another = FileAction.new(some_patterns, '')
|
44
|
-
expect(subject).not_to eq(another)
|
45
|
-
another = FileAction.new(['*.feature'], subpath)
|
46
|
-
expect(subject).not_to eq(another)
|
47
|
-
end
|
48
|
-
end # context
|
49
|
-
end # describe
|
50
|
-
|
51
|
-
|
52
|
-
describe CopyAction do
|
53
|
-
let(:source_dir) do
|
54
|
-
child = '/sample_features/files_to_copy'
|
55
|
-
File.join(File.dirname(__FILE__), child)
|
56
|
-
end
|
57
|
-
|
58
|
-
let(:subdir) do
|
59
|
-
'./sample_features/saved_files'
|
60
|
-
end
|
61
|
-
|
62
|
-
|
63
|
-
def clean_dir(aDirectory)
|
64
|
-
terminator = DeleteAction.new(['*.*'])
|
65
|
-
terminator.run!(aDirectory)
|
66
|
-
end
|
67
|
-
|
68
|
-
|
69
|
-
before(:all) do
|
70
|
-
# Clean stuffed dirs
|
71
|
-
path_suffix = '/sample_features/saved_files'
|
72
|
-
target_dir = File.join(File.dirname(__FILE__), path_suffix)
|
73
|
-
if Dir.exist?(target_dir)
|
74
|
-
clean_dir(target_dir)
|
75
|
-
else
|
76
|
-
Dir.mkdir(target_dir)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
|
81
|
-
before(:each) do
|
82
|
-
# Store the working dir before starting
|
83
|
-
@original_work_dir = Dir.getwd
|
84
|
-
end
|
85
|
-
|
86
|
-
|
87
|
-
after(:each) do
|
88
|
-
# Restore the original working dir
|
89
|
-
Dir.chdir(@original_work_dir)
|
90
|
-
end
|
91
|
-
|
92
|
-
|
93
|
-
context 'Copying files' do
|
94
|
-
it 'should copy files matching the patterns' do
|
95
|
-
my_dir = File.dirname(__FILE__)
|
96
|
-
|
97
|
-
# Case: one file pattern
|
98
|
-
instance1 = CopyAction.new(['*.md'], subdir)
|
99
|
-
expect { instance1.run!(source_dir, my_dir) }.not_to raise_error
|
100
|
-
|
101
|
-
Dir.chdir(my_dir)
|
102
|
-
# Control the result...
|
103
|
-
copied_files = Dir.glob(subdir + '/' + '*.*')
|
104
|
-
expect(copied_files.size).to eq(1)
|
105
|
-
|
106
|
-
# Case: two file patterns
|
107
|
-
instance2 = CopyAction.new(['file1.txt', 'file2.txt'], subdir)
|
108
|
-
expect { instance2.run!(source_dir, my_dir) }.not_to raise_error
|
109
|
-
|
110
|
-
# Control the result...
|
111
|
-
copied_files = Dir.glob(subdir + '/' + '*.*')
|
112
|
-
expect(copied_files.size).to eq(3)
|
113
|
-
end
|
114
|
-
end # context
|
115
|
-
end # describe
|
116
|
-
|
117
|
-
|
118
|
-
describe DeleteAction do
|
119
|
-
let(:subdir) do
|
120
|
-
'./sample_features/saved_files'
|
121
|
-
end
|
122
|
-
|
123
|
-
let(:target_dir) do
|
124
|
-
File.join(File.dirname(__FILE__), subdir)
|
125
|
-
end
|
126
|
-
|
127
|
-
|
128
|
-
before(:each) do
|
129
|
-
# Store the working dir before starting
|
130
|
-
@original_work_dir = Dir.getwd
|
131
|
-
end
|
132
|
-
|
133
|
-
|
134
|
-
after(:each) do
|
135
|
-
# Restore the original working dir
|
136
|
-
Dir.chdir(@original_work_dir)
|
137
|
-
end
|
138
|
-
|
139
|
-
|
140
|
-
context 'Deleting files' do
|
141
|
-
it 'should delete files matching the patterns' do
|
142
|
-
my_dir = File.dirname(__FILE__)
|
143
|
-
|
144
|
-
# Case: one file pattern and a subdir
|
145
|
-
instance1 = DeleteAction.new(['*.md'], subdir)
|
146
|
-
expect { instance1.run!(my_dir) }.not_to raise_error
|
147
|
-
Dir.chdir(my_dir)
|
148
|
-
|
149
|
-
# Control the result...
|
150
|
-
remaining_files = Dir.glob(subdir + '/' + '*.*')
|
151
|
-
expect(remaining_files.size).to eq(2)
|
152
|
-
|
153
|
-
# Case: multiple file patterns and no subdir
|
154
|
-
instance2 = DeleteAction.new(['file1.txt', 'file3.txt'])
|
155
|
-
expect { instance2.run!(target_dir) }.not_to raise_error
|
156
|
-
|
157
|
-
# Control the result...
|
158
|
-
remaining_files = Dir.glob(subdir + '/' + '*.*')
|
159
|
-
expect(remaining_files.size).to eq(1)
|
160
|
-
|
161
|
-
# Delete all files
|
162
|
-
instance3 = DeleteAction.new(['*.*'])
|
163
|
-
expect { instance3.run!(target_dir) }.not_to raise_error
|
164
|
-
|
165
|
-
# Control the result...
|
166
|
-
remaining_files = Dir.glob(subdir + '/' + '*.*')
|
167
|
-
expect(remaining_files.size).to eq(0)
|
168
|
-
end
|
169
|
-
end # context
|
170
|
-
end # describe
|
171
|
-
|
172
|
-
|
173
|
-
describe ActionTriplet do
|
174
|
-
def saved_files_dir
|
175
|
-
my_dir = File.dirname(__FILE__)
|
176
|
-
return my_dir + '/sample_features/saved_files'
|
177
|
-
end
|
178
|
-
|
179
|
-
# File patterns
|
180
|
-
def all_files
|
181
|
-
return ['*.*']
|
182
|
-
end
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
other_config =
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
clean_dir(
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
child
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
Dir.
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
copy_config =
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
project_dir
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
Dir
|
305
|
-
actuals
|
306
|
-
expect(actuals.
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
Dir.
|
318
|
-
|
319
|
-
|
320
|
-
actuals
|
321
|
-
|
322
|
-
(txt_files
|
323
|
-
expect(
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
saved
|
331
|
-
Dir.
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
save_config =
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
instance
|
341
|
-
|
342
|
-
actuals
|
343
|
-
expect(actuals
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
save_config[:
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
Dir
|
357
|
-
actuals
|
358
|
-
expect(actuals.
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
end #
|
364
|
-
|
365
|
-
|
366
|
-
# End of file
|
1
|
+
# File: file-action_spec.rb
|
2
|
+
require_relative '../spec_helper'
|
3
|
+
|
4
|
+
# Load the class under testing
|
5
|
+
require_relative '../../lib/cukedep/file-action'
|
6
|
+
|
7
|
+
module Cukedep # Open module to get rid of long qualified names
|
8
|
+
# Test the behaviour of the superclass
|
9
|
+
describe FileAction do
|
10
|
+
let(:some_patterns) { %w(README.* *tests.feature) }
|
11
|
+
let(:subpath) { './some-dir' }
|
12
|
+
|
13
|
+
subject { FileAction.new(some_patterns, subpath) }
|
14
|
+
|
15
|
+
context 'Creation & initialization:' do
|
16
|
+
it 'should be created with file patterns and a subdirectory argument' do
|
17
|
+
# Case 1: empty instance
|
18
|
+
expect { FileAction.new([], '') }.not_to raise_error
|
19
|
+
|
20
|
+
# Case 2: stuffed instance
|
21
|
+
expect { FileAction.new(some_patterns, subpath) }.not_to raise_error
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should know its file patterns' do
|
25
|
+
expect(subject.patterns).to eq(some_patterns)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should know the target's subdirectory" do
|
29
|
+
expect(subject.delta).to eq(subpath)
|
30
|
+
end
|
31
|
+
end # context
|
32
|
+
|
33
|
+
|
34
|
+
context 'Basic services:' do
|
35
|
+
it 'should know whether it is equal to another instance' do
|
36
|
+
# Case 1: comparing with itself
|
37
|
+
expect(subject).to eq(subject)
|
38
|
+
|
39
|
+
# Case 2: comparing with instance with same attribute values
|
40
|
+
expect(subject).to eq(subject.dup)
|
41
|
+
|
42
|
+
# Case 3: comparing with instances having different attribute values
|
43
|
+
another = FileAction.new(some_patterns, '')
|
44
|
+
expect(subject).not_to eq(another)
|
45
|
+
another = FileAction.new(['*.feature'], subpath)
|
46
|
+
expect(subject).not_to eq(another)
|
47
|
+
end
|
48
|
+
end # context
|
49
|
+
end # describe
|
50
|
+
|
51
|
+
|
52
|
+
describe CopyAction do
|
53
|
+
let(:source_dir) do
|
54
|
+
child = '/sample_features/files_to_copy'
|
55
|
+
File.join(File.dirname(__FILE__), child)
|
56
|
+
end
|
57
|
+
|
58
|
+
let(:subdir) do
|
59
|
+
'./sample_features/saved_files'
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
def clean_dir(aDirectory)
|
64
|
+
terminator = DeleteAction.new(['*.*'])
|
65
|
+
terminator.run!(aDirectory)
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
before(:all) do
|
70
|
+
# Clean stuffed dirs
|
71
|
+
path_suffix = '/sample_features/saved_files'
|
72
|
+
target_dir = File.join(File.dirname(__FILE__), path_suffix)
|
73
|
+
if Dir.exist?(target_dir)
|
74
|
+
clean_dir(target_dir)
|
75
|
+
else
|
76
|
+
Dir.mkdir(target_dir)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
before(:each) do
|
82
|
+
# Store the working dir before starting
|
83
|
+
@original_work_dir = Dir.getwd
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
after(:each) do
|
88
|
+
# Restore the original working dir
|
89
|
+
Dir.chdir(@original_work_dir)
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
context 'Copying files' do
|
94
|
+
it 'should copy files matching the patterns' do
|
95
|
+
my_dir = File.dirname(__FILE__)
|
96
|
+
|
97
|
+
# Case: one file pattern
|
98
|
+
instance1 = CopyAction.new(['*.md'], subdir)
|
99
|
+
expect { instance1.run!(source_dir, my_dir) }.not_to raise_error
|
100
|
+
|
101
|
+
Dir.chdir(my_dir)
|
102
|
+
# Control the result...
|
103
|
+
copied_files = Dir.glob(subdir + '/' + '*.*')
|
104
|
+
expect(copied_files.size).to eq(1)
|
105
|
+
|
106
|
+
# Case: two file patterns
|
107
|
+
instance2 = CopyAction.new(['file1.txt', 'file2.txt'], subdir)
|
108
|
+
expect { instance2.run!(source_dir, my_dir) }.not_to raise_error
|
109
|
+
|
110
|
+
# Control the result...
|
111
|
+
copied_files = Dir.glob(subdir + '/' + '*.*')
|
112
|
+
expect(copied_files.size).to eq(3)
|
113
|
+
end
|
114
|
+
end # context
|
115
|
+
end # describe
|
116
|
+
|
117
|
+
|
118
|
+
describe DeleteAction do
|
119
|
+
let(:subdir) do
|
120
|
+
'./sample_features/saved_files'
|
121
|
+
end
|
122
|
+
|
123
|
+
let(:target_dir) do
|
124
|
+
File.join(File.dirname(__FILE__), subdir)
|
125
|
+
end
|
126
|
+
|
127
|
+
|
128
|
+
before(:each) do
|
129
|
+
# Store the working dir before starting
|
130
|
+
@original_work_dir = Dir.getwd
|
131
|
+
end
|
132
|
+
|
133
|
+
|
134
|
+
after(:each) do
|
135
|
+
# Restore the original working dir
|
136
|
+
Dir.chdir(@original_work_dir)
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
context 'Deleting files' do
|
141
|
+
it 'should delete files matching the patterns' do
|
142
|
+
my_dir = File.dirname(__FILE__)
|
143
|
+
|
144
|
+
# Case: one file pattern and a subdir
|
145
|
+
instance1 = DeleteAction.new(['*.md'], subdir)
|
146
|
+
expect { instance1.run!(my_dir) }.not_to raise_error
|
147
|
+
Dir.chdir(my_dir)
|
148
|
+
|
149
|
+
# Control the result...
|
150
|
+
remaining_files = Dir.glob(subdir + '/' + '*.*')
|
151
|
+
expect(remaining_files.size).to eq(2)
|
152
|
+
|
153
|
+
# Case: multiple file patterns and no subdir
|
154
|
+
instance2 = DeleteAction.new(['file1.txt', 'file3.txt'])
|
155
|
+
expect { instance2.run!(target_dir) }.not_to raise_error
|
156
|
+
|
157
|
+
# Control the result...
|
158
|
+
remaining_files = Dir.glob(subdir + '/' + '*.*')
|
159
|
+
expect(remaining_files.size).to eq(1)
|
160
|
+
|
161
|
+
# Delete all files
|
162
|
+
instance3 = DeleteAction.new(['*.*'])
|
163
|
+
expect { instance3.run!(target_dir) }.not_to raise_error
|
164
|
+
|
165
|
+
# Control the result...
|
166
|
+
remaining_files = Dir.glob(subdir + '/' + '*.*')
|
167
|
+
expect(remaining_files.size).to eq(0)
|
168
|
+
end
|
169
|
+
end # context
|
170
|
+
end # describe
|
171
|
+
|
172
|
+
|
173
|
+
describe ActionTriplet do
|
174
|
+
def saved_files_dir
|
175
|
+
my_dir = File.dirname(__FILE__)
|
176
|
+
return my_dir + '/sample_features/saved_files'
|
177
|
+
end
|
178
|
+
|
179
|
+
# File patterns
|
180
|
+
def all_files
|
181
|
+
return ['*.*']
|
182
|
+
end
|
183
|
+
|
184
|
+
def txt_only
|
185
|
+
return ['*.txt']
|
186
|
+
end
|
187
|
+
|
188
|
+
let(:empty_config) do
|
189
|
+
{
|
190
|
+
save_patterns: [],
|
191
|
+
save_subdir: '',
|
192
|
+
delete_patterns: [],
|
193
|
+
delete_subdir: '',
|
194
|
+
copy_patterns: [],
|
195
|
+
copy_subdir: ''
|
196
|
+
}
|
197
|
+
end
|
198
|
+
|
199
|
+
let(:sample_config) do
|
200
|
+
{
|
201
|
+
save_patterns: txt_only,
|
202
|
+
save_subdir: saved_files_dir,
|
203
|
+
delete_patterns: all_files,
|
204
|
+
delete_subdir: '',
|
205
|
+
copy_patterns: txt_only,
|
206
|
+
copy_subdir: ''
|
207
|
+
}
|
208
|
+
end
|
209
|
+
|
210
|
+
context 'Creation & initialization:' do
|
211
|
+
it 'should be created with Hash-like arguments' do
|
212
|
+
# Case 1: empty instance
|
213
|
+
expect { ActionTriplet.new(empty_config) }.not_to raise_error
|
214
|
+
|
215
|
+
# Case 2: stuffed instance
|
216
|
+
expect { ActionTriplet.new(sample_config) }.not_to raise_error
|
217
|
+
end
|
218
|
+
end # context
|
219
|
+
|
220
|
+
context 'Basic services:' do
|
221
|
+
subject { ActionTriplet.new(sample_config) }
|
222
|
+
|
223
|
+
it 'should compare with other instances' do
|
224
|
+
# Case 1: comparing with itself
|
225
|
+
expect(subject).to eq(subject)
|
226
|
+
|
227
|
+
# Case 2: comparing with instance with same attribute values
|
228
|
+
expect(subject).to eq(subject.dup)
|
229
|
+
|
230
|
+
# Case 3: comparing with instance with different attribute values
|
231
|
+
other_config = sample_config.dup
|
232
|
+
other_config[:copy_patterns] = all_files
|
233
|
+
another = ActionTriplet.new(other_config)
|
234
|
+
expect(subject).not_to eq(another)
|
235
|
+
end
|
236
|
+
end # context
|
237
|
+
|
238
|
+
|
239
|
+
context 'Actions on files:' do
|
240
|
+
before(:each) do
|
241
|
+
# Store the working dir before starting
|
242
|
+
@original_work_dir = Dir.getwd
|
243
|
+
end
|
244
|
+
|
245
|
+
|
246
|
+
after(:each) do
|
247
|
+
# Restore the original working dir
|
248
|
+
Dir.chdir(@original_work_dir)
|
249
|
+
end
|
250
|
+
|
251
|
+
after(:all) do
|
252
|
+
# Clean stuffed dirs
|
253
|
+
clean_dir(saved_files_dir)
|
254
|
+
clean_dir(proj_dir)
|
255
|
+
end
|
256
|
+
|
257
|
+
# Directories
|
258
|
+
def proj_dir
|
259
|
+
my_dir = File.join(File.dirname(__FILE__), '/dummy_project')
|
260
|
+
|
261
|
+
if Dir.exist?(my_dir)
|
262
|
+
clean_dir(my_dir)
|
263
|
+
else
|
264
|
+
Dir.mkdir(my_dir)
|
265
|
+
end
|
266
|
+
|
267
|
+
return my_dir
|
268
|
+
end
|
269
|
+
|
270
|
+
def files_to_copy_dir
|
271
|
+
child = '/sample_features/files_to_copy'
|
272
|
+
File.join(File.dirname(__FILE__), child)
|
273
|
+
end
|
274
|
+
|
275
|
+
def clean_dir(aDirectory)
|
276
|
+
# Create an instance with just delete file items
|
277
|
+
instance = DeleteAction.new(all_files, '')
|
278
|
+
|
279
|
+
# Clean the directory
|
280
|
+
instance.run!(aDirectory)
|
281
|
+
end
|
282
|
+
|
283
|
+
|
284
|
+
it 'should be able to delete all files in the specified dir' do
|
285
|
+
# Clean project dir
|
286
|
+
clean_dir(proj_dir)
|
287
|
+
Dir.chdir(proj_dir)
|
288
|
+
expect(Dir['*.*']).to be_empty
|
289
|
+
end
|
290
|
+
|
291
|
+
it 'should copy files to specified dir' do
|
292
|
+
# Case 1: an instance with just one copy file pattern
|
293
|
+
copy_config = empty_config.dup
|
294
|
+
copy_config[:copy_patterns] = txt_only
|
295
|
+
instance = ActionTriplet.new(copy_config)
|
296
|
+
|
297
|
+
# Current dir is the directory containing the files to copy
|
298
|
+
Dir.chdir(files_to_copy_dir)
|
299
|
+
project_dir = proj_dir
|
300
|
+
instance.run!(Dir.getwd, project_dir)
|
301
|
+
|
302
|
+
# Check that the project dir contain the requested files
|
303
|
+
Dir.chdir(project_dir)
|
304
|
+
actuals = Dir['*.*']
|
305
|
+
expect(actuals.size).to eq(3)
|
306
|
+
expect(actuals.sort).to eq(%w(file1.txt file2.txt file3.txt))
|
307
|
+
|
308
|
+
# Clean project dir
|
309
|
+
clean_dir(project_dir)
|
310
|
+
|
311
|
+
# Case 2: an instance with just two copy file patterns
|
312
|
+
copy_config[:copy_patterns] << 'README.md'
|
313
|
+
instance = ActionTriplet.new(copy_config)
|
314
|
+
|
315
|
+
# Current dir is the directory containing the files to copy
|
316
|
+
Dir.chdir(files_to_copy_dir)
|
317
|
+
instance.run!(Dir.getwd, project_dir)
|
318
|
+
|
319
|
+
actuals = Dir['*.*']
|
320
|
+
expect(actuals.size).to eq(4)
|
321
|
+
(txt_files, md_files) = actuals.partition { |f| f =~ /\.txt/ }
|
322
|
+
expect(txt_files.sort).to eq(%w(file1.txt file2.txt file3.txt))
|
323
|
+
expect(md_files).to eq(%w(README.md))
|
324
|
+
end
|
325
|
+
|
326
|
+
=begin
|
327
|
+
it 'should save files to the specified folder' do
|
328
|
+
# Clean saved_files dir
|
329
|
+
saved = saved_files_dir
|
330
|
+
Dir.chdir(saved)
|
331
|
+
pp Dir.getwd
|
332
|
+
expect(Dir['*.*']).to be_empty
|
333
|
+
|
334
|
+
save_config = empty_config.dup
|
335
|
+
save_config[:save_patterns] = ['README.md']
|
336
|
+
project_dir = proj_dir
|
337
|
+
|
338
|
+
# Case 1: the save dir is absolute
|
339
|
+
instance = ActionTriplet.new(save_config)
|
340
|
+
instance.run!(Dir.getwd, project_dir)
|
341
|
+
actuals = Dir['*.*']
|
342
|
+
expect(actuals.size).to eq(1)
|
343
|
+
expect(actuals).to eq(['README.md'])
|
344
|
+
|
345
|
+
# Clean again saved_files dir
|
346
|
+
clean_dir(saved)
|
347
|
+
my_dir = File.dirname(__FILE__)
|
348
|
+
save_config[:save_patterns] = txt_only
|
349
|
+
save_config[:save_subdir] = './sample_features/saved_files'
|
350
|
+
|
351
|
+
instance = ActionTriplet.new(save_config)
|
352
|
+
Dir.chdir(my_dir)
|
353
|
+
instance.run!(my_dir, project_dir)
|
354
|
+
|
355
|
+
Dir.chdir(saved_files_dir)
|
356
|
+
actuals = Dir['*.*']
|
357
|
+
expect(actuals.size).to eq(3)
|
358
|
+
expect(actuals.sort).to eq(%w[file1.txt file2.txt file3.txt])
|
359
|
+
end
|
360
|
+
=end
|
361
|
+
end # context
|
362
|
+
end # describe
|
363
|
+
end # module
|
364
|
+
|
365
|
+
# End of file
|