delta_test 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/README.md +22 -34
  4. data/Rakefile +5 -2
  5. data/bin/delta_test +1 -1
  6. data/circle.yml +5 -1
  7. data/delta_test.gemspec +1 -1
  8. data/lib/delta_test/cli/command_base.rb +114 -0
  9. data/lib/delta_test/cli/exec_command.rb +95 -0
  10. data/lib/delta_test/cli/help_command.rb +38 -0
  11. data/lib/delta_test/cli/specs_command.rb +43 -0
  12. data/lib/delta_test/cli/stats_clean_command.rb +20 -0
  13. data/lib/delta_test/cli/stats_save_command.rb +67 -0
  14. data/lib/delta_test/cli/stats_show_command.rb +46 -0
  15. data/lib/delta_test/cli/version_command.rb +13 -0
  16. data/lib/delta_test/cli.rb +22 -296
  17. data/lib/delta_test/configuration.rb +57 -42
  18. data/lib/delta_test/errors.rb +24 -0
  19. data/lib/delta_test/generator.rb +4 -24
  20. data/lib/delta_test/git.rb +161 -80
  21. data/lib/delta_test/profiler.rb +8 -0
  22. data/lib/delta_test/related_spec_list.rb +14 -9
  23. data/lib/delta_test/stats.rb +41 -0
  24. data/lib/delta_test/version.rb +2 -2
  25. data/lib/delta_test.rb +14 -9
  26. data/spec/lib/delta_test/cli/command_base_spec.rb +164 -0
  27. data/spec/lib/delta_test/cli/exec_command_spec.rb +128 -0
  28. data/spec/lib/delta_test/cli/help_command_spec.rb +17 -0
  29. data/spec/lib/delta_test/cli/specs_command_spec.rb +54 -0
  30. data/spec/lib/delta_test/cli/stats_clean_command_spec.rb +39 -0
  31. data/spec/lib/delta_test/cli/stats_save_command_spec.rb +207 -0
  32. data/spec/lib/delta_test/cli/stats_show_command_spec.rb +52 -0
  33. data/spec/lib/delta_test/cli/version_command_spec.rb +17 -0
  34. data/spec/lib/delta_test/cli_spec.rb +47 -386
  35. data/spec/lib/delta_test/configuration_spec.rb +99 -47
  36. data/spec/lib/delta_test/dependencies_table_spec.rb +1 -1
  37. data/spec/lib/delta_test/generator_spec.rb +3 -3
  38. data/spec/lib/delta_test/git_spec.rb +291 -50
  39. data/spec/lib/delta_test/profiler_spec.rb +3 -3
  40. data/spec/lib/delta_test/related_spec_list_spec.rb +12 -14
  41. data/spec/lib/delta_test/stats_spec.rb +89 -0
  42. data/spec/lib/delta_test/utils_spec.rb +4 -4
  43. data/spec/lib/delta_test_spec.rb +13 -4
  44. data/spec/rails/Gemfile.lock +5 -2
  45. data/spec/rails/app/models/category.rb +4 -0
  46. data/spec/rails/delta_test.yml +4 -3
  47. data/spec/rails/spec/models/category_spec.rb +4 -0
  48. data/spec/spec_helper.rb +9 -2
  49. data/spec/supports/create_table_file.rb +11 -1
  50. data/visual.jpg +0 -0
  51. metadata +32 -4
@@ -6,92 +6,118 @@ describe DeltaTest::Git do
6
6
  let(:success_status) { [out, '', double(success?: true)] }
7
7
  let(:error_status) { ['', '', double(success?: false)] }
8
8
 
9
- describe '::git_repo?' do
9
+ let(:git) { DeltaTest::Git.new('.') }
10
10
 
11
- let(:command) { %q{git rev-parse --is-inside-work-tree} }
11
+ describe '.new' do
12
+
13
+ it 'sholud execute commands in the specified directory' do
14
+ dir = '/dir'
15
+ git = DeltaTest::Git.new(dir)
16
+ expect(git.dir).to be_a_kind_of(Pathname)
17
+ expect(git.dir.to_s).to eq(dir)
18
+ end
19
+
20
+ end
21
+
22
+ describe '#git_repo?' do
23
+
24
+ let(:subcommand) { ['rev-parse --is-inside-work-tree'] }
25
+
26
+ before do
27
+ allow(git).to receive(:git_repo?).and_call_original
28
+ end
12
29
 
13
30
  it 'should return false if `git` command is not exist' do
14
- allow(Open3).to receive(:capture3).with(command, any_args).and_raise
31
+ expect(git).to receive(:exec).with(*subcommand).and_call_original
32
+ allow(Open3).to receive(:capture3).and_raise
15
33
 
16
34
  result = nil
17
35
 
18
36
  expect {
19
- result = DeltaTest::Git.git_repo?
37
+ result = git.git_repo?
20
38
  }.not_to raise_error
21
39
 
22
40
  expect(result).to be(false)
23
41
  end
24
42
 
25
43
  it 'should return true exit code is 0' do
26
- allow(Open3).to receive(:capture3).with(command, any_args).and_return(success_status)
44
+ expect(git).to receive(:exec).with(*subcommand).and_call_original
45
+ allow(Open3).to receive(:capture3).and_return(success_status)
27
46
 
28
- expect(DeltaTest::Git.git_repo?).to be(true)
47
+ expect(git.git_repo?).to be(true)
29
48
  end
30
49
 
31
50
  it 'should return false exit code not is 0' do
32
- allow(Open3).to receive(:capture3).with(command, any_args).and_return(error_status)
51
+ expect(git).to receive(:exec).with(*subcommand).and_call_original
52
+ allow(Open3).to receive(:capture3).and_return(error_status)
33
53
 
34
- expect(DeltaTest::Git.git_repo?).to be(false)
54
+ expect(git.git_repo?).to be(false)
35
55
  end
36
56
 
37
57
  end
38
58
 
39
- describe '::root_dir' do
59
+ describe '#root_dir' do
40
60
 
41
- let(:command) { %q{git rev-parse --show-toplevel} }
42
- let(:out) { '/root/dir' }
61
+ let(:subcommand) { ['rev-parse --show-toplevel'] }
62
+ let(:out) { '/root/dir' }
43
63
 
44
64
  it 'should raise an error if the command is not exist' do
45
- allow(Open3).to receive(:capture3).with(command, any_args).and_raise
65
+ expect(git).to receive(:exec).with(*subcommand).and_call_original
66
+ allow(Open3).to receive(:capture3).and_raise
46
67
 
47
68
  expect {
48
- DeltaTest::Git.root_dir
69
+ git.root_dir
49
70
  }.to raise_error
50
71
  end
51
72
 
52
73
  it 'should return a root directory path if success' do
53
- allow(Open3).to receive(:capture3).with(command, any_args).and_return(success_status)
74
+ expect(git).to receive(:exec).with(*subcommand).and_call_original
75
+ allow(Open3).to receive(:capture3).and_return(success_status)
54
76
 
55
- expect(DeltaTest::Git.root_dir).to eq(out)
77
+ expect(git.root_dir).to eq(out)
56
78
  end
57
79
 
58
80
  it 'should return nil if error' do
59
- allow(Open3).to receive(:capture3).with(command, any_args).and_return(error_status)
81
+ expect(git).to receive(:exec).with(*subcommand).and_call_original
82
+ allow(Open3).to receive(:capture3).and_return(error_status)
60
83
 
61
- expect(DeltaTest::Git.root_dir).to be_nil
84
+ expect(git.root_dir).to be_nil
62
85
  end
63
86
 
64
87
  end
65
88
 
66
- describe '::rev_parse' do
89
+ describe '#rev_parse' do
67
90
 
68
- let(:rev) { 'HEAD' }
69
- let(:command) { %Q{git rev-parse #{rev}} }
70
- let(:out) { '818b60efa12b4bd99815e9b550185d1fb6244663' }
91
+ let(:rev) { 'HEAD' }
92
+ let(:subcommand) { ['rev-parse %s', rev] }
93
+ let(:out) { '818b60efa12b4bd99815e9b550185d1fb6244663' }
71
94
 
72
95
  it 'should raise an error if the command is not exist' do
73
- allow(Open3).to receive(:capture3).with(command, any_args).and_raise
96
+ expect(git).to receive(:exec).with(*subcommand).and_call_original
97
+ allow(Open3).to receive(:capture3).and_raise
74
98
 
75
99
  expect {
76
- DeltaTest::Git.rev_parse(rev)
100
+ git.rev_parse(rev)
77
101
  }.to raise_error
78
102
  end
79
103
 
80
104
  it 'should return a commit id if success' do
81
- allow(Open3).to receive(:capture3).with(command, any_args).and_return(success_status)
105
+ expect(git).to receive(:exec).with(*subcommand).and_call_original
106
+ allow(Open3).to receive(:capture3).and_return(success_status)
82
107
 
83
- expect(DeltaTest::Git.rev_parse(rev)).to eq(out)
108
+ expect(git.rev_parse(rev)).to eq(out)
84
109
  end
85
110
 
86
111
  it 'should return nil if error' do
87
- allow(Open3).to receive(:capture3).with(command, any_args).and_return(error_status)
112
+ expect(git).to receive(:exec).with(*subcommand).and_call_original
113
+ allow(Open3).to receive(:capture3).and_return(error_status)
88
114
 
89
- expect(DeltaTest::Git.rev_parse(rev)).to be_nil
115
+ expect(git.rev_parse(rev)).to be_nil
90
116
  end
91
117
 
92
118
  end
93
119
 
94
- describe '::same_commit?' do
120
+ describe '#same_commit?' do
95
121
 
96
122
  let(:map) do
97
123
  {
@@ -103,74 +129,289 @@ describe DeltaTest::Git do
103
129
 
104
130
  before do
105
131
  map.each do |name, commit_id|
106
- allow(DeltaTest::Git).to receive(:rev_parse).with(name).and_return(commit_id)
132
+ allow(git).to receive(:rev_parse).with(name).and_return(commit_id)
107
133
  end
108
134
  end
109
135
 
110
136
  it 'should compare two names by thier commit ids' do
111
137
  names = map.values
112
138
  names.product(names).each do |r1, r2|
113
- expect(DeltaTest::Git).to receive(:rev_parse).with(r1).ordered
114
- expect(DeltaTest::Git).to receive(:rev_parse).with(r2).ordered
139
+ expect(git).to receive(:rev_parse).with(r1).ordered
140
+ expect(git).to receive(:rev_parse).with(r2).ordered
115
141
 
116
142
  is_same = (map[r1] == map[r2])
117
143
 
118
- expect(DeltaTest::Git.same_commit?(r1, r2)).to be(is_same)
144
+ expect(git.same_commit?(r1, r2)).to be(is_same)
119
145
  end
120
146
  end
121
147
 
122
148
  end
123
149
 
124
- describe '::ls_files' do
150
+ describe '#ls_files' do
125
151
 
126
- let(:command) { %q{git ls-files -z} }
127
- let(:out) { "/a/file/1\x0/a/file/2\x0/a/file/3" }
152
+ let(:subcommand) { ['ls-files -z %s', '.'] }
153
+ let(:out) { "/a/file/1\x0/a/file/2\x0/a/file/3" }
128
154
 
129
155
  it 'should raise an error if the command is not exist' do
130
- allow(Open3).to receive(:capture3).with(command, any_args).and_raise
156
+ expect(git).to receive(:exec).with(*subcommand).and_call_original
157
+ allow(Open3).to receive(:capture3).and_raise
131
158
 
132
159
  expect {
133
- DeltaTest::Git.ls_files
160
+ git.ls_files
134
161
  }.to raise_error
135
162
  end
136
163
 
137
164
  it 'should return an array if success' do
138
- allow(Open3).to receive(:capture3).with(command, any_args).and_return(success_status)
165
+ expect(git).to receive(:exec).with(*subcommand).and_call_original
166
+ allow(Open3).to receive(:capture3).and_return(success_status)
139
167
 
140
- expect(DeltaTest::Git.ls_files).to eq(out.split("\x0"))
168
+ expect(git.ls_files).to eq(out.split("\x0"))
141
169
  end
142
170
 
143
171
  it 'should return an empty array if error' do
144
- allow(Open3).to receive(:capture3).with(command, any_args).and_return(error_status)
172
+ expect(git).to receive(:exec).with(*subcommand).and_call_original
173
+ allow(Open3).to receive(:capture3).and_return(error_status)
145
174
 
146
- expect(DeltaTest::Git.ls_files).to eq([])
175
+ expect(git.ls_files).to eq([])
147
176
  end
148
177
 
149
178
  end
150
179
 
151
- describe '::changed_files' do
180
+ describe '#changed_files' do
152
181
 
153
- let(:command) { %q{git --no-pager diff --name-only -z master HEAD} }
154
- let(:out) { "/a/file/1\x0/a/file/2\x0/a/file/3" }
182
+ let(:subcommand) { ['diff --name-only -z %s %s %s', 'master', 'HEAD', '.'] }
183
+ let(:out) { "/a/file/1\x0/a/file/2\x0/a/file/3" }
155
184
 
156
185
  it 'should raise an error if the command is not exist' do
157
- allow(Open3).to receive(:capture3).with(command, any_args).and_raise
186
+ expect(git).to receive(:exec).with(*subcommand).and_call_original
187
+ allow(Open3).to receive(:capture3).and_raise
158
188
 
159
189
  expect {
160
- DeltaTest::Git.changed_files
190
+ git.changed_files
161
191
  }.to raise_error
162
192
  end
163
193
 
164
194
  it 'should return an array if success' do
165
- allow(Open3).to receive(:capture3).with(command, any_args).and_return(success_status)
195
+ expect(git).to receive(:exec).with(*subcommand).and_call_original
196
+ allow(Open3).to receive(:capture3).and_return(success_status)
166
197
 
167
- expect(DeltaTest::Git.changed_files).to eq(out.split("\x0"))
198
+ expect(git.changed_files).to eq(out.split("\x0"))
168
199
  end
169
200
 
170
201
  it 'should return an empty array if error' do
171
- allow(Open3).to receive(:capture3).with(command, any_args).and_return(error_status)
202
+ expect(git).to receive(:exec).with(*subcommand).and_call_original
203
+ allow(Open3).to receive(:capture3).and_return(error_status)
204
+
205
+ expect(git.changed_files).to eq([])
206
+ end
207
+
208
+ end
209
+
210
+ describe '#ls_hashes' do
211
+
212
+ let(:subcommand) { [%q{log -z -n %d --format='%%H'}, 10] }
213
+ let(:out) { "0000\x01111\x02222" }
214
+
215
+ it 'should raise an error if the command is not exist' do
216
+ expect(git).to receive(:exec).with(*subcommand).and_call_original
217
+ allow(Open3).to receive(:capture3).and_raise
218
+
219
+ expect {
220
+ git.ls_hashes(10)
221
+ }.to raise_error
222
+ end
223
+
224
+ it 'should return an array if success' do
225
+ expect(git).to receive(:exec).with(*subcommand).and_call_original
226
+ allow(Open3).to receive(:capture3).and_return(success_status)
227
+
228
+ expect(git.ls_hashes(10)).to eq(out.split("\x0"))
229
+ end
230
+
231
+ it 'should return an empty array if error' do
232
+ expect(git).to receive(:exec).with(*subcommand).and_call_original
233
+ allow(Open3).to receive(:capture3).and_return(error_status)
234
+
235
+ expect(git.ls_hashes(10)).to eq([])
236
+ end
237
+
238
+ end
239
+
240
+ describe '#remote_url' do
241
+
242
+ let(:subcommand) { ['config --get remote.origin.url'] }
243
+ let(:out) { 'git@example.com:test/test.git' }
244
+
245
+ it 'should raise an error if the command is not exist' do
246
+ expect(git).to receive(:exec).with(*subcommand).and_call_original
247
+ allow(Open3).to receive(:capture3).and_raise
248
+
249
+ expect {
250
+ git.remote_url
251
+ }.to raise_error
252
+ end
253
+
254
+ it 'should return an url if success' do
255
+ expect(git).to receive(:exec).with(*subcommand).and_call_original
256
+ allow(Open3).to receive(:capture3).and_return(success_status)
257
+
258
+ expect(git.remote_url).to eq(out)
259
+ end
260
+
261
+ it 'should return nil if error' do
262
+ expect(git).to receive(:exec).with(*subcommand).and_call_original
263
+ allow(Open3).to receive(:capture3).and_return(error_status)
264
+
265
+ expect(git.remote_url).to be_nil
266
+ end
267
+
268
+ end
269
+
270
+ describe '#has_remote?' do
271
+
272
+ let(:subcommand) { ['config --get remote.origin.url'] }
273
+ let(:out) { 'git@example.com:test/test.git' }
274
+
275
+ it 'should return false if the command is not exist' do
276
+ expect(git).to receive(:exec).with(*subcommand).and_call_original
277
+ allow(Open3).to receive(:capture3).and_raise
278
+
279
+ res = nil
280
+
281
+ expect {
282
+ res = git.has_remote?
283
+ }.not_to raise_error
284
+ expect(res).to be(false)
285
+ end
286
+
287
+ it 'should return true if it has a remote origin' do
288
+ expect(git).to receive(:exec).with(*subcommand).and_call_original
289
+ allow(Open3).to receive(:capture3).and_return(success_status)
290
+
291
+ expect(git.has_remote?).to be(true)
292
+ end
293
+
294
+ it 'should return false if not' do
295
+ expect(git).to receive(:exec).with(*subcommand).and_call_original
296
+ allow(Open3).to receive(:capture3).and_return(error_status)
297
+
298
+ expect(git.has_remote?).to be(false)
299
+ end
300
+
301
+ end
302
+
303
+ describe '#pull' do
304
+
305
+ let(:subcommand) { ['pull origin master'] }
306
+
307
+ it 'should raise an error if the command is not exist' do
308
+ expect(git).to receive(:exec).with(*subcommand).and_call_original
309
+ allow(Open3).to receive(:capture3).and_raise
310
+
311
+ expect {
312
+ git.pull
313
+ }.to raise_error
314
+ end
315
+
316
+ it 'should return true if success' do
317
+ expect(git).to receive(:exec).with(*subcommand).and_call_original
318
+ allow(Open3).to receive(:capture3).and_return(success_status)
319
+
320
+ expect(git.pull).to be(true)
321
+ end
322
+
323
+ it 'should return false if error' do
324
+ expect(git).to receive(:exec).with(*subcommand).and_call_original
325
+ allow(Open3).to receive(:capture3).and_return(error_status)
326
+
327
+ expect(git.pull).to be(false)
328
+ end
329
+
330
+ end
331
+
332
+ describe '#push' do
333
+
334
+ let(:subcommand) { ['push origin master'] }
335
+
336
+ it 'should raise an error if the command is not exist' do
337
+ expect(git).to receive(:exec).with(*subcommand).and_call_original
338
+ allow(Open3).to receive(:capture3).and_raise
339
+
340
+ expect {
341
+ git.push
342
+ }.to raise_error
343
+ end
344
+
345
+ it 'should return true if success' do
346
+ expect(git).to receive(:exec).with(*subcommand).and_call_original
347
+ allow(Open3).to receive(:capture3).and_return(success_status)
348
+
349
+ expect(git.push).to be(true)
350
+ end
351
+
352
+ it 'should return false if error' do
353
+ expect(git).to receive(:exec).with(*subcommand).and_call_original
354
+ allow(Open3).to receive(:capture3).and_return(error_status)
355
+
356
+ expect(git.push).to be(false)
357
+ end
358
+
359
+ end
360
+
361
+ describe '#add' do
362
+
363
+ let(:subcommand) { ['add %s', '/a/path'] }
364
+
365
+ it 'should raise an error if the command is not exist' do
366
+ expect(git).to receive(:exec).with(*subcommand).and_call_original
367
+ allow(Open3).to receive(:capture3).and_raise
368
+
369
+ expect {
370
+ git.add('/a/path')
371
+ }.to raise_error
372
+ end
373
+
374
+ it 'should return true if success' do
375
+ expect(git).to receive(:exec).with(*subcommand).and_call_original
376
+ allow(Open3).to receive(:capture3).and_return(success_status)
377
+
378
+ expect(git.add('/a/path')).to be(true)
379
+ end
380
+
381
+ it 'should return false if error' do
382
+ expect(git).to receive(:exec).with(*subcommand).and_call_original
383
+ allow(Open3).to receive(:capture3).and_return(error_status)
384
+
385
+ expect(git.add('/a/path')).to be(false)
386
+ end
387
+
388
+ end
389
+
390
+ describe '#commit' do
391
+
392
+ let(:subcommand) { ['commit -m %s', 'message'] }
393
+
394
+ it 'should raise an error if the command is not exist' do
395
+ expect(git).to receive(:exec).with(*subcommand).and_call_original
396
+ allow(Open3).to receive(:capture3).and_raise
397
+
398
+ expect {
399
+ git.commit('message')
400
+ }.to raise_error
401
+ end
402
+
403
+ it 'should return true if success' do
404
+ expect(git).to receive(:exec).with(*subcommand).and_call_original
405
+ allow(Open3).to receive(:capture3).and_return(success_status)
406
+
407
+ expect(git.commit('message')).to be(true)
408
+ end
409
+
410
+ it 'should return false if error' do
411
+ expect(git).to receive(:exec).with(*subcommand).and_call_original
412
+ allow(Open3).to receive(:capture3).and_return(error_status)
172
413
 
173
- expect(DeltaTest::Git.changed_files).to eq([])
414
+ expect(git.commit('message')).to be(false)
174
415
  end
175
416
 
176
417
  end
@@ -6,7 +6,7 @@ describe DeltaTest::Profiler do
6
6
  DeltaTest::Profiler.clean!
7
7
  end
8
8
 
9
- describe '::start!' do
9
+ describe '.start!' do
10
10
 
11
11
  it 'should start profiler' do
12
12
  expect(DeltaTest::Profiler.running?).to be(false)
@@ -20,7 +20,7 @@ describe DeltaTest::Profiler do
20
20
 
21
21
  end
22
22
 
23
- describe '::stop!' do
23
+ describe '.stop!' do
24
24
 
25
25
  it 'should not raise error if the profiler not yet started' do
26
26
  expect {
@@ -43,7 +43,7 @@ describe DeltaTest::Profiler do
43
43
 
44
44
  end
45
45
 
46
- describe '::last_result' do
46
+ describe '.last_result' do
47
47
 
48
48
  it 'should retrun an array if not yet started' do
49
49
  files = DeltaTest::Profiler.last_result
@@ -4,16 +4,14 @@ describe DeltaTest::RelatedSpecList do
4
4
 
5
5
  include_examples :defer_create_table_file
6
6
 
7
- let(:base) { 'master' }
8
- let(:head) { 'feature/foo' }
9
7
  let(:list) { DeltaTest::RelatedSpecList.new }
10
8
 
11
- let(:base_path) { '/base_path' }
9
+ let(:base_commit) { '1111111111111111111111111111111111111111' }
10
+ let(:base_path) { '/base_path' }
12
11
 
13
12
  before do
14
13
  DeltaTest.configure do |config|
15
- config.base_path = base_path
16
- config.table_file = table_file_path
14
+ config.base_path = base_path
17
15
  end
18
16
  end
19
17
 
@@ -41,8 +39,8 @@ describe DeltaTest::RelatedSpecList do
41
39
  before do
42
40
  allow(DeltaTest::DependenciesTable).to receive(:load).with(Pathname.new(table_file_path)).and_return(table)
43
41
 
44
- allow(DeltaTest::Git).to receive(:git_repo?).and_return(true)
45
- allow(DeltaTest::Git).to receive(:changed_files).with(base, head).and_return(changed_files)
42
+ allow(list.git).to receive(:git_repo?).and_return(true)
43
+ allow(list.git).to receive(:changed_files).with(base_commit).and_return(changed_files)
46
44
  end
47
45
 
48
46
  end
@@ -51,7 +49,7 @@ describe DeltaTest::RelatedSpecList do
51
49
 
52
50
  it 'should raise an error if a table file is not exist' do
53
51
  expect {
54
- list.load_table!
52
+ list.load_table!(table_file_path)
55
53
  }.to raise_error(DeltaTest::TableNotFoundError)
56
54
  end
57
55
 
@@ -61,7 +59,7 @@ describe DeltaTest::RelatedSpecList do
61
59
  expect(list.table).to be_nil
62
60
 
63
61
  expect {
64
- list.load_table!
62
+ list.load_table!(table_file_path)
65
63
  }.not_to raise_error
66
64
 
67
65
  expect(list.table).to be_a(DeltaTest::DependenciesTable)
@@ -74,17 +72,17 @@ describe DeltaTest::RelatedSpecList do
74
72
  include_examples :_mock_table_and_changed_files
75
73
 
76
74
  it 'shoud raise an error if the directory is not managed by git' do
77
- allow(DeltaTest::Git).to receive(:git_repo?).and_return(false)
75
+ allow(list.git).to receive(:git_repo?).and_return(false)
78
76
 
79
77
  expect {
80
- list.retrive_changed_files!(base, head)
78
+ list.retrive_changed_files!(base_commit)
81
79
  }.to raise_error(DeltaTest::NotInGitRepositoryError)
82
80
  end
83
81
 
84
82
  it 'shoud retrive a list of changed files' do
85
83
  expect(list.changed_files).to be_nil
86
84
 
87
- list.retrive_changed_files!(base, head)
85
+ list.retrive_changed_files!(base_commit)
88
86
 
89
87
  expect(list.changed_files).to be_a(Array)
90
88
  expect(list.changed_files).not_to be_empty
@@ -98,8 +96,8 @@ describe DeltaTest::RelatedSpecList do
98
96
 
99
97
  before do
100
98
  table_file
101
- list.load_table!
102
- list.retrive_changed_files!(base, head)
99
+ list.load_table!(table_file_path)
100
+ list.retrive_changed_files!(base_commit)
103
101
  end
104
102
 
105
103
  describe '#dependents' do
@@ -0,0 +1,89 @@
1
+ require 'delta_test/stats'
2
+ require 'delta_test/git'
3
+
4
+ describe DeltaTest::Stats do
5
+
6
+ describe '.new' do
7
+
8
+ it 'should initialize git instances for base_path and stats_path' do
9
+ expect(DeltaTest::Git).to receive(:new).with(DeltaTest.config.base_path)
10
+ expect(DeltaTest::Git).to receive(:new).with(DeltaTest.config.stats_path)
11
+ expect {
12
+ DeltaTest::Stats.new
13
+ }.not_to raise_error
14
+ end
15
+
16
+ end
17
+
18
+ let(:stats) { DeltaTest::Stats.new }
19
+
20
+ let(:commit_hashes) do
21
+ [
22
+ '4444444444444444444444444444444444444444',
23
+ '3333333333333333333333333333333333333333',
24
+ '2222222222222222222222222222222222222222',
25
+ '1111111111111111111111111111111111111111',
26
+ '0000000000000000000000000000000000000000',
27
+ ]
28
+ end
29
+
30
+ let(:files) do
31
+ [
32
+ '11/11111111111111111111111111111111111111/foo.txt',
33
+ '11/11111111111111111111111111111111111111/table.marshal',
34
+ '33/33333333333333333333333333333333333333/bar.txt',
35
+ '33/33333333333333333333333333333333333333/table.marshal',
36
+ ]
37
+ end
38
+
39
+ before do
40
+ allow_any_instance_of(DeltaTest::Git).to receive(:ls_hashes)
41
+ .with(DeltaTest.config.stats_life)
42
+ .and_return(commit_hashes)
43
+ allow_any_instance_of(DeltaTest::Git).to receive(:ls_files).and_return([])
44
+ end
45
+
46
+ describe '#base_commit' do
47
+
48
+ it 'should return a base commit if exists' do
49
+ allow_any_instance_of(DeltaTest::Git).to receive(:ls_files).and_return(files)
50
+ expect(stats.base_commit).to eq('3333333333333333333333333333333333333333')
51
+ end
52
+
53
+ it 'should return nil if not exists' do
54
+ expect(stats.base_commit).to be_nil
55
+ end
56
+
57
+ end
58
+
59
+ describe '#commit_dir' do
60
+
61
+ let(:commit_dir) { DeltaTest.config.stats_path.join('33/33333333333333333333333333333333333333') }
62
+
63
+ it 'should return a file for the commit hash if base_commit exists' do
64
+ allow_any_instance_of(DeltaTest::Git).to receive(:ls_files).and_return(files)
65
+ expect(stats.commit_dir).to eq(commit_dir)
66
+ end
67
+
68
+ it 'should return nil if base_commit does not exist' do
69
+ expect(stats.commit_dir).to be_nil
70
+ end
71
+
72
+ end
73
+
74
+ describe '#table_file_path' do
75
+
76
+ let(:table_file_path) { DeltaTest.config.stats_path.join('33/33333333333333333333333333333333333333/table.marshal') }
77
+
78
+ it 'should return a path of table file' do
79
+ allow_any_instance_of(DeltaTest::Git).to receive(:ls_files).and_return(files)
80
+ expect(stats.table_file_path).to eq(table_file_path)
81
+ end
82
+
83
+ it 'should return nil if base_commit does not exist' do
84
+ expect(stats.table_file_path).to be_nil
85
+ end
86
+
87
+ end
88
+
89
+ end
@@ -2,7 +2,7 @@ require 'delta_test/utils'
2
2
 
3
3
  describe DeltaTest::Utils do
4
4
 
5
- describe '::regulate_filepath' do
5
+ describe '.regulate_filepath' do
6
6
 
7
7
  let(:base_path) { Pathname.new('/base_path') }
8
8
 
@@ -28,7 +28,7 @@ describe DeltaTest::Utils do
28
28
 
29
29
  end
30
30
 
31
- describe '::find_file_upward' do
31
+ describe '.find_file_upward' do
32
32
 
33
33
  let(:file) { FakeFS::FakeFile.new }
34
34
  let(:file_name) { 'file' }
@@ -131,7 +131,7 @@ describe DeltaTest::Utils do
131
131
 
132
132
  end
133
133
 
134
- describe '::grep_pattern_to_regexp' do
134
+ describe '.grep_pattern_to_regexp' do
135
135
 
136
136
  # private method
137
137
  let(:grep_pattern_to_regexp) { DeltaTest::Utils.method(:grep_pattern_to_regexp) }
@@ -177,7 +177,7 @@ describe DeltaTest::Utils do
177
177
 
178
178
  end
179
179
 
180
- describe '::files_grep' do
180
+ describe '.files_grep' do
181
181
 
182
182
  let(:files) do
183
183
  [