cukedep 0.0.8 → 0.1.03

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