delta_test 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +4 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +165 -0
- data/Rakefile +17 -0
- data/bin/delta_test +12 -0
- data/circle.yml +12 -0
- data/delta_test.gemspec +30 -0
- data/lib/delta_test/analyzer.rb +47 -0
- data/lib/delta_test/cli.rb +224 -0
- data/lib/delta_test/configuration.rb +173 -0
- data/lib/delta_test/dependencies_table.rb +83 -0
- data/lib/delta_test/errors.rb +55 -0
- data/lib/delta_test/generator.rb +101 -0
- data/lib/delta_test/git.rb +88 -0
- data/lib/delta_test/related_spec_list.rb +64 -0
- data/lib/delta_test/spec_helpers.rb +42 -0
- data/lib/delta_test/utils.rb +93 -0
- data/lib/delta_test/version.rb +9 -0
- data/lib/delta_test.rb +47 -0
- data/spec/fixtures/sample/alpha.rb +19 -0
- data/spec/fixtures/sample/beta.rb +15 -0
- data/spec/fixtures/sample/gamma.rb +9 -0
- data/spec/lib/delta_test/analyzer_spec.rb +126 -0
- data/spec/lib/delta_test/cli_spec.rb +422 -0
- data/spec/lib/delta_test/configuration_spec.rb +353 -0
- data/spec/lib/delta_test/dependencies_table_spec.rb +129 -0
- data/spec/lib/delta_test/generator_spec.rb +201 -0
- data/spec/lib/delta_test/git_spec.rb +178 -0
- data/spec/lib/delta_test/related_spec_list_spec.rb +182 -0
- data/spec/lib/delta_test/spec_helpers_spec.rb +72 -0
- data/spec/lib/delta_test/utils_spec.rb +244 -0
- data/spec/lib/delta_test_spec.rb +119 -0
- data/spec/rails/.gitignore +19 -0
- data/spec/rails/.rspec +3 -0
- data/spec/rails/Gemfile +15 -0
- data/spec/rails/Gemfile.lock +163 -0
- data/spec/rails/README.rdoc +28 -0
- data/spec/rails/Rakefile +6 -0
- data/spec/rails/app/controllers/application_controller.rb +5 -0
- data/spec/rails/app/controllers/concerns/.keep +0 -0
- data/spec/rails/app/helpers/application_helper.rb +2 -0
- data/spec/rails/app/mailers/.keep +0 -0
- data/spec/rails/app/models/.keep +0 -0
- data/spec/rails/app/models/concerns/.keep +0 -0
- data/spec/rails/app/views/layouts/application.html.haml +7 -0
- data/spec/rails/bin/bundle +3 -0
- data/spec/rails/bin/rails +4 -0
- data/spec/rails/bin/rake +4 -0
- data/spec/rails/bin/setup +29 -0
- data/spec/rails/config/application.rb +35 -0
- data/spec/rails/config/boot.rb +3 -0
- data/spec/rails/config/database.yml +25 -0
- data/spec/rails/config/environment.rb +5 -0
- data/spec/rails/config/environments/development.rb +41 -0
- data/spec/rails/config/environments/production.rb +79 -0
- data/spec/rails/config/environments/test.rb +42 -0
- data/spec/rails/config/initializers/assets.rb +11 -0
- data/spec/rails/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/rails/config/initializers/cookies_serializer.rb +3 -0
- data/spec/rails/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/rails/config/initializers/inflections.rb +16 -0
- data/spec/rails/config/initializers/mime_types.rb +4 -0
- data/spec/rails/config/initializers/session_store.rb +3 -0
- data/spec/rails/config/initializers/wrap_parameters.rb +14 -0
- data/spec/rails/config/locales/en.yml +23 -0
- data/spec/rails/config/routes.rb +56 -0
- data/spec/rails/config/secrets.yml +22 -0
- data/spec/rails/config.ru +4 -0
- data/spec/rails/db/seeds.rb +7 -0
- data/spec/rails/delta_test.yml +5 -0
- data/spec/rails/lib/assets/.keep +0 -0
- data/spec/rails/lib/tasks/.keep +0 -0
- data/spec/rails/log/.keep +0 -0
- data/spec/rails/public/404.html +67 -0
- data/spec/rails/public/422.html +67 -0
- data/spec/rails/public/500.html +66 -0
- data/spec/rails/public/favicon.ico +0 -0
- data/spec/rails/public/robots.txt +5 -0
- data/spec/rails/spec/features/sample_spec.rb +7 -0
- data/spec/rails/spec/spec_helper.rb +16 -0
- data/spec/rails/vendor/assets/javascripts/.keep +0 -0
- data/spec/rails/vendor/assets/stylesheets/.keep +0 -0
- data/spec/spec_helper.rb +39 -0
- data/spec/supports/create_table_file.rb +21 -0
- metadata +283 -0
@@ -0,0 +1,353 @@
|
|
1
|
+
describe DeltaTest::Configuration do
|
2
|
+
|
3
|
+
let(:configuration) { DeltaTest::Configuration.new }
|
4
|
+
|
5
|
+
describe '::new' do
|
6
|
+
|
7
|
+
let(:options) do
|
8
|
+
%i[
|
9
|
+
base_path
|
10
|
+
table_file
|
11
|
+
files
|
12
|
+
]
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should set default values' do
|
16
|
+
options.each do |option|
|
17
|
+
expect(configuration.respond_to?(option)).to be(true)
|
18
|
+
expect(configuration.send(option)).not_to be_nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#base_path, #base_path=' do
|
25
|
+
|
26
|
+
it 'should return an instance of Pathname' do
|
27
|
+
expect(configuration.base_path).to be_a(Pathname)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should store an instance of Pathname from a string in the setter' do
|
31
|
+
path = 'foo/bar'
|
32
|
+
|
33
|
+
expect {
|
34
|
+
configuration.base_path = path
|
35
|
+
}.not_to raise_error
|
36
|
+
|
37
|
+
expect(configuration.base_path).to be_a(Pathname)
|
38
|
+
expect(configuration.base_path.to_s).to eq(path)
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#table_file, #table_file=' do
|
44
|
+
|
45
|
+
it 'should return an instance of Pathname' do
|
46
|
+
expect(configuration.table_file).to be_a(Pathname)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should store an instance of Pathname from a string in the setter' do
|
50
|
+
path = 'foo/bar'
|
51
|
+
|
52
|
+
expect {
|
53
|
+
configuration.table_file = path
|
54
|
+
}.not_to raise_error
|
55
|
+
|
56
|
+
expect(configuration.table_file).to be_a(Pathname)
|
57
|
+
expect(configuration.table_file.to_s).to eq(path)
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#validate!' do
|
63
|
+
|
64
|
+
describe '#base_path' do
|
65
|
+
|
66
|
+
it 'should raise an error if `base_path` is a relative path' do
|
67
|
+
configuration.base_path = "relative/path"
|
68
|
+
|
69
|
+
expect {
|
70
|
+
configuration.validate!
|
71
|
+
}.to raise_error(/base_path/)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should not raise if `base_path` is a absolute path' do
|
75
|
+
configuration.base_path = "/absolute/path"
|
76
|
+
|
77
|
+
expect {
|
78
|
+
configuration.validate!
|
79
|
+
}.not_to raise_error
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
describe '#files' do
|
85
|
+
|
86
|
+
it 'should raise an error if `files` is not set' do
|
87
|
+
configuration.files = nil
|
88
|
+
|
89
|
+
expect {
|
90
|
+
configuration.validate!
|
91
|
+
}.to raise_error(/files/)
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should raise an error if `files` is neither an array' do
|
95
|
+
configuration.files = {}
|
96
|
+
|
97
|
+
expect {
|
98
|
+
configuration.validate!
|
99
|
+
}.to raise_error(/files/)
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'should not raise if `files` is an array' do
|
103
|
+
configuration.files = []
|
104
|
+
|
105
|
+
expect {
|
106
|
+
configuration.validate!
|
107
|
+
}.not_to raise_error
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
describe '#patterns' do
|
113
|
+
|
114
|
+
it 'should raise an error if `patterns` is not set' do
|
115
|
+
configuration.patterns = nil
|
116
|
+
|
117
|
+
expect {
|
118
|
+
configuration.validate!
|
119
|
+
}.to raise_error(/patterns/)
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'should raise an error if `patterns` is neither an array' do
|
123
|
+
configuration.patterns = {}
|
124
|
+
|
125
|
+
expect {
|
126
|
+
configuration.validate!
|
127
|
+
}.to raise_error(/patterns/)
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'should not raise if `patterns` is an array' do
|
131
|
+
configuration.patterns = []
|
132
|
+
|
133
|
+
expect {
|
134
|
+
configuration.validate!
|
135
|
+
}.not_to raise_error
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
139
|
+
|
140
|
+
describe '#exclude_patterns' do
|
141
|
+
|
142
|
+
it 'should raise an error if `exclude_patterns` is not set' do
|
143
|
+
configuration.exclude_patterns = nil
|
144
|
+
|
145
|
+
expect {
|
146
|
+
configuration.validate!
|
147
|
+
}.to raise_error(/patterns/)
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'should raise an error if `exclude_patterns` is neither an array' do
|
151
|
+
configuration.exclude_patterns = {}
|
152
|
+
|
153
|
+
expect {
|
154
|
+
configuration.validate!
|
155
|
+
}.to raise_error(/exclude_patterns/)
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'should not raise if `exclude_patterns` is an array' do
|
159
|
+
configuration.exclude_patterns = []
|
160
|
+
|
161
|
+
expect {
|
162
|
+
configuration.validate!
|
163
|
+
}.not_to raise_error
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|
169
|
+
|
170
|
+
describe '#precalculate!' do
|
171
|
+
|
172
|
+
describe '#filtered_files' do
|
173
|
+
|
174
|
+
it 'should return an instance of Set' do
|
175
|
+
configuration.precalculate!
|
176
|
+
expect(configuration.filtered_files).to be_a(Set)
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'should return a set of filtered file paths' do
|
180
|
+
base_path = '/base_path'
|
181
|
+
patterns = [
|
182
|
+
'**/*r'
|
183
|
+
]
|
184
|
+
files = [
|
185
|
+
'/base_path/foo/bar',
|
186
|
+
'/base_path/foo/bar',
|
187
|
+
'/base_path/foo/bar/baz',
|
188
|
+
]
|
189
|
+
filtered_files = Set[
|
190
|
+
Pathname.new('foo/bar'),
|
191
|
+
]
|
192
|
+
|
193
|
+
configuration.base_path = base_path
|
194
|
+
configuration.files = files
|
195
|
+
configuration.patterns = patterns
|
196
|
+
|
197
|
+
configuration.precalculate!
|
198
|
+
expect(configuration.filtered_files).to eq(filtered_files)
|
199
|
+
end
|
200
|
+
|
201
|
+
end
|
202
|
+
|
203
|
+
describe '#table_file_path' do
|
204
|
+
|
205
|
+
it 'should return an absolute path to the table file if `table_file` is a relative' do
|
206
|
+
configuration.base_path = '/base_path'
|
207
|
+
configuration.table_file = 'somewhere/table_file'
|
208
|
+
|
209
|
+
configuration.precalculate!
|
210
|
+
expect(configuration.table_file_path).to eq(Pathname.new('/base_path/somewhere/table_file'))
|
211
|
+
end
|
212
|
+
|
213
|
+
it 'should return the same value to the table file if `table_file` is a absolute' do
|
214
|
+
configuration.base_path = '/base_path'
|
215
|
+
configuration.table_file = '/somewhere/table_file'
|
216
|
+
|
217
|
+
configuration.precalculate!
|
218
|
+
expect(configuration.table_file_path).to eq(Pathname.new('/somewhere/table_file'))
|
219
|
+
end
|
220
|
+
|
221
|
+
end
|
222
|
+
|
223
|
+
end
|
224
|
+
|
225
|
+
describe '#update' do
|
226
|
+
|
227
|
+
it 'should call `validate!` and `precalculate!` after the block' do
|
228
|
+
dummy = double
|
229
|
+
allow(dummy).to receive(:not_yet_called)
|
230
|
+
allow(dummy).to receive(:already_called)
|
231
|
+
|
232
|
+
expect(dummy).to receive(:not_yet_called).with(no_args).once.ordered
|
233
|
+
expect(configuration).to receive(:validate!).with(no_args).once.ordered
|
234
|
+
expect(configuration).to receive(:precalculate!).with(no_args).once.ordered
|
235
|
+
expect(dummy).to receive(:already_called).with(no_args).once.ordered
|
236
|
+
|
237
|
+
configuration.update do |config|
|
238
|
+
dummy.not_yet_called
|
239
|
+
end
|
240
|
+
|
241
|
+
dummy.already_called
|
242
|
+
end
|
243
|
+
|
244
|
+
end
|
245
|
+
|
246
|
+
describe 'Auto configuration' do
|
247
|
+
|
248
|
+
describe '#auto_configure!' do
|
249
|
+
|
250
|
+
it 'should call `load_from_file!`, `retrive_files_from_git_index!` and `update`' do
|
251
|
+
allow(configuration).to receive(:load_from_file!).and_return(true)
|
252
|
+
allow(configuration).to receive(:retrive_files_from_git_index!).and_return(true)
|
253
|
+
|
254
|
+
expect(configuration).to receive(:load_from_file!).with(no_args).once.ordered
|
255
|
+
expect(configuration).to receive(:retrive_files_from_git_index!).with(no_args).once.ordered
|
256
|
+
expect(configuration).to receive(:update).with(no_args).once.ordered
|
257
|
+
|
258
|
+
configuration.auto_configure!
|
259
|
+
end
|
260
|
+
|
261
|
+
end
|
262
|
+
|
263
|
+
describe '#load_from_file!' do
|
264
|
+
|
265
|
+
let(:pwd) { '/path/to/pwd' }
|
266
|
+
let(:yaml_file_path) { '/path/to/delta_test.yml' }
|
267
|
+
let(:table_file_path) { '/path/to/table_file' }
|
268
|
+
|
269
|
+
let(:yaml_file) do
|
270
|
+
file = FakeFS::FakeFile.new
|
271
|
+
|
272
|
+
file.content = <<-YAML
|
273
|
+
table_file: #{table_file_path}
|
274
|
+
YAML
|
275
|
+
|
276
|
+
file
|
277
|
+
end
|
278
|
+
|
279
|
+
before do
|
280
|
+
FakeFS::FileSystem.add(pwd)
|
281
|
+
Dir.chdir(pwd)
|
282
|
+
end
|
283
|
+
|
284
|
+
it 'should raise an error if no file is found' do
|
285
|
+
expect {
|
286
|
+
configuration.load_from_file!
|
287
|
+
}.to raise_error(DeltaTest::NoConfigurationFileFoundError)
|
288
|
+
end
|
289
|
+
|
290
|
+
it 'should set `base_path` to the directory of yaml file' do
|
291
|
+
FakeFS::FileSystem.add(yaml_file_path, yaml_file)
|
292
|
+
|
293
|
+
expect {
|
294
|
+
configuration.load_from_file!
|
295
|
+
}.not_to raise_error
|
296
|
+
|
297
|
+
expect(configuration.base_path).to eq(Pathname.new(File.dirname(yaml_file_path)))
|
298
|
+
end
|
299
|
+
|
300
|
+
it 'should set other option values from yaml' do
|
301
|
+
FakeFS::FileSystem.add(yaml_file_path, yaml_file)
|
302
|
+
|
303
|
+
expect {
|
304
|
+
configuration.load_from_file!
|
305
|
+
}.not_to raise_error
|
306
|
+
|
307
|
+
expect(configuration.table_file).to eq(Pathname.new(table_file_path))
|
308
|
+
end
|
309
|
+
|
310
|
+
it 'should raise an error if there is invalid option in yaml' do
|
311
|
+
FakeFS::FileSystem.add(yaml_file_path, yaml_file)
|
312
|
+
yaml_file.content = <<-YAML
|
313
|
+
foo: true
|
314
|
+
YAML
|
315
|
+
|
316
|
+
expect {
|
317
|
+
configuration.load_from_file!
|
318
|
+
}.to raise_error(DeltaTest::InvalidOptionError, /foo/)
|
319
|
+
end
|
320
|
+
|
321
|
+
end
|
322
|
+
|
323
|
+
describe 'retrive_files_from_git_index!' do
|
324
|
+
|
325
|
+
it 'should raise an error if not in git repo' do
|
326
|
+
allow(DeltaTest::Git).to receive(:git_repo?).with(no_args).and_return(false)
|
327
|
+
|
328
|
+
expect {
|
329
|
+
configuration.retrive_files_from_git_index!
|
330
|
+
}.to raise_error(DeltaTest::NotInGitRepositoryError)
|
331
|
+
end
|
332
|
+
|
333
|
+
it 'should set `files` from the file indices of git' do
|
334
|
+
files = [
|
335
|
+
'a/file_1',
|
336
|
+
'a/file_2',
|
337
|
+
]
|
338
|
+
|
339
|
+
allow(DeltaTest::Git).to receive(:git_repo?).with(no_args).and_return(true)
|
340
|
+
allow(DeltaTest::Git).to receive(:ls_files).with(no_args).and_return(files)
|
341
|
+
|
342
|
+
expect {
|
343
|
+
configuration.retrive_files_from_git_index!
|
344
|
+
}.not_to raise_error
|
345
|
+
|
346
|
+
expect(configuration.files).to eq(files)
|
347
|
+
end
|
348
|
+
|
349
|
+
end
|
350
|
+
|
351
|
+
end
|
352
|
+
|
353
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require 'delta_test/dependencies_table'
|
2
|
+
|
3
|
+
describe DeltaTest::DependenciesTable do
|
4
|
+
|
5
|
+
it 'should be a subclass of Hash' do
|
6
|
+
expect(DeltaTest::DependenciesTable).to be < Hash
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
let(:table) { DeltaTest::DependenciesTable.new }
|
11
|
+
|
12
|
+
describe '#[]' do
|
13
|
+
|
14
|
+
it 'should initiate an empty set if not accessed before' do
|
15
|
+
value = table[:foo]
|
16
|
+
expect(value).to be_a(Set)
|
17
|
+
expect(value).to be_empty
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should retain objects throughout accesses' do
|
21
|
+
foo_1 = table[:foo].object_id
|
22
|
+
foo_2 = table[:foo].object_id
|
23
|
+
expect(foo_1).to eq(foo_2)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#add' do
|
29
|
+
|
30
|
+
let(:spec_file) { 'spec/foo_spec.rb' }
|
31
|
+
let(:base_path) { '/base_path' }
|
32
|
+
|
33
|
+
let(:files) do
|
34
|
+
['foo/file_1.txt']
|
35
|
+
end
|
36
|
+
|
37
|
+
before do
|
38
|
+
DeltaTest.configure do |config|
|
39
|
+
config.base_path = base_path
|
40
|
+
config.files = files
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should add a regulated file path' do
|
45
|
+
table.add(spec_file, '/base_path/foo/file_1.txt')
|
46
|
+
expect(table[spec_file]).to eq(Set[Pathname.new('foo/file_1.txt')])
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should add nothing if a file path is not included in `files` set' do
|
50
|
+
table.add(spec_file, '/base_path/foo/file_2.txt')
|
51
|
+
expect(table[spec_file]).to be_empty
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '#without_default_proc' do
|
57
|
+
|
58
|
+
it 'should reset default_proc temporary inside a block' do
|
59
|
+
expect(table.default_proc).not_to be_nil
|
60
|
+
table.without_default_proc do
|
61
|
+
expect(table.default_proc).to be_nil
|
62
|
+
end
|
63
|
+
expect(table.default_proc).not_to be_nil
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '#cleanup!' do
|
69
|
+
|
70
|
+
it 'should delete items where value is an empty set' do
|
71
|
+
table[:foo]
|
72
|
+
table[:bar] << 1
|
73
|
+
expect(table.keys).to eq([:foo, :bar])
|
74
|
+
table.cleanup!
|
75
|
+
expect(table.keys).to eq([:bar])
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
shared_examples :_create_table do
|
81
|
+
|
82
|
+
include_examples :create_table_file
|
83
|
+
|
84
|
+
let!(:table) do
|
85
|
+
table = DeltaTest::DependenciesTable.new
|
86
|
+
|
87
|
+
table[:foo] << 1
|
88
|
+
table[:foo] << 2
|
89
|
+
table[:bar] << 10
|
90
|
+
table[:bar] << 20
|
91
|
+
|
92
|
+
table
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
describe '#dump' do
|
98
|
+
|
99
|
+
include_examples :_create_table
|
100
|
+
|
101
|
+
it 'should dump a table object to a file' do
|
102
|
+
expect(table_file.content).to be_empty
|
103
|
+
|
104
|
+
expect {
|
105
|
+
table.dump(table_file_path)
|
106
|
+
}.not_to raise_error
|
107
|
+
|
108
|
+
expect(table_file.content).not_to be_empty
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
describe '::load' do
|
114
|
+
|
115
|
+
include_examples :_create_table
|
116
|
+
|
117
|
+
it 'should restore a table object from a file' do
|
118
|
+
table.dump(table_file_path)
|
119
|
+
restored_table = nil
|
120
|
+
expect {
|
121
|
+
restored_table = DeltaTest::DependenciesTable.load(table_file_path)
|
122
|
+
}.not_to raise_error
|
123
|
+
expect(restored_table).to be_a(DeltaTest::DependenciesTable)
|
124
|
+
expect(restored_table).to eq(table)
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
@@ -0,0 +1,201 @@
|
|
1
|
+
require 'delta_test/generator'
|
2
|
+
|
3
|
+
describe DeltaTest::Generator do
|
4
|
+
|
5
|
+
include_examples :create_table_file
|
6
|
+
|
7
|
+
let(:base_path) { Pathname.new(File.expand_path('../../../fixtures', __FILE__)) }
|
8
|
+
|
9
|
+
let(:spec_file) { 'foo/spec_file.rb' }
|
10
|
+
let(:spec_file_2) { 'foo/spec_file_2.rb' }
|
11
|
+
|
12
|
+
let(:files) do
|
13
|
+
[
|
14
|
+
'sample/alpha.rb',
|
15
|
+
'sample/beta.rb',
|
16
|
+
# 'sample/gamma.rb', # intentionally omitted
|
17
|
+
]
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:generator) { DeltaTest::Generator.new }
|
21
|
+
|
22
|
+
before do
|
23
|
+
DeltaTest.configure do |config|
|
24
|
+
config.base_path = base_path
|
25
|
+
config.table_file = table_file_path
|
26
|
+
config.files = files
|
27
|
+
end
|
28
|
+
|
29
|
+
DeltaTest.active = true
|
30
|
+
end
|
31
|
+
|
32
|
+
after do
|
33
|
+
DeltaTest.active = false
|
34
|
+
RubyProf.stop if RubyProf.running?
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#setup!' do
|
38
|
+
|
39
|
+
it 'should setup a generator' do
|
40
|
+
expect {
|
41
|
+
generator.setup!(false) # disable tearadown
|
42
|
+
}.not_to raise_error
|
43
|
+
|
44
|
+
expect(generator).to be_respond_to(:table)
|
45
|
+
expect(generator.table).to be_a(DeltaTest::DependenciesTable)
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '#start!' do
|
51
|
+
|
52
|
+
before do
|
53
|
+
generator.setup!(false) # disable tearadown
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should start ruby-prof' do
|
57
|
+
expect(RubyProf.running?).to be(false)
|
58
|
+
|
59
|
+
expect {
|
60
|
+
generator.start!(spec_file)
|
61
|
+
}.not_to raise_error
|
62
|
+
|
63
|
+
expect(RubyProf.running?).to be(true)
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '#current_spec_file' do
|
67
|
+
|
68
|
+
it 'should be set' do
|
69
|
+
expect(generator.current_spec_file).to be_nil
|
70
|
+
generator.start!(spec_file)
|
71
|
+
expect(generator.current_spec_file).to eq(spec_file)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should be regulated' do
|
75
|
+
expect(generator.current_spec_file).to be_nil
|
76
|
+
generator.start!('./%s' % spec_file)
|
77
|
+
expect(generator.current_spec_file).to eq(spec_file)
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
describe '#stop!' do
|
85
|
+
|
86
|
+
before do
|
87
|
+
generator.setup!(false) # disable tearadown
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'should stop ruby-prof' do
|
91
|
+
expect(RubyProf.running?).to be(false)
|
92
|
+
generator.start!(spec_file)
|
93
|
+
expect(RubyProf.running?).to be(true)
|
94
|
+
generator.stop!
|
95
|
+
expect(RubyProf.running?).to be(false)
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'should unset current_spec_file' do
|
99
|
+
expect(generator.current_spec_file).to be_nil
|
100
|
+
generator.start!(spec_file)
|
101
|
+
expect(generator.current_spec_file).to eq(spec_file)
|
102
|
+
generator.stop!
|
103
|
+
expect(generator.current_spec_file).to be_nil
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
describe '#table' do
|
109
|
+
|
110
|
+
before do
|
111
|
+
generator.setup!(false) # disable tearadown
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'should return a set of source files' do
|
115
|
+
expect(generator.table).to be_empty
|
116
|
+
|
117
|
+
generator.start!(spec_file)
|
118
|
+
Sample::Alpha.new.alpha
|
119
|
+
generator.stop!
|
120
|
+
|
121
|
+
expect(generator.table.keys).to eq([spec_file])
|
122
|
+
expect(generator.table[spec_file]).to include(Pathname.new('sample/alpha.rb'))
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'should return a set of source files for every spec files' do
|
126
|
+
expect(generator.table).to be_empty
|
127
|
+
|
128
|
+
generator.start!(spec_file)
|
129
|
+
Sample::Alpha.new.alpha
|
130
|
+
generator.stop!
|
131
|
+
|
132
|
+
generator.start!(spec_file_2)
|
133
|
+
Sample::Beta.new.beta
|
134
|
+
generator.stop!
|
135
|
+
|
136
|
+
expect(generator.table.keys).to eq([spec_file, spec_file_2])
|
137
|
+
expect(generator.table[spec_file]).to include(Pathname.new('sample/alpha.rb'))
|
138
|
+
expect(generator.table[spec_file_2]).to include(Pathname.new('sample/beta.rb'))
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'should not include paths not included in `files`' do
|
142
|
+
expect(generator.table).to be_empty
|
143
|
+
|
144
|
+
generator.start!(spec_file)
|
145
|
+
Sample::Alpha.new.beta_gamma
|
146
|
+
generator.stop!
|
147
|
+
|
148
|
+
expect(generator.table.keys).to eq([spec_file])
|
149
|
+
expect(generator.table[spec_file]).to include(Pathname.new('sample/alpha.rb'))
|
150
|
+
expect(generator.table[spec_file]).to include(Pathname.new('sample/beta.rb'))
|
151
|
+
expect(generator.table[spec_file]).not_to include(Pathname.new('sample/gamma.rb'))
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|
155
|
+
|
156
|
+
describe '#teardown!' do
|
157
|
+
|
158
|
+
context 'When not `setup!` is called yet' do
|
159
|
+
|
160
|
+
it 'should do nothing' do
|
161
|
+
expect {
|
162
|
+
generator.teardown!
|
163
|
+
}.not_to raise_error
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
167
|
+
|
168
|
+
context 'When `setup!` is called' do
|
169
|
+
|
170
|
+
before do
|
171
|
+
generator.setup!(false) # disable tearadown
|
172
|
+
end
|
173
|
+
|
174
|
+
it 'should stop ruby-prof if running' do
|
175
|
+
expect(RubyProf.running?).to be(false)
|
176
|
+
generator.start!(spec_file)
|
177
|
+
expect(RubyProf.running?).to be(true)
|
178
|
+
generator.teardown!
|
179
|
+
expect(RubyProf.running?).to be(false)
|
180
|
+
end
|
181
|
+
|
182
|
+
it 'should save the table into a file' do
|
183
|
+
expect(generator.table).to be_empty
|
184
|
+
|
185
|
+
generator.start!(spec_file)
|
186
|
+
Sample::Alpha.new.beta_gamma
|
187
|
+
generator.stop!
|
188
|
+
|
189
|
+
expect(generator.table).not_to be_empty
|
190
|
+
expect(table_file.content).to be_empty
|
191
|
+
|
192
|
+
generator.teardown!
|
193
|
+
|
194
|
+
expect(table_file.content).not_to be_empty
|
195
|
+
end
|
196
|
+
|
197
|
+
end
|
198
|
+
|
199
|
+
end
|
200
|
+
|
201
|
+
end
|