delta_test 0.2.0 → 1.0.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +22 -34
- data/Rakefile +5 -2
- data/bin/delta_test +1 -1
- data/circle.yml +5 -1
- data/delta_test.gemspec +1 -1
- data/lib/delta_test/cli/command_base.rb +114 -0
- data/lib/delta_test/cli/exec_command.rb +95 -0
- data/lib/delta_test/cli/help_command.rb +38 -0
- data/lib/delta_test/cli/specs_command.rb +43 -0
- data/lib/delta_test/cli/stats_clean_command.rb +20 -0
- data/lib/delta_test/cli/stats_save_command.rb +67 -0
- data/lib/delta_test/cli/stats_show_command.rb +46 -0
- data/lib/delta_test/cli/version_command.rb +13 -0
- data/lib/delta_test/cli.rb +22 -296
- data/lib/delta_test/configuration.rb +57 -42
- data/lib/delta_test/errors.rb +24 -0
- data/lib/delta_test/generator.rb +4 -24
- data/lib/delta_test/git.rb +161 -80
- data/lib/delta_test/profiler.rb +8 -0
- data/lib/delta_test/related_spec_list.rb +14 -9
- data/lib/delta_test/stats.rb +41 -0
- data/lib/delta_test/version.rb +2 -2
- data/lib/delta_test.rb +14 -9
- data/spec/lib/delta_test/cli/command_base_spec.rb +164 -0
- data/spec/lib/delta_test/cli/exec_command_spec.rb +128 -0
- data/spec/lib/delta_test/cli/help_command_spec.rb +17 -0
- data/spec/lib/delta_test/cli/specs_command_spec.rb +54 -0
- data/spec/lib/delta_test/cli/stats_clean_command_spec.rb +39 -0
- data/spec/lib/delta_test/cli/stats_save_command_spec.rb +207 -0
- data/spec/lib/delta_test/cli/stats_show_command_spec.rb +52 -0
- data/spec/lib/delta_test/cli/version_command_spec.rb +17 -0
- data/spec/lib/delta_test/cli_spec.rb +47 -386
- data/spec/lib/delta_test/configuration_spec.rb +99 -47
- data/spec/lib/delta_test/dependencies_table_spec.rb +1 -1
- data/spec/lib/delta_test/generator_spec.rb +3 -3
- data/spec/lib/delta_test/git_spec.rb +291 -50
- data/spec/lib/delta_test/profiler_spec.rb +3 -3
- data/spec/lib/delta_test/related_spec_list_spec.rb +12 -14
- data/spec/lib/delta_test/stats_spec.rb +89 -0
- data/spec/lib/delta_test/utils_spec.rb +4 -4
- data/spec/lib/delta_test_spec.rb +13 -4
- data/spec/rails/Gemfile.lock +5 -2
- data/spec/rails/app/models/category.rb +4 -0
- data/spec/rails/delta_test.yml +4 -3
- data/spec/rails/spec/models/category_spec.rb +4 -0
- data/spec/spec_helper.rb +9 -2
- data/spec/supports/create_table_file.rb +11 -1
- data/visual.jpg +0 -0
- metadata +32 -4
@@ -1,441 +1,102 @@
|
|
1
1
|
require 'delta_test/cli'
|
2
|
-
require 'delta_test/
|
2
|
+
require 'delta_test/cli/exec_command'
|
3
|
+
require 'delta_test/cli/specs_command'
|
4
|
+
require 'delta_test/cli/stats_clean_command'
|
5
|
+
require 'delta_test/cli/stats_show_command'
|
6
|
+
require 'delta_test/cli/stats_save_command'
|
7
|
+
require 'delta_test/cli/version_command'
|
8
|
+
require 'delta_test/cli/help_command'
|
3
9
|
|
4
10
|
describe DeltaTest::CLI do
|
5
11
|
|
6
|
-
let(:cli) { DeltaTest::CLI.new }
|
7
|
-
|
8
|
-
before do
|
9
|
-
DeltaTest::CLI.class_eval do
|
10
|
-
attr_writer :args
|
11
|
-
attr_writer :options
|
12
|
-
attr_writer :command
|
13
|
-
attr_reader :list
|
14
|
-
end
|
15
|
-
|
16
|
-
# ignore outputs
|
17
|
-
allow($stdout).to receive(:puts).with(any_args).and_return(nil)
|
18
|
-
allow($stderr).to receive(:puts).with(any_args).and_return(nil)
|
19
|
-
end
|
20
|
-
|
21
12
|
describe '#run' do
|
22
13
|
|
23
|
-
|
24
|
-
allow(cli).to receive(:invoke).with(no_args).and_return(nil)
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'should set the first argument as command' do
|
28
|
-
args = ['command', 'foo', 'bar']
|
29
|
-
cli.run(args)
|
30
|
-
expect(cli.command).to eq(args[0])
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'should call `parse_options!` and `invoke`' do
|
34
|
-
expect(cli).to receive(:parse_options!).with(no_args).and_return({}).once.ordered
|
35
|
-
expect(cli).to receive(:invoke).with(no_args).once.ordered
|
36
|
-
|
37
|
-
args = ['command', 'foo', 'bar']
|
38
|
-
cli.run(args)
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
describe '#parse_options!' do
|
44
|
-
|
45
|
-
it 'should parse short options' do
|
46
|
-
cli.args = ['-a', '-b']
|
47
|
-
|
48
|
-
options = cli.parse_options!
|
49
|
-
|
50
|
-
expect(cli.args).to be_empty
|
51
|
-
expect(options).to be_a(Hash)
|
52
|
-
expect(options['a']).to be(true)
|
53
|
-
expect(options['b']).to be(true)
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'should parse long options' do
|
57
|
-
cli.args = ['--long-a', '--long-b']
|
58
|
-
|
59
|
-
options = cli.parse_options!
|
60
|
-
|
61
|
-
expect(cli.args).to be_empty
|
62
|
-
expect(options).to be_a(Hash)
|
63
|
-
expect(options['long-a']).to be(true)
|
64
|
-
expect(options['long-b']).to be(true)
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'should parse long options with value' do
|
68
|
-
cli.args = ['--long-a=value-of-a', '--long-b=value-of-b']
|
69
|
-
|
70
|
-
options = cli.parse_options!
|
71
|
-
|
72
|
-
expect(cli.args).to be_empty
|
73
|
-
expect(options).to be_a(Hash)
|
74
|
-
expect(options['long-a']).to eq('value-of-a')
|
75
|
-
expect(options['long-b']).to eq('value-of-b')
|
76
|
-
end
|
77
|
-
|
78
|
-
it 'should not parse options after once non-option args appears' do
|
79
|
-
cli.args = ['-a', '--long-a', 'non-option', '--long-b=value-of-b']
|
80
|
-
|
81
|
-
options = cli.parse_options!
|
82
|
-
|
83
|
-
expect(cli.args).to eq(['non-option', '--long-b=value-of-b'])
|
84
|
-
expect(options).to be_a(Hash)
|
85
|
-
expect(options['a']).to be(true)
|
86
|
-
expect(options['long-a']).to be(true)
|
87
|
-
expect(options['long-b']).to be_nil
|
88
|
-
end
|
89
|
-
|
90
|
-
describe 'Defaults' do
|
91
|
-
|
92
|
-
it 'should set default options' do
|
93
|
-
cli.args = []
|
94
|
-
|
95
|
-
options = cli.parse_options!
|
14
|
+
describe 'exec' do
|
96
15
|
|
97
|
-
|
16
|
+
it 'should call invoke on ExecCommand' do
|
17
|
+
expect(DeltaTest::CLI::ExecCommand).to receive(:new).with(['echo']).and_call_original
|
18
|
+
expect_any_instance_of(DeltaTest::CLI::ExecCommand).to receive(:invoke).and_return(nil)
|
98
19
|
|
99
|
-
|
100
|
-
expect(options['head']).to eq('HEAD')
|
101
|
-
end
|
102
|
-
|
103
|
-
it 'should be able to overwrite default options' do
|
104
|
-
cli.args = ['--base=develop', '--head=feature/foo']
|
105
|
-
|
106
|
-
options = cli.parse_options!
|
107
|
-
|
108
|
-
expect(options).to be_a(Hash)
|
109
|
-
|
110
|
-
expect(options['base']).to eq('develop')
|
111
|
-
expect(options['head']).to eq('feature/foo')
|
20
|
+
DeltaTest::CLI.new(['exec', 'echo']).run
|
112
21
|
end
|
113
22
|
|
114
23
|
end
|
115
24
|
|
116
|
-
|
117
|
-
|
118
|
-
describe '#exit_with_message' do
|
119
|
-
|
120
|
-
let(:message) { 'a message' }
|
121
|
-
let(:message_regexp) { /a message/ }
|
122
|
-
|
123
|
-
context 'With status code of zero' do
|
25
|
+
describe 'specs' do
|
124
26
|
|
125
|
-
|
27
|
+
it 'should call invoke on SpecsCommand' do
|
28
|
+
expect(DeltaTest::CLI::SpecsCommand).to receive(:new).with([]).and_call_original
|
29
|
+
expect_any_instance_of(DeltaTest::CLI::SpecsCommand).to receive(:invoke).and_return(nil)
|
126
30
|
|
127
|
-
|
128
|
-
expect {
|
129
|
-
begin
|
130
|
-
cli.exit_with_message(status, message)
|
131
|
-
rescue SystemExit => e
|
132
|
-
expect(e.status).to eq(status)
|
133
|
-
end
|
134
|
-
}.to output(message_regexp).to_stdout
|
31
|
+
DeltaTest::CLI.new(['specs']).run
|
135
32
|
end
|
136
33
|
|
137
34
|
end
|
138
35
|
|
139
|
-
|
36
|
+
describe 'stats:clean' do
|
140
37
|
|
141
|
-
|
38
|
+
it 'should call invoke on StatsCleanCommand' do
|
39
|
+
expect(DeltaTest::CLI::StatsCleanCommand).to receive(:new).with([]).and_call_original
|
40
|
+
expect_any_instance_of(DeltaTest::CLI::StatsCleanCommand).to receive(:invoke).and_return(nil)
|
142
41
|
|
143
|
-
|
144
|
-
expect {
|
145
|
-
begin
|
146
|
-
cli.exit_with_message(status, message)
|
147
|
-
rescue SystemExit => e
|
148
|
-
expect(e.status).to eq(status)
|
149
|
-
end
|
150
|
-
}.to output(message_regexp).to_stderr
|
42
|
+
DeltaTest::CLI.new(['stats:clean']).run
|
151
43
|
end
|
152
44
|
|
153
45
|
end
|
154
46
|
|
155
|
-
|
156
|
-
|
157
|
-
describe '#profile_mode?' do
|
158
|
-
|
159
|
-
let(:map) do
|
160
|
-
{
|
161
|
-
'master' => '0000000000000000000000000000000000000000',
|
162
|
-
'feature/foo' => '1111111111111111111111111111111111111111',
|
163
|
-
}
|
164
|
-
end
|
47
|
+
describe 'stats:show' do
|
165
48
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
end
|
170
|
-
end
|
49
|
+
it 'should call invoke on StatsShowCommand' do
|
50
|
+
expect(DeltaTest::CLI::StatsShowCommand).to receive(:new).with([]).and_call_original
|
51
|
+
expect_any_instance_of(DeltaTest::CLI::StatsShowCommand).to receive(:invoke).and_return(nil)
|
171
52
|
|
172
|
-
|
173
|
-
|
174
|
-
before do
|
175
|
-
cli.options = {
|
176
|
-
'base' => 'master',
|
177
|
-
'head' => 'master',
|
178
|
-
}
|
179
|
-
end
|
180
|
-
|
181
|
-
it 'should return true' do
|
182
|
-
expect(cli.profile_mode?).to be(true)
|
53
|
+
DeltaTest::CLI.new(['stats:show']).run
|
183
54
|
end
|
184
55
|
|
185
56
|
end
|
186
57
|
|
187
|
-
|
58
|
+
describe 'stats:save' do
|
188
59
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
'head' => 'feature/foo',
|
193
|
-
}
|
194
|
-
end
|
60
|
+
it 'should call invoke on StatsSaveCommand' do
|
61
|
+
expect(DeltaTest::CLI::StatsSaveCommand).to receive(:new).with([]).and_call_original
|
62
|
+
expect_any_instance_of(DeltaTest::CLI::StatsSaveCommand).to receive(:invoke).and_return(nil)
|
195
63
|
|
196
|
-
|
197
|
-
expect(cli.profile_mode?).to be(false)
|
64
|
+
DeltaTest::CLI.new(['stats:save']).run
|
198
65
|
end
|
199
66
|
|
200
67
|
end
|
201
68
|
|
202
|
-
|
203
|
-
|
204
|
-
context 'Commands' do
|
205
|
-
|
206
|
-
describe '#do_table' do
|
207
|
-
|
208
|
-
let(:table) do
|
209
|
-
{
|
210
|
-
'spec/foo_spec.rb' => ['lib/foo.rb']
|
211
|
-
}
|
212
|
-
end
|
213
|
-
|
214
|
-
before do
|
215
|
-
allow(cli).to receive(:invoke).with(no_args).and_return(nil)
|
69
|
+
describe 'version' do
|
216
70
|
|
217
|
-
|
71
|
+
it 'should call invoke on VersionCommand' do
|
72
|
+
expect(DeltaTest::CLI::VersionCommand).to receive(:new).with([]).and_call_original
|
73
|
+
expect_any_instance_of(DeltaTest::CLI::VersionCommand).to receive(:invoke).and_return(nil)
|
218
74
|
|
219
|
-
|
220
|
-
allow(cli.list).to receive(:table).with(no_args).and_return(table)
|
221
|
-
end
|
222
|
-
|
223
|
-
it 'should load a table file' do
|
224
|
-
expect(cli.list).to receive(:load_table!).with(no_args).once.ordered
|
225
|
-
expect(cli.list).to receive(:table).with(no_args).once.ordered
|
226
|
-
|
227
|
-
expect {
|
228
|
-
cli.do_table
|
229
|
-
}.not_to raise_error
|
230
|
-
end
|
231
|
-
|
232
|
-
it 'should show the table contents' do
|
233
|
-
expect(cli.list).to receive(:load_table!).with(no_args).once.ordered
|
234
|
-
expect(cli.list).to receive(:table).with(no_args).once.ordered
|
235
|
-
|
236
|
-
expect {
|
237
|
-
cli.do_table
|
238
|
-
}.to output(/foo_spec\.rb/).to_stdout
|
75
|
+
DeltaTest::CLI.new(['version']).run
|
239
76
|
end
|
240
77
|
|
241
78
|
end
|
242
79
|
|
243
|
-
describe '
|
244
|
-
|
245
|
-
let(:related_spec_files) do
|
246
|
-
[
|
247
|
-
'spec/foo_spec.rb',
|
248
|
-
]
|
249
|
-
end
|
80
|
+
describe 'help' do
|
250
81
|
|
251
|
-
|
252
|
-
|
82
|
+
it 'should call invoke on HelpCommand' do
|
83
|
+
expect(DeltaTest::CLI::HelpCommand).to receive(:new).with([]).and_call_original
|
84
|
+
expect_any_instance_of(DeltaTest::CLI::HelpCommand).to receive(:invoke).and_return(nil)
|
253
85
|
|
254
|
-
|
255
|
-
|
256
|
-
allow(cli.list).to receive(:load_table!).with(no_args).and_return(nil)
|
257
|
-
allow(cli.list).to receive(:retrive_changed_files!).with(any_args).and_return(nil)
|
258
|
-
allow(cli.list).to receive(:related_spec_files).with(no_args).and_return(related_spec_files)
|
259
|
-
end
|
260
|
-
|
261
|
-
it 'should load a table file and retrive changed files' do
|
262
|
-
expect(cli.list).to receive(:load_table!).with(no_args).once.ordered
|
263
|
-
expect(cli.list).to receive(:retrive_changed_files!).with(any_args).once.ordered
|
264
|
-
|
265
|
-
expect {
|
266
|
-
cli.do_list
|
267
|
-
}.not_to raise_error
|
268
|
-
end
|
269
|
-
|
270
|
-
it 'should show a list of related spec files' do
|
271
|
-
expect(cli.list).to receive(:load_table!).with(no_args).once.ordered
|
272
|
-
expect(cli.list).to receive(:retrive_changed_files!).with(any_args).once.ordered
|
273
|
-
expect(cli.list).to receive(:related_spec_files).with(no_args).once.ordered
|
274
|
-
|
275
|
-
expect {
|
276
|
-
cli.do_list
|
277
|
-
}.to output(/foo_spec\.rb/).to_stdout
|
86
|
+
DeltaTest::CLI.new(['help']).run
|
278
87
|
end
|
279
88
|
|
280
89
|
end
|
281
90
|
|
282
|
-
describe '
|
91
|
+
describe '(other)' do
|
283
92
|
|
284
|
-
|
285
|
-
[
|
286
|
-
|
93
|
+
it 'should call invoke on HelpCommand' do
|
94
|
+
expect(DeltaTest::CLI::HelpCommand).to receive(:new).with([]).and_call_original
|
95
|
+
expect_any_instance_of(DeltaTest::CLI::HelpCommand).to receive(:invoke).and_return(nil)
|
287
96
|
|
288
|
-
|
289
|
-
[
|
290
|
-
'spec/foo_spec.rb',
|
291
|
-
]
|
97
|
+
DeltaTest::CLI.new(['foo']).run
|
292
98
|
end
|
293
99
|
|
294
|
-
before do
|
295
|
-
allow(cli).to receive(:invoke).with(no_args).and_return(nil)
|
296
|
-
|
297
|
-
cli.run(args)
|
298
|
-
|
299
|
-
allow(cli.list).to receive(:load_table!).with(no_args).and_return(nil)
|
300
|
-
allow(cli.list).to receive(:retrive_changed_files!).with(any_args).and_return(nil)
|
301
|
-
allow(cli.list).to receive(:related_spec_files).with(no_args).and_return(related_spec_files)
|
302
|
-
|
303
|
-
allow(Open3).to receive(:popen3).with(any_args).and_return(nil)
|
304
|
-
end
|
305
|
-
|
306
|
-
context 'Full tests' do
|
307
|
-
|
308
|
-
before do
|
309
|
-
allow(cli).to receive(:profile_mode?).with(no_args).and_return(true)
|
310
|
-
end
|
311
|
-
|
312
|
-
it 'should run script with a flag' do
|
313
|
-
expect(cli.list).not_to receive(:related_spec_files).with(no_args)
|
314
|
-
|
315
|
-
_args = ['%s=%s' % [DeltaTest::ACTIVE_FLAG, true], *args[1..-1]].join(' ')
|
316
|
-
expect(Open3).to receive(:popen3).with(_args)
|
317
|
-
|
318
|
-
expect {
|
319
|
-
cli.do_exec
|
320
|
-
}.not_to raise_error
|
321
|
-
end
|
322
|
-
|
323
|
-
end
|
324
|
-
|
325
|
-
context 'Partial tests' do
|
326
|
-
|
327
|
-
before do
|
328
|
-
allow(cli).to receive(:profile_mode?).with(no_args).and_return(false)
|
329
|
-
end
|
330
|
-
|
331
|
-
context 'Any related files' do
|
332
|
-
|
333
|
-
it 'should run script with related spec files' do
|
334
|
-
expect(cli.list).to receive(:related_spec_files).with(no_args)
|
335
|
-
|
336
|
-
_args = ['cat', '|', 'xargs', *args[1..-1]].join(' ')
|
337
|
-
expect(Open3).to receive(:popen3).with(_args)
|
338
|
-
|
339
|
-
expect {
|
340
|
-
cli.do_exec
|
341
|
-
}.not_to raise_error
|
342
|
-
end
|
343
|
-
|
344
|
-
end
|
345
|
-
|
346
|
-
context 'No related files' do
|
347
|
-
|
348
|
-
let(:related_spec_files) { [] }
|
349
|
-
|
350
|
-
it 'should not run script and exit with a message' do
|
351
|
-
expect(cli.list).to receive(:related_spec_files).with(no_args)
|
352
|
-
|
353
|
-
expect {
|
354
|
-
begin
|
355
|
-
cli.do_exec
|
356
|
-
rescue SystemExit => e
|
357
|
-
expect(e.status).to eq(0)
|
358
|
-
end
|
359
|
-
}.to output(/Nothing/).to_stdout
|
360
|
-
end
|
361
|
-
|
362
|
-
end
|
363
|
-
|
364
|
-
end
|
365
|
-
|
366
|
-
end
|
367
|
-
|
368
|
-
describe '#do_clear' do
|
369
|
-
|
370
|
-
before do
|
371
|
-
allow(Open3).to receive(:capture3).and_return(nil)
|
372
|
-
end
|
373
|
-
|
374
|
-
let(:table_file_path) { '/path/to/table' }
|
375
|
-
|
376
|
-
it 'should remove table files' do
|
377
|
-
allow(DeltaTest.config).to receive(:table_file_path).and_return(table_file_path)
|
378
|
-
expect(DeltaTest.config).to receive(:table_file_path).with('')
|
379
|
-
expect(Open3).to receive(:capture3).with('rm %s*' % table_file_path)
|
380
|
-
|
381
|
-
expect {
|
382
|
-
cli.do_clear
|
383
|
-
}.not_to raise_error
|
384
|
-
end
|
385
|
-
|
386
|
-
end
|
387
|
-
|
388
|
-
describe '#do_help' do
|
389
|
-
|
390
|
-
it 'should print help' do
|
391
|
-
expect {
|
392
|
-
cli.do_help
|
393
|
-
}.to output(/usage/).to_stdout
|
394
|
-
end
|
395
|
-
|
396
|
-
end
|
397
|
-
|
398
|
-
describe '#do_version' do
|
399
|
-
|
400
|
-
it 'should print gem version' do
|
401
|
-
expect {
|
402
|
-
cli.do_version
|
403
|
-
}.to output(/v\d+\.\d+.\d+/).to_stdout
|
404
|
-
end
|
405
|
-
|
406
|
-
end
|
407
|
-
|
408
|
-
end
|
409
|
-
|
410
|
-
describe '#invoke' do
|
411
|
-
|
412
|
-
let(:commands) do
|
413
|
-
{
|
414
|
-
'list' => 'do_list',
|
415
|
-
'table' => 'do_table',
|
416
|
-
'exec' => 'do_exec',
|
417
|
-
'clear' => 'do_clear',
|
418
|
-
'help' => 'do_help',
|
419
|
-
'-v' => 'do_version',
|
420
|
-
}
|
421
|
-
end
|
422
|
-
|
423
|
-
before do
|
424
|
-
commands.each do |_, action|
|
425
|
-
allow(cli).to receive(action).with(no_args).and_return(nil)
|
426
|
-
end
|
427
|
-
end
|
428
|
-
|
429
|
-
it 'should invoke method for a command' do
|
430
|
-
commands.each do |command, action|
|
431
|
-
expect(cli).to receive(action).with(no_args)
|
432
|
-
|
433
|
-
cli.command = command
|
434
|
-
|
435
|
-
expect {
|
436
|
-
cli.invoke
|
437
|
-
}.not_to raise_error
|
438
|
-
end
|
439
100
|
end
|
440
101
|
|
441
102
|
end
|