autoloaded 2.1.1 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +4 -8
  3. data/.rspec +1 -1
  4. data/.travis.yml +20 -0
  5. data/Gemfile +14 -9
  6. data/Gemfile_ci_mri_19 +7 -0
  7. data/Guardfile +21 -22
  8. data/History.md +35 -10
  9. data/License.md +1 -1
  10. data/README.md +82 -68
  11. data/Rakefile +4 -0
  12. data/autoloaded.gemspec +41 -37
  13. data/bin/console +10 -0
  14. data/bin/setup +8 -0
  15. data/lib/autoloaded/autoloader.rb +24 -6
  16. data/lib/autoloaded/deprecation.rb +0 -2
  17. data/lib/autoloaded/inflection.rb +0 -2
  18. data/lib/autoloaded/load_pathed_directory.rb +2 -4
  19. data/lib/autoloaded/specification.rb +2 -0
  20. data/lib/autoloaded/specifications.rb +3 -3
  21. data/lib/autoloaded/version.rb +1 -1
  22. data/lib/autoloaded/warning.rb +1 -3
  23. data/lib/tasks/lib_each.rake +15 -3
  24. data/lib/tasks/spec.rake +3 -6
  25. metadata +20 -85
  26. data/spec/autoloaded/autoloader_spec.rb +0 -469
  27. data/spec/autoloaded/inflection_spec.rb +0 -30
  28. data/spec/autoloaded/load_pathed_directory_spec.rb +0 -120
  29. data/spec/autoloaded/specification_spec.rb +0 -98
  30. data/spec/autoloaded/specifications_spec.rb +0 -191
  31. data/spec/autoloaded/version_spec.rb +0 -3
  32. data/spec/autoloaded/warning_spec.rb +0 -115
  33. data/spec/autoloaded_macro_sharedspec.rb +0 -24
  34. data/spec/autoloaded_spec.rb +0 -173
  35. data/spec/fixtures/autoloaded_with_conventional_filename/N-est-ed.rb +0 -1
  36. data/spec/fixtures/autoloaded_with_conventional_filename/nest_ed.rb +0 -1
  37. data/spec/fixtures/autoloaded_with_conventional_filename/nested/doubly_nested.rb +0 -9
  38. data/spec/fixtures/autoloaded_with_conventional_filename/nested.rb +0 -16
  39. data/spec/fixtures/autoloaded_with_conventional_filename/old_school_autoload.rb +0 -5
  40. data/spec/fixtures/autoloaded_with_conventional_filename.rb +0 -12
  41. data/spec/fixtures/autoloaded_with_unconventional_filename/N-est-ed.rb +0 -7
  42. data/spec/fixtures/autoloaded_with_unconventional_filename/nest_ed.rb +0 -1
  43. data/spec/fixtures/autoloaded_with_unconventional_filename/old_school_autoload.rb +0 -5
  44. data/spec/fixtures/autoloaded_with_unconventional_filename.rb +0 -12
  45. data/spec/fixtures/filenames/AFilename.rb +0 -0
  46. data/spec/fixtures/filenames/a-file-name.rb +0 -0
  47. data/spec/fixtures/filenames/a-filename.rb +0 -0
  48. data/spec/fixtures/filenames/a_file_name.rb +0 -0
  49. data/spec/fixtures/filenames/a_filename.rb +0 -0
  50. data/spec/fixtures/filenames/afile-name.rb +0 -0
  51. data/spec/fixtures/filenames/afile_name.rb +0 -0
  52. data/spec/fixtures/not_autoloaded/nested.rb +0 -1
  53. data/spec/fixtures/not_autoloaded/old_school_autoload.rb +0 -5
  54. data/spec/fixtures/not_autoloaded.rb +0 -5
  55. data/spec/matchers.rb +0 -85
  56. data/spec/spec_helper.rb +0 -91
  57. data/spec/support/util.rb +0 -42
  58. data/spec/support/without_side_effects.rb +0 -37
@@ -1,469 +0,0 @@
1
- RSpec.describe Autoloaded::Autoloader do
2
- subject(:autoloader) { autoloader_class.new host_binding }
3
-
4
- before :each do
5
- allow(specifications_class).to receive(:new).and_return(specifications)
6
- allow(inflector_class).to receive(:to_constant_name).
7
- and_return(:FromInflection1,
8
- :FromInflection2,
9
- :FromInflection3,
10
- :FromInflection4)
11
- end
12
-
13
- let(:autoloader_class) { described_class }
14
-
15
- let(:host_binding) { self.class.class_eval 'binding', __FILE__, __LINE__ }
16
-
17
- let(:directory_class) { Autoloaded::LoadPathedDirectory }
18
-
19
- let(:specifications) { specifications_class.new }
20
-
21
- let(:specifications_class) { Autoloaded::Specifications }
22
-
23
- let(:specification_class) { Autoloaded::Specification }
24
-
25
- let(:inflector_class) { Autoloaded::Inflection }
26
-
27
- describe '.new' do
28
- describe 'with nil argument' do
29
- specify {
30
- expect { autoloader_class.new nil }.to raise_error(ArgumentError,
31
- "can't be nil")
32
- }
33
- end
34
- end
35
-
36
- describe '#from' do
37
- subject(:from) { autoloader.from }
38
-
39
- describe 'has expected default value' do
40
- specify { is_expected.to eq(__FILE__.gsub(/\.rb$/, '')) }
41
- end
42
-
43
- describe 'rejects relative path argument' do
44
- specify {
45
- expect {
46
- autoloader.from 'a/relative/path'
47
- }.to raise_error(ArgumentError, "can't be relative")
48
- }
49
- end
50
-
51
- describe 'operates as attribute reader and writer' do
52
- specify {
53
- autoloader.from '/an/absolute/path'
54
- is_expected.to eq('/an/absolute/path')
55
- }
56
- end
57
- end
58
-
59
- describe '#except' do
60
- specify("delegates to #{Autoloaded::Specifications.name}#except") {
61
- expect(specifications.except).to be_empty
62
- autoloader.except 'foo'
63
- expect(specifications.except).to contain_exactly(specification_class.new('foo'))
64
- }
65
-
66
- describe 'where #only is specified' do
67
- before :each do
68
- autoloader.only :Foo
69
- end
70
-
71
- specify {
72
- expect { autoloader.except :Bar }.to raise_error(RuntimeError,
73
- "can't specify `except' when `only' is already specified")
74
- }
75
- end
76
- end
77
-
78
- describe '#only' do
79
- specify("delegates to #{Autoloaded::Specifications.name}#only") {
80
- expect(specifications.only).to be_empty
81
- autoloader.only 'foo'
82
- expect(specifications.only).to contain_exactly(specification_class.new('foo'))
83
- }
84
-
85
- describe 'where #except is specified' do
86
- before :each do
87
- autoloader.except :Foo
88
- end
89
-
90
- specify {
91
- expect { autoloader.only :Bar }.to raise_error(RuntimeError,
92
- "can't specify `only' when `except' is already specified")
93
- }
94
- end
95
- end
96
-
97
- describe '#with' do
98
- specify("delegates to #{Autoloaded::Specifications.name}#with") {
99
- expect(specifications.with).to be_empty
100
- autoloader.with 'foo'
101
- expect(specifications.with).to contain_exactly(specification_class.new('foo'))
102
- }
103
- end
104
-
105
- describe '#autoload!' do
106
- before :each do
107
- allow_any_instance_of(directory_class).to receive(:closest_ruby_load_path).
108
- and_return('/foo')
109
- allow(directory_class).to receive(:new).and_return(directory)
110
- allow(directory).to receive(:each_source_filename)
111
- end
112
-
113
- let(:directory) { directory_class.new '/foo' }
114
-
115
- describe 'where #from is' do
116
- describe 'not specified' do
117
- describe "initializes #{Autoloaded::LoadPathedDirectory.name} with computed value" do
118
- specify {
119
- expect(directory_class).to receive(:new).
120
- with(__FILE__.gsub(/\.rb$/, '')).
121
- and_return(directory)
122
- autoloader.autoload!
123
- }
124
- end
125
- end
126
-
127
- describe 'specified' do
128
- before :each do
129
- autoloader.from directory.path
130
- allow(specifications).to receive(:except).
131
- and_return(except_specifications)
132
- allow(specifications).to receive(:only).
133
- and_return(only_specifications)
134
- allow(specifications).to receive(:with).
135
- and_return(with_specifications)
136
- end
137
-
138
- let(:except_specifications) { [] }
139
-
140
- let(:except_specification) { specification_class.new }
141
-
142
- let(:only_specifications) { [] }
143
-
144
- let(:only_specification) { specification_class.new }
145
-
146
- let(:with_specifications) { [] }
147
-
148
- let(:with_specification) { specification_class.new }
149
-
150
- describe 'where no source files are found' do
151
- specify {
152
- expect(Kernel).not_to receive(:eval)
153
- autoloader.autoload!
154
- }
155
-
156
- specify { expect(autoloader.autoload!).to be_empty }
157
- end
158
-
159
- describe 'where a source file is found' do
160
- before :each do
161
- allow(directory).to receive(:each_source_filename).
162
- and_yield('from_each_source_filename')
163
- end
164
-
165
- describe 'and no specifications are provided' do
166
- specify {
167
- expect(Kernel).to receive(:eval).
168
- with('autoload? :FromInflection1',
169
- # host_binding,
170
- # kind_of(String),
171
- # kind_of(Numeric)).
172
- host_binding).
173
- ordered
174
- expect(Kernel).to receive(:eval).
175
- with('constants.include? :FromInflection1',
176
- # host_binding,
177
- # kind_of(String),
178
- # kind_of(Numeric)).
179
- host_binding).
180
- ordered
181
- expect(Kernel).to receive(:eval).
182
- with('autoload :FromInflection1, "from_each_source_filename"',
183
- # host_binding,
184
- # kind_of(String),
185
- # kind_of(Numeric)).
186
- host_binding).
187
- ordered
188
- autoloader.autoload!
189
- }
190
-
191
- specify {
192
- expect(autoloader.autoload!).to eq([[:FromInflection1,
193
- 'from_each_source_filename']])
194
- }
195
- end
196
-
197
- describe "and a `with' specification is provided" do
198
- before :each do
199
- allow(with_specification).to receive(:match).and_return(:FromWith)
200
- end
201
-
202
- let(:with_specifications) { [with_specification] }
203
-
204
- specify {
205
- expect(Kernel).to receive(:eval).
206
- with('autoload? :FromWith',
207
- # host_binding,
208
- # kind_of(String),
209
- # kind_of(Numeric)).
210
- host_binding).
211
- ordered
212
- expect(Kernel).to receive(:eval).
213
- with('constants.include? :FromWith',
214
- # host_binding,
215
- # kind_of(String),
216
- # kind_of(Numeric)).
217
- host_binding).
218
- ordered
219
- expect(Kernel).to receive(:eval).
220
- with('autoload :FromWith, "from_each_source_filename"',
221
- # host_binding,
222
- # kind_of(String),
223
- # kind_of(Numeric))
224
- host_binding).
225
- ordered
226
- autoloader.autoload!
227
- }
228
-
229
- specify {
230
- expect(autoloader.autoload!).to eq([[:FromWith,
231
- 'from_each_source_filename']])
232
- }
233
- end
234
-
235
- describe "and an `only' specification is provided" do
236
- before :each do
237
- allow(only_specification).to receive(:match).and_return(:FromOnly)
238
- end
239
-
240
- let(:only_specifications) { [only_specification] }
241
-
242
- specify {
243
- expect(Kernel).to receive(:eval).
244
- with('autoload? :FromOnly',
245
- # host_binding,
246
- # kind_of(String),
247
- # kind_of(Numeric)).
248
- host_binding).
249
- ordered
250
- expect(Kernel).to receive(:eval).
251
- with('constants.include? :FromOnly',
252
- # host_binding,
253
- # kind_of(String),
254
- # kind_of(Numeric)).
255
- host_binding).
256
- ordered
257
- expect(Kernel).to receive(:eval).
258
- with('autoload :FromOnly, "from_each_source_filename"',
259
- # host_binding,
260
- # kind_of(String),
261
- # kind_of(Numeric)).
262
- host_binding).
263
- ordered
264
- autoloader.autoload!
265
- }
266
-
267
- specify { expect(autoloader.autoload!).to eq([[:FromOnly,
268
- 'from_each_source_filename']]) }
269
- end
270
-
271
- describe "and both `with' and `only' specifications are provided" do
272
- before :each do
273
- allow(with_specification).to receive(:match).and_return(:FromWith)
274
- allow(only_specification).to receive(:match).and_return(:FromOnly)
275
- end
276
-
277
- let(:with_specifications) { [with_specification] }
278
-
279
- let(:only_specifications) { [only_specification] }
280
-
281
- specify {
282
- expect(Kernel).to receive(:eval).
283
- with('autoload? :FromWith',
284
- # host_binding,
285
- # kind_of(String),
286
- # kind_of(Numeric)).
287
- host_binding).
288
- ordered
289
- expect(Kernel).to receive(:eval).
290
- with('constants.include? :FromWith',
291
- # host_binding,
292
- # kind_of(String),
293
- # kind_of(Numeric)).
294
- host_binding).
295
- ordered
296
- expect(Kernel).to receive(:eval).
297
- with('autoload :FromWith, "from_each_source_filename"',
298
- # host_binding,
299
- # kind_of(String),
300
- # kind_of(Numeric)).
301
- host_binding).
302
- ordered
303
- autoloader.autoload!
304
- }
305
-
306
- specify { expect(autoloader.autoload!).to eq([[:FromWith,
307
- 'from_each_source_filename']]) }
308
- end
309
- end
310
-
311
- describe 'where multiple source files are found' do
312
- before :each do
313
- allow(directory).to receive(:each_source_filename).
314
- and_yield('from_each_source_filename1').
315
- and_yield('from_each_source_filename2').
316
- and_yield('from_each_source_filename3')
317
- end
318
-
319
- describe 'and no specifications are provided' do
320
- specify {
321
- expect(Kernel).to receive(:eval).
322
- with('autoload? :FromInflection1',
323
- # host_binding,
324
- # kind_of(String),
325
- # kind_of(Numeric)).
326
- host_binding).
327
- ordered
328
- expect(Kernel).to receive(:eval).
329
- with('constants.include? :FromInflection1',
330
- # host_binding,
331
- # kind_of(String),
332
- # kind_of(Numeric)).
333
- host_binding).
334
- ordered
335
- expect(Kernel).to receive(:eval).
336
- with('autoload :FromInflection1, "from_each_source_filename1"',
337
- # host_binding,
338
- # kind_of(String),
339
- # kind_of(Numeric)).
340
- host_binding).
341
- ordered
342
- expect(Kernel).to receive(:eval).
343
- with('autoload? :FromInflection2',
344
- # host_binding,
345
- # kind_of(String),
346
- # kind_of(Numeric)).
347
- host_binding).
348
- ordered
349
- expect(Kernel).to receive(:eval).
350
- with('constants.include? :FromInflection2',
351
- # host_binding,
352
- # kind_of(String),
353
- # kind_of(Numeric)).
354
- host_binding).
355
- ordered
356
- expect(Kernel).to receive(:eval).
357
- with('autoload :FromInflection2, "from_each_source_filename2"',
358
- # host_binding,
359
- # kind_of(String),
360
- # kind_of(Numeric)).
361
- host_binding).
362
- ordered
363
- expect(Kernel).to receive(:eval).
364
- with('autoload? :FromInflection3',
365
- # host_binding,
366
- # kind_of(String),
367
- # kind_of(Numeric)).
368
- host_binding).
369
- ordered
370
- expect(Kernel).to receive(:eval).
371
- with('constants.include? :FromInflection3',
372
- # host_binding,
373
- # kind_of(String),
374
- # kind_of(Numeric)).
375
- host_binding).
376
- ordered
377
- expect(Kernel).to receive(:eval).
378
- with('autoload :FromInflection3, "from_each_source_filename3"',
379
- # host_binding,
380
- # kind_of(String),
381
- # kind_of(Numeric)).
382
- host_binding).
383
- ordered
384
- autoloader.autoload!
385
- }
386
-
387
- specify {
388
- expect(autoloader.autoload!).to eq([[:FromInflection1,
389
- 'from_each_source_filename1'],
390
- [:FromInflection2,
391
- 'from_each_source_filename2'],
392
- [:FromInflection3,
393
- 'from_each_source_filename3']])
394
- }
395
- end
396
-
397
- describe "and a matching `except' specification is provided" do
398
- before :each do
399
- allow(except_specification).to receive(:match).
400
- with('from_each_source_filename1').
401
- and_return(nil)
402
- allow(except_specification).to receive(:match).
403
- with('from_each_source_filename2').
404
- and_return(:FromExcept)
405
- allow(except_specification).to receive(:match).
406
- with('from_each_source_filename3').
407
- and_return(nil)
408
- end
409
-
410
- let(:except_specifications) { [except_specification] }
411
-
412
- specify {
413
- expect(Kernel).to receive(:eval).
414
- with('autoload? :FromInflection1',
415
- # host_binding,
416
- # kind_of(String),
417
- # kind_of(Numeric)).
418
- host_binding).
419
- ordered
420
- expect(Kernel).to receive(:eval).
421
- with('constants.include? :FromInflection1',
422
- # host_binding,
423
- # kind_of(String),
424
- # kind_of(Numeric)).
425
- host_binding).
426
- ordered
427
- expect(Kernel).to receive(:eval).
428
- with('autoload :FromInflection1, "from_each_source_filename1"',
429
- # host_binding,
430
- # kind_of(String),
431
- # kind_of(Numeric)).
432
- host_binding).
433
- ordered
434
- expect(Kernel).to receive(:eval).
435
- with('autoload? :FromInflection2',
436
- # host_binding,
437
- # kind_of(String),
438
- # kind_of(Numeric)).
439
- host_binding).
440
- ordered
441
- expect(Kernel).to receive(:eval).
442
- with('constants.include? :FromInflection2',
443
- # host_binding,
444
- # kind_of(String),
445
- # kind_of(Numeric)).
446
- host_binding).
447
- ordered
448
- expect(Kernel).to receive(:eval).
449
- with('autoload :FromInflection2, "from_each_source_filename3"',
450
- # host_binding,
451
- # kind_of(String),
452
- # kind_of(Numeric)).
453
- host_binding).
454
- ordered
455
- autoloader.autoload!
456
- }
457
-
458
- specify {
459
- expect(autoloader.autoload!).to eq([[:FromInflection1,
460
- 'from_each_source_filename1'],
461
- [:FromInflection2,
462
- 'from_each_source_filename3']])
463
- }
464
- end
465
- end
466
- end
467
- end
468
- end
469
- end
@@ -1,30 +0,0 @@
1
- RSpec.describe Autoloaded::Inflection do
2
- subject(:inflection_module) { described_class }
3
-
4
- def self.make_source_filename(source_basename)
5
- "path/to/#{source_basename}.rb"
6
- end
7
-
8
- {'x' => :X,
9
- 'foo_bar' => :FooBar,
10
- 'foo__bar' => :FooBar,
11
- '__foo_bar' => :FooBar,
12
- 'foo-bar' => :FooBar,
13
- 'foo--bar' => :FooBar,
14
- '--foo-bar' => :FooBar,
15
- 'FooBar' => :FooBar,
16
- 'FOO_BAR' => :FOO_BAR,
17
- 'FOO-BAR' => :FOO_BAR,
18
- 'FOO--BAR' => :FOO_BAR,
19
- 'foo7bar' => :Foo7bar}.each do |source_basename, expected_constant_name|
20
- describe %Q{for #{make_source_filename(source_basename).inspect}"} do
21
- describe '#to_constant_name' do
22
- specify {
23
- source_filename = self.class.make_source_filename(source_basename)
24
- constant_name = inflection_module.to_constant_name(source_filename)
25
- expect(constant_name).to eq(expected_constant_name)
26
- }
27
- end
28
- end
29
- end
30
- end
@@ -1,120 +0,0 @@
1
- RSpec.describe Autoloaded::LoadPathedDirectory do
2
- before :each do
3
- allow(directory_class).to receive(:ruby_load_paths).
4
- and_return(ruby_load_paths)
5
- end
6
-
7
- subject(:directory) { directory_class.new path }
8
-
9
- let(:directory_class) { described_class }
10
-
11
- let(:ruby_load_paths) { [Dir.pwd] }
12
-
13
- describe '.new' do
14
- describe 'with a nil argument' do
15
- specify {
16
- expect { directory_class.new nil }.to raise_error(ArgumentError,
17
- "can't be nil")
18
- }
19
- end
20
-
21
- describe 'with a relative-path argument' do
22
- specify {
23
- expect { directory_class.new 'foo' }.to raise_error(ArgumentError,
24
- "can't be relative")
25
- }
26
- end
27
- end
28
-
29
- describe 'with an absolute #path' do
30
- let(:path) { File.expand_path 'spec/fixtures/filenames' }
31
-
32
- let(:expected_relative_source_filenames) {
33
- %w(a-file-name
34
- a-filename
35
- a_file_name
36
- a_filename
37
- afile-name
38
- afile_name
39
- AFilename)
40
- }
41
-
42
- describe '#path' do
43
- subject { directory.path }
44
-
45
- specify { is_expected.to eq(path) }
46
- end
47
-
48
- describe '#each_source_filename' do
49
- subject(:yielded_arguments) {
50
- result = []
51
- directory.each_source_filename do |source_filename|
52
- result << source_filename
53
- end
54
- result
55
- }
56
-
57
- describe 'where #path does not match a Ruby load path' do
58
- let(:ruby_load_paths) { [] }
59
-
60
- let(:expected_source_filenames) {
61
- expected_relative_source_filenames.collect do |f|
62
- File.expand_path f, 'spec/fixtures/filenames'
63
- end
64
- }
65
-
66
- describe 'yielded arguments' do
67
- specify('should be absolute paths to the expected source filenames') {
68
- is_expected.to match_array(expected_source_filenames)
69
- }
70
- end
71
- end
72
-
73
- describe 'where #path partially matches one Ruby load path' do
74
- let(:expected_source_filenames) {
75
- expected_relative_source_filenames.collect do |f|
76
- File.join 'spec/fixtures/filenames', f
77
- end
78
- }
79
-
80
- describe 'yielded arguments' do
81
- specify('should be partial paths to the expected source filenames') {
82
- is_expected.to match_array(expected_source_filenames)
83
- }
84
- end
85
- end
86
-
87
- describe 'where #path partially matches multiple Ruby load paths' do
88
- let(:ruby_load_paths) {
89
- [Dir.pwd,
90
- File.join(Dir.pwd, 'spec/fixtures'),
91
- File.join(Dir.pwd, 'spec')]
92
- }
93
-
94
- let(:expected_source_filenames) {
95
- expected_relative_source_filenames.collect do |f|
96
- File.join 'filenames', f
97
- end
98
- }
99
-
100
- describe 'yielded arguments' do
101
- specify('should be partial paths to the expected source filenames') {
102
- is_expected.to match_array(expected_source_filenames)
103
- }
104
- end
105
- end
106
-
107
- describe 'where #path exactly matches a Ruby load path' do
108
- let(:ruby_load_paths) { [File.join(Dir.pwd, 'spec/fixtures/filenames')] }
109
-
110
- let(:expected_source_filenames) { expected_relative_source_filenames }
111
-
112
- describe 'yielded arguments' do
113
- specify('should be the expected source filenames') {
114
- is_expected.to match_array(expected_source_filenames)
115
- }
116
- end
117
- end
118
- end
119
- end
120
- end