autoloaded 1.4.1 → 1.7.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 +5 -5
- data/.gitignore +4 -8
- data/.rspec +1 -1
- data/.travis.yml +15 -0
- data/Gemfile +11 -10
- data/Guardfile +21 -22
- data/History.md +35 -10
- data/License.md +1 -1
- data/README.md +78 -68
- data/Rakefile +4 -0
- data/autoloaded.gemspec +41 -37
- data/bin/console +10 -0
- data/bin/setup +8 -0
- data/lib/autoloaded/autoloader.rb +24 -6
- data/lib/autoloaded/constant.rb +1 -0
- data/lib/autoloaded/deprecation.rb +0 -2
- data/lib/autoloaded/inflection.rb +0 -2
- data/lib/autoloaded/load_pathed_directory.rb +2 -4
- data/lib/autoloaded/specification.rb +2 -0
- data/lib/autoloaded/specifications.rb +3 -3
- data/lib/autoloaded/version.rb +1 -1
- data/lib/autoloaded/warning.rb +1 -3
- data/lib/tasks/lib_each.rake +15 -3
- data/lib/tasks/spec.rake +3 -6
- metadata +22 -121
- data/spec/autoloaded/autoloader_spec.rb +0 -469
- data/spec/autoloaded/constant_spec.rb +0 -53
- data/spec/autoloaded/deprecation_spec.rb +0 -23
- data/spec/autoloaded/inflection_spec.rb +0 -30
- data/spec/autoloaded/load_pathed_directory_spec.rb +0 -120
- data/spec/autoloaded/refine/string/to_source_filename_spec.rb +0 -19
- data/spec/autoloaded/specification_spec.rb +0 -98
- data/spec/autoloaded/specifications_spec.rb +0 -191
- data/spec/autoloaded/version_spec.rb +0 -3
- data/spec/autoloaded/warning_spec.rb +0 -115
- data/spec/autoloaded_macro_sharedspec.rb +0 -24
- data/spec/autoloaded_spec.rb +0 -321
- data/spec/fixtures/autoloaded_with_conventional_filename/N-est-ed.rb +0 -1
- data/spec/fixtures/autoloaded_with_conventional_filename/nest_ed.rb +0 -1
- data/spec/fixtures/autoloaded_with_conventional_filename/nested/doubly_nested.rb +0 -9
- data/spec/fixtures/autoloaded_with_conventional_filename/nested.rb +0 -16
- data/spec/fixtures/autoloaded_with_conventional_filename/old_school_autoload.rb +0 -5
- data/spec/fixtures/autoloaded_with_conventional_filename.rb +0 -12
- data/spec/fixtures/autoloaded_with_unconventional_filename/N-est-ed.rb +0 -7
- data/spec/fixtures/autoloaded_with_unconventional_filename/nest_ed.rb +0 -1
- data/spec/fixtures/autoloaded_with_unconventional_filename/old_school_autoload.rb +0 -5
- data/spec/fixtures/autoloaded_with_unconventional_filename.rb +0 -12
- data/spec/fixtures/filenames/AFilename.rb +0 -0
- data/spec/fixtures/filenames/a-file-name.rb +0 -0
- data/spec/fixtures/filenames/a-filename.rb +0 -0
- data/spec/fixtures/filenames/a_file_name.rb +0 -0
- data/spec/fixtures/filenames/a_filename.rb +0 -0
- data/spec/fixtures/filenames/afile-name.rb +0 -0
- data/spec/fixtures/filenames/afile_name.rb +0 -0
- data/spec/fixtures/not_autoloaded/nested.rb +0 -1
- data/spec/fixtures/not_autoloaded/old_school_autoload.rb +0 -5
- data/spec/fixtures/not_autoloaded.rb +0 -5
- data/spec/fixtures/old_api/autoloaded_with_conventional_filename/N-est-ed.rb +0 -1
- data/spec/fixtures/old_api/autoloaded_with_conventional_filename/nest_ed.rb +0 -1
- data/spec/fixtures/old_api/autoloaded_with_conventional_filename/nested.rb +0 -5
- data/spec/fixtures/old_api/autoloaded_with_conventional_filename/old_school_autoload.rb +0 -5
- data/spec/fixtures/old_api/autoloaded_with_conventional_filename.rb +0 -10
- data/spec/fixtures/old_api/autoloaded_with_conventional_filename_only/nested.rb +0 -5
- data/spec/fixtures/old_api/autoloaded_with_conventional_filename_only/old_school_autoload.rb +0 -5
- data/spec/fixtures/old_api/autoloaded_with_conventional_filename_only.rb +0 -10
- data/spec/fixtures/old_api/autoloaded_with_unconventional_filenames/N-est-ed.rb +0 -5
- data/spec/fixtures/old_api/autoloaded_with_unconventional_filenames/nest_ed.rb +0 -0
- data/spec/fixtures/old_api/autoloaded_with_unconventional_filenames/old_school_autoload.rb +0 -5
- data/spec/fixtures/old_api/autoloaded_with_unconventional_filenames.rb +0 -10
- data/spec/fixtures/old_api/not_autoloaded/nested.rb +0 -1
- data/spec/fixtures/old_api/not_autoloaded/old_school_autoload.rb +0 -5
- data/spec/fixtures/old_api/not_autoloaded.rb +0 -6
- data/spec/matchers.rb +0 -85
- data/spec/spec_helper.rb +0 -91
- data/spec/support/util.rb +0 -43
- data/spec/support/without_side_effects.rb +0 -37
data/spec/autoloaded_spec.rb
DELETED
@@ -1,321 +0,0 @@
|
|
1
|
-
require 'autoloaded_macro_sharedspec'
|
2
|
-
require 'matchers'
|
3
|
-
require 'stringio'
|
4
|
-
|
5
|
-
RSpec.describe Autoloaded do
|
6
|
-
let(:autoloaded_module) { described_class }
|
7
|
-
|
8
|
-
let(:warning_module) { autoloaded_module::Warning }
|
9
|
-
|
10
|
-
describe '.class' do
|
11
|
-
it_behaves_like "an #{Autoloaded.name} macro", :class
|
12
|
-
end
|
13
|
-
|
14
|
-
describe '.module' do
|
15
|
-
it_behaves_like "an #{Autoloaded.name} macro", :module
|
16
|
-
end
|
17
|
-
|
18
|
-
describe '.warn' do
|
19
|
-
describe 'simple form' do
|
20
|
-
before :each do
|
21
|
-
allow(warning_module).to receive(:enable).
|
22
|
-
and_return(:warning_enable_result)
|
23
|
-
end
|
24
|
-
|
25
|
-
specify("delegates to #{Autoloaded::Warning.name}.enable") {
|
26
|
-
expect(warning_module).to receive(:enable).
|
27
|
-
with('foo').
|
28
|
-
and_return(:warning_enable_result)
|
29
|
-
autoloaded_module.warn 'foo'
|
30
|
-
}
|
31
|
-
|
32
|
-
specify("returns #{Autoloaded.name}") {
|
33
|
-
expect(autoloaded_module.warn('foo')).to eq(autoloaded_module)
|
34
|
-
}
|
35
|
-
end
|
36
|
-
|
37
|
-
describe 'block form' do
|
38
|
-
specify("delegates to #{Autoloaded::Warning.name}.enable") {
|
39
|
-
expect(warning_module).to receive(:enable).
|
40
|
-
with('foo').
|
41
|
-
and_yield.
|
42
|
-
and_return(:warning_enable_result)
|
43
|
-
result = autoloaded_module.warn('foo') do
|
44
|
-
:block_result
|
45
|
-
end
|
46
|
-
expect(result).to eq(:warning_enable_result)
|
47
|
-
}
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe '.warn?' do
|
52
|
-
specify("delegates to #{Autoloaded::Warning.name}.enabled?") {
|
53
|
-
expect(warning_module).to receive(:enabled?).
|
54
|
-
and_return(:warning_enabled_result)
|
55
|
-
expect(autoloaded_module.warn?).to eq(:warning_enabled_result)
|
56
|
-
}
|
57
|
-
end
|
58
|
-
|
59
|
-
describe 'integration' do
|
60
|
-
before :each do
|
61
|
-
class << self
|
62
|
-
alias_method :define_constant, :define_constants
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
begin
|
67
|
-
fork do
|
68
|
-
# The codeclimate-test-reporter RubyGem uses Kernel#at_exit to hook the
|
69
|
-
# end of test/spec runs for sending coverage statistics to their web
|
70
|
-
# service. We need to skip that hook in this process fork because this is
|
71
|
-
# not the end of a test/spec run, only of a process fork.
|
72
|
-
exit!(true) if ENV['CODECLIMATE_REPO_TOKEN']
|
73
|
-
end
|
74
|
-
rescue NotImplementedError => e
|
75
|
-
pending "[pending because #{e.message}]"
|
76
|
-
else
|
77
|
-
describe 'not extending a namespace' do
|
78
|
-
subject(:source_file) { 'spec/fixtures/not_autoloaded.rb' }
|
79
|
-
|
80
|
-
it { is_expected.to define_constant(:NotAutoloaded) }
|
81
|
-
|
82
|
-
it { is_expected.to define_constant('NotAutoloaded::OldSchoolAutoload') }
|
83
|
-
|
84
|
-
it { is_expected.not_to define_constant('NotAutoloaded::Nested') }
|
85
|
-
|
86
|
-
it {
|
87
|
-
is_expected.to set_up_autoload_for_constant('NotAutoloaded::OldSchoolAutoload').
|
88
|
-
from_file('fixtures/not_autoloaded/old_school_autoload')
|
89
|
-
}
|
90
|
-
|
91
|
-
it {
|
92
|
-
is_expected.not_to set_up_autoload_for_constant('NotAutoloaded::Nested')
|
93
|
-
}
|
94
|
-
end
|
95
|
-
|
96
|
-
describe 'extending a namespace whose constituent source files include' do
|
97
|
-
describe 'a conventional source filename used for autoloading' do
|
98
|
-
subject(:source_file) {
|
99
|
-
'spec/fixtures/autoloaded_with_conventional_filename.rb'
|
100
|
-
}
|
101
|
-
|
102
|
-
it {
|
103
|
-
is_expected.to define_constant(:AutoloadedWithConventionalFilename)
|
104
|
-
}
|
105
|
-
|
106
|
-
it {
|
107
|
-
is_expected.to define_constant('AutoloadedWithConventionalFilename::OldSchoolAutoload')
|
108
|
-
}
|
109
|
-
|
110
|
-
it {
|
111
|
-
is_expected.to define_constant('AutoloadedWithConventionalFilename::Nested')
|
112
|
-
}
|
113
|
-
|
114
|
-
it {
|
115
|
-
is_expected.not_to define_constant('AutoloadedWithConventionalFilename::NONEXISTENT')
|
116
|
-
}
|
117
|
-
|
118
|
-
it {
|
119
|
-
is_expected.to set_up_autoload_for_constant('AutoloadedWithConventionalFilename::OldSchoolAutoload').
|
120
|
-
from_file('fixtures/autoloaded_with_conventional_filename/old_school_autoload')
|
121
|
-
}
|
122
|
-
|
123
|
-
it {
|
124
|
-
is_expected.to set_up_autoload_for_constant('AutoloadedWithConventionalFilename::Nested').
|
125
|
-
from_file('fixtures/autoloaded_with_conventional_filename/nested')
|
126
|
-
}
|
127
|
-
|
128
|
-
it {
|
129
|
-
is_expected.not_to set_up_autoload_for_constant('AutoloadedWithConventionalFilename::NONEXISTENT')
|
130
|
-
}
|
131
|
-
end
|
132
|
-
|
133
|
-
describe 'unconventional source filenames' do
|
134
|
-
subject(:source_file) {
|
135
|
-
'spec/fixtures/autoloaded_with_unconventional_filename.rb'
|
136
|
-
}
|
137
|
-
|
138
|
-
it {
|
139
|
-
is_expected.to define_constant(:AutoloadedWithUnconventionalFilename)
|
140
|
-
}
|
141
|
-
|
142
|
-
it {
|
143
|
-
is_expected.to define_constant('AutoloadedWithUnconventionalFilename::OldSchoolAutoload')
|
144
|
-
}
|
145
|
-
|
146
|
-
it {
|
147
|
-
is_expected.to define_constants('AutoloadedWithUnconventionalFilename::Nested1',
|
148
|
-
'AutoloadedWithUnconventionalFilename::Nested2')
|
149
|
-
}
|
150
|
-
|
151
|
-
it {
|
152
|
-
is_expected.to set_up_autoload_for_constant('AutoloadedWithUnconventionalFilename::OldSchoolAutoload').
|
153
|
-
from_file('fixtures/autoloaded_with_unconventional_filename/old_school_autoload')
|
154
|
-
}
|
155
|
-
|
156
|
-
it {
|
157
|
-
is_expected.to set_up_autoload_for_constant('AutoloadedWithUnconventionalFilename::Nested1').
|
158
|
-
from_file('fixtures/autoloaded_with_unconventional_filename/N-est-ed')
|
159
|
-
}
|
160
|
-
|
161
|
-
it {
|
162
|
-
is_expected.to set_up_autoload_for_constant('AutoloadedWithUnconventionalFilename::Nested2').
|
163
|
-
from_file('fixtures/autoloaded_with_unconventional_filename/N-est-ed')
|
164
|
-
}
|
165
|
-
|
166
|
-
it {
|
167
|
-
is_expected.not_to set_up_autoload_for_constant('AutoloadedWithUnconventionalFilename::NONEXISTENT')
|
168
|
-
}
|
169
|
-
end
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
describe 'old API' do
|
174
|
-
before :each do
|
175
|
-
autoloaded_module::Deprecation.io = StringIO.new
|
176
|
-
end
|
177
|
-
|
178
|
-
after :each do
|
179
|
-
autoloaded_module::Deprecation.io = nil
|
180
|
-
end
|
181
|
-
|
182
|
-
begin
|
183
|
-
fork do
|
184
|
-
# The codeclimate-test-reporter RubyGem uses Kernel#at_exit to hook the
|
185
|
-
# end of test/spec runs for sending coverage statistics to their web
|
186
|
-
# service. We need to skip that hook in this process fork because this is
|
187
|
-
# not the end of a test/spec run, only of a process fork.
|
188
|
-
exit!(true) if ENV['CODECLIMATE_REPO_TOKEN']
|
189
|
-
end
|
190
|
-
rescue NotImplementedError => e
|
191
|
-
pending "[pending because #{e.message}]"
|
192
|
-
else
|
193
|
-
describe 'not extending a namespace' do
|
194
|
-
subject(:source_file) { 'spec/fixtures/old_api/not_autoloaded.rb' }
|
195
|
-
|
196
|
-
it { is_expected.to define_constant(:NotAutoloaded) }
|
197
|
-
|
198
|
-
it {
|
199
|
-
is_expected.to define_constant('NotAutoloaded::OldSchoolAutoload')
|
200
|
-
}
|
201
|
-
|
202
|
-
it { is_expected.not_to define_constant('NotAutoloaded::Nested') }
|
203
|
-
|
204
|
-
it {
|
205
|
-
is_expected.to set_up_autoload_for_constant('NotAutoloaded::OldSchoolAutoload').
|
206
|
-
from_file('fixtures/old_api/not_autoloaded/old_school_autoload')
|
207
|
-
}
|
208
|
-
|
209
|
-
it {
|
210
|
-
is_expected.not_to set_up_autoload_for_constant('NotAutoloaded::Nested')
|
211
|
-
}
|
212
|
-
end
|
213
|
-
|
214
|
-
describe 'extending a namespace whose constituent source files include' do
|
215
|
-
describe 'a conventional source filename used for autoloading' do
|
216
|
-
subject(:source_file) {
|
217
|
-
'spec/fixtures/old_api/autoloaded_with_conventional_filename.rb'
|
218
|
-
}
|
219
|
-
|
220
|
-
it {
|
221
|
-
is_expected.to define_constant(:AutoloadedWithConventionalFilename)
|
222
|
-
}
|
223
|
-
|
224
|
-
it {
|
225
|
-
is_expected.to define_constant('AutoloadedWithConventionalFilename::OldSchoolAutoload')
|
226
|
-
}
|
227
|
-
|
228
|
-
it {
|
229
|
-
is_expected.to define_constant('AutoloadedWithConventionalFilename::Nested')
|
230
|
-
}
|
231
|
-
|
232
|
-
it {
|
233
|
-
is_expected.not_to define_constant('AutoloadedWithConventionalFilename::NONEXISTENT')
|
234
|
-
}
|
235
|
-
|
236
|
-
it {
|
237
|
-
is_expected.to set_up_autoload_for_constant('AutoloadedWithConventionalFilename::OldSchoolAutoload').
|
238
|
-
from_file('fixtures/old_api/autoloaded_with_conventional_filename/old_school_autoload')
|
239
|
-
}
|
240
|
-
|
241
|
-
it {
|
242
|
-
is_expected.to set_up_autoload_for_constant('AutoloadedWithConventionalFilename::Nested').
|
243
|
-
from_files('fixtures/old_api/autoloaded_with_conventional_filename/nested',
|
244
|
-
'fixtures/old_api/autoloaded_with_conventional_filename/N-est-ed',
|
245
|
-
'fixtures/old_api/autoloaded_with_conventional_filename/nest_ed')
|
246
|
-
}
|
247
|
-
|
248
|
-
it {
|
249
|
-
is_expected.not_to set_up_autoload_for_constant('AutoloadedWithConventionalFilename::NONEXISTENT')
|
250
|
-
}
|
251
|
-
end
|
252
|
-
|
253
|
-
describe 'a conventional source filename only' do
|
254
|
-
subject(:source_file) {
|
255
|
-
'spec/fixtures/old_api/autoloaded_with_conventional_filename_only.rb'
|
256
|
-
}
|
257
|
-
|
258
|
-
it {
|
259
|
-
is_expected.to define_constant(:AutoloadedWithConventionalFilenameOnly)
|
260
|
-
}
|
261
|
-
|
262
|
-
it {
|
263
|
-
is_expected.to define_constant('AutoloadedWithConventionalFilenameOnly::OldSchoolAutoload')
|
264
|
-
}
|
265
|
-
|
266
|
-
it {
|
267
|
-
is_expected.to define_constant('AutoloadedWithConventionalFilenameOnly::Nested')
|
268
|
-
}
|
269
|
-
|
270
|
-
it {
|
271
|
-
is_expected.to set_up_autoload_for_constant('AutoloadedWithConventionalFilenameOnly::OldSchoolAutoload').
|
272
|
-
from_file('fixtures/old_api/autoloaded_with_conventional_filename_only/old_school_autoload')
|
273
|
-
}
|
274
|
-
|
275
|
-
it {
|
276
|
-
is_expected.to set_up_autoload_for_constant('AutoloadedWithConventionalFilenameOnly::Nested').
|
277
|
-
from_file('fixtures/old_api/autoloaded_with_conventional_filename_only/nested')
|
278
|
-
}
|
279
|
-
|
280
|
-
it {
|
281
|
-
is_expected.not_to set_up_autoload_for_constant('AutoloadedWithConventionalFilenameOnly::NONEXISTENT')
|
282
|
-
}
|
283
|
-
end
|
284
|
-
|
285
|
-
describe 'unconventional source filenames' do
|
286
|
-
subject(:source_file) {
|
287
|
-
'spec/fixtures/old_api/autoloaded_with_unconventional_filenames.rb'
|
288
|
-
}
|
289
|
-
|
290
|
-
it {
|
291
|
-
is_expected.to define_constant(:AutoloadedWithUnconventionalFilenames)
|
292
|
-
}
|
293
|
-
|
294
|
-
it {
|
295
|
-
is_expected.to define_constant('AutoloadedWithUnconventionalFilenames::OldSchoolAutoload')
|
296
|
-
}
|
297
|
-
|
298
|
-
it {
|
299
|
-
is_expected.to define_constants('AutoloadedWithUnconventionalFilenames::Nested')
|
300
|
-
}
|
301
|
-
|
302
|
-
it {
|
303
|
-
is_expected.to set_up_autoload_for_constant('AutoloadedWithUnconventionalFilenames::OldSchoolAutoload').
|
304
|
-
from_file('fixtures/old_api/autoloaded_with_unconventional_filenames/old_school_autoload')
|
305
|
-
}
|
306
|
-
|
307
|
-
it {
|
308
|
-
is_expected.to set_up_autoload_for_constant('AutoloadedWithUnconventionalFilenames::Nested').
|
309
|
-
from_files('fixtures/old_api/autoloaded_with_unconventional_filenames/N-est-ed',
|
310
|
-
'fixtures/old_api/autoloaded_with_unconventional_filenames/nest_ed')
|
311
|
-
}
|
312
|
-
|
313
|
-
it {
|
314
|
-
is_expected.not_to set_up_autoload_for_constant('AutoloadedWithUnconventionalFilenames::NONEXISTENT')
|
315
|
-
}
|
316
|
-
end
|
317
|
-
end
|
318
|
-
end
|
319
|
-
end
|
320
|
-
end
|
321
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
raise "The file #{__FILE__} should not have been loaded"
|
@@ -1 +0,0 @@
|
|
1
|
-
raise "The file #{__FILE__} should not have been loaded"
|
@@ -1,12 +0,0 @@
|
|
1
|
-
require 'autoloaded'
|
2
|
-
|
3
|
-
module AutoloadedWithConventionalFilename
|
4
|
-
|
5
|
-
autoload :OldSchoolAutoload,
|
6
|
-
'fixtures/autoloaded_with_conventional_filename/old_school_autoload'
|
7
|
-
|
8
|
-
::Autoloaded.module do |autoloaded|
|
9
|
-
autoloaded.except 'N-est-ed', 'nest_ed'
|
10
|
-
end
|
11
|
-
|
12
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
raise "The file #{__FILE__} should not have been loaded"
|
@@ -1,12 +0,0 @@
|
|
1
|
-
require 'autoloaded'
|
2
|
-
|
3
|
-
module AutoloadedWithUnconventionalFilename
|
4
|
-
|
5
|
-
autoload :OldSchoolAutoload,
|
6
|
-
'fixtures/autoloaded_with_unconventional_filename/old_school_autoload'
|
7
|
-
|
8
|
-
::Autoloaded.module do |autoloaded|
|
9
|
-
autoloaded.only 'N-est-ed' => [:Nested1, :Nested2]
|
10
|
-
end
|
11
|
-
|
12
|
-
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -1 +0,0 @@
|
|
1
|
-
raise "The file #{__FILE__} should not have been loaded"
|
@@ -1 +0,0 @@
|
|
1
|
-
raise "The file #{__FILE__} should not have been loaded"
|
@@ -1 +0,0 @@
|
|
1
|
-
raise "The file #{__FILE__} should not have been loaded"
|
File without changes
|
@@ -1 +0,0 @@
|
|
1
|
-
raise "The file #{__FILE__} should not have been loaded"
|
data/spec/matchers.rb
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
require 'support/util'
|
2
|
-
require 'support/without_side_effects'
|
3
|
-
|
4
|
-
RSpec::Matchers.define :define_constants do |*constant_names|
|
5
|
-
match do |source_file|
|
6
|
-
# Ensure the file exists.
|
7
|
-
File.open source_file, 'r' do
|
8
|
-
end
|
9
|
-
|
10
|
-
without_side_effects do
|
11
|
-
constant_names.each do |constant_name|
|
12
|
-
if Util.constantize(constant_name)
|
13
|
-
fail "constant #{constant_name} is already defined outside #{source_file}"
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
load source_file
|
18
|
-
|
19
|
-
constant_names.all? do |constant_name|
|
20
|
-
Util.namespace_and_unqualified_constant_name constant_name,
|
21
|
-
raise_if_namespace_invalid: true
|
22
|
-
Util.constantize constant_name
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
description do
|
28
|
-
fragments = []
|
29
|
-
fragments << case constant_names.length
|
30
|
-
when 0
|
31
|
-
'no constants'
|
32
|
-
when 1
|
33
|
-
"constant #{constant_names.first}"
|
34
|
-
else
|
35
|
-
"constants #{constant_names.join ' and '}"
|
36
|
-
end
|
37
|
-
"define #{fragments.join ' '}"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
RSpec::Matchers.define :set_up_autoload_for_constant do |constant_name|
|
42
|
-
match do |source_file|
|
43
|
-
# Ensure the file exists.
|
44
|
-
File.open source_file, 'r' do
|
45
|
-
end
|
46
|
-
|
47
|
-
without_side_effects do
|
48
|
-
namespace, unqualified_constant_name = Util.namespace_and_unqualified_constant_name(constant_name)
|
49
|
-
if namespace && namespace.autoload?(unqualified_constant_name)
|
50
|
-
fail "#{namespace.name}::#{unqualified_constant_name} is already set up for autoload outside #{source_file}"
|
51
|
-
end
|
52
|
-
|
53
|
-
load source_file
|
54
|
-
|
55
|
-
namespace, unqualified_constant_name = Util.namespace_and_unqualified_constant_name(constant_name,
|
56
|
-
raise_if_namespace_invalid: true)
|
57
|
-
if filename_or_filenames
|
58
|
-
Array(filename_or_filenames).sort == Array(namespace.autoload?(unqualified_constant_name)).sort
|
59
|
-
else
|
60
|
-
namespace.autoload? unqualified_constant_name
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
chain :from_file do |filename|
|
66
|
-
@filename_or_filenames = filename
|
67
|
-
end
|
68
|
-
|
69
|
-
chain :from_files do |*filenames|
|
70
|
-
@filename_or_filenames = filenames
|
71
|
-
end
|
72
|
-
|
73
|
-
description do
|
74
|
-
fragments = []
|
75
|
-
fragments << "constant #{constant_name}"
|
76
|
-
if filename_or_filenames
|
77
|
-
unless (filenames = Array(filename_or_filenames)).empty?
|
78
|
-
fragments << "from file#{(filenames.length == 1) ? nil : 's'} #{filenames.join ' and '}"
|
79
|
-
end
|
80
|
-
end
|
81
|
-
"set up #{Module.name}#autoload? for #{fragments.join ' '}"
|
82
|
-
end
|
83
|
-
|
84
|
-
attr_reader :filename_or_filenames
|
85
|
-
end
|