1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
|
require "spec_helper"
describe Bundler::SourceList do
before do
allow(Bundler).to receive(:root) { Pathname.new "/" }
end
subject(:source_list) { Bundler::SourceList.new }
let(:rubygems_aggregate) { Bundler::Source::Rubygems.new }
describe "adding sources" do
before do
source_list.add_path_source("path" => "/existing/path/to/gem")
source_list.add_git_source("uri" => "git://existing-git.org/path.git")
source_list.add_rubygems_source("remotes" => ["https://existing-rubygems.org"])
end
describe "#add_path_source" do
before do
@duplicate = source_list.add_path_source("path" => "/path/to/gem")
@new_source = source_list.add_path_source("path" => "/path/to/gem")
end
it "returns the new path source" do
expect(@new_source).to be_instance_of(Bundler::Source::Path)
end
it "passes the provided options to the new source" do
expect(@new_source.options).to eq("path" => "/path/to/gem")
end
it "adds the source to the beginning of path_sources" do
expect(source_list.path_sources.first).to equal(@new_source)
end
it "removes existing duplicates" do
expect(source_list.path_sources).not_to include equal(@duplicate)
end
end
describe "#add_git_source" do
before do
@duplicate = source_list.add_git_source("uri" => "git://host/path.git")
@new_source = source_list.add_git_source("uri" => "git://host/path.git")
end
it "returns the new git source" do
expect(@new_source).to be_instance_of(Bundler::Source::Git)
end
it "passes the provided options to the new source" do
expect(@new_source.options).to eq("uri" => "git://host/path.git")
end
it "adds the source to the beginning of git_sources" do
expect(source_list.git_sources.first).to equal(@new_source)
end
it "removes existing duplicates" do
expect(source_list.git_sources).not_to include equal(@duplicate)
end
end
describe "#add_rubygems_source" do
before do
@duplicate = source_list.add_rubygems_source("remotes" => ["https://rubygems.org/"])
@new_source = source_list.add_rubygems_source("remotes" => ["https://rubygems.org/"])
end
it "returns the new rubygems source" do
expect(@new_source).to be_instance_of(Bundler::Source::Rubygems)
end
it "passes the provided options to the new source" do
expect(@new_source.options).to eq("remotes" => ["https://rubygems.org/"])
end
it "adds the source to the beginning of rubygems_sources" do
expect(source_list.rubygems_sources.first).to equal(@new_source)
end
it "removes duplicates" do
expect(source_list.rubygems_sources).not_to include equal(@duplicate)
end
end
describe "#add_rubygems_remote" do
before do
@returned_source = source_list.add_rubygems_remote("https://rubygems.org/")
end
it "returns the aggregate rubygems source" do
expect(@returned_source).to be_instance_of(Bundler::Source::Rubygems)
end
it "adds the provided remote to the beginning of the aggregate source" do
source_list.add_rubygems_remote("https://othersource.org")
expect(@returned_source.remotes.first).to eq(URI("https://othersource.org/"))
end
end
end
describe "#all_sources" do
it "includes the aggregate rubygems source when rubygems sources have been added" do
source_list.add_git_source("uri" => "git://host/path.git")
source_list.add_rubygems_source("remotes" => ["https://rubygems.org"])
source_list.add_path_source("path" => "/path/to/gem")
expect(source_list.all_sources).to include rubygems_aggregate
end
it "includes the aggregate rubygems source when no rubygems sources have been added" do
source_list.add_git_source("uri" => "git://host/path.git")
source_list.add_path_source("path" => "/path/to/gem")
expect(source_list.all_sources).to include rubygems_aggregate
end
it "returns sources of the same type in the reverse order that they were added" do
source_list.add_git_source("uri" => "git://third-git.org/path.git")
source_list.add_rubygems_source("remotes" => ["https://fifth-rubygems.org"])
source_list.add_path_source("path" => "/third/path/to/gem")
source_list.add_rubygems_source("remotes" => ["https://fourth-rubygems.org"])
source_list.add_path_source("path" => "/second/path/to/gem")
source_list.add_rubygems_source("remotes" => ["https://third-rubygems.org"])
source_list.add_git_source("uri" => "git://second-git.org/path.git")
source_list.add_rubygems_source("remotes" => ["https://second-rubygems.org"])
source_list.add_path_source("path" => "/first/path/to/gem")
source_list.add_rubygems_source("remotes" => ["https://first-rubygems.org"])
source_list.add_git_source("uri" => "git://first-git.org/path.git")
expect(source_list.all_sources).to eq [
Bundler::Source::Path.new("path" => "/first/path/to/gem"),
Bundler::Source::Path.new("path" => "/second/path/to/gem"),
Bundler::Source::Path.new("path" => "/third/path/to/gem"),
Bundler::Source::Git.new("uri" => "git://first-git.org/path.git"),
Bundler::Source::Git.new("uri" => "git://second-git.org/path.git"),
Bundler::Source::Git.new("uri" => "git://third-git.org/path.git"),
Bundler::Source::Rubygems.new("remotes" => ["https://first-rubygems.org"]),
Bundler::Source::Rubygems.new("remotes" => ["https://second-rubygems.org"]),
Bundler::Source::Rubygems.new("remotes" => ["https://third-rubygems.org"]),
Bundler::Source::Rubygems.new("remotes" => ["https://fourth-rubygems.org"]),
Bundler::Source::Rubygems.new("remotes" => ["https://fifth-rubygems.org"]),
rubygems_aggregate,
]
end
end
describe "#path_sources" do
it "returns an empty array when no path sources have been added" do
source_list.add_rubygems_remote("https://rubygems.org")
source_list.add_git_source("uri" => "git://host/path.git")
expect(source_list.path_sources).to be_empty
end
it "returns path sources in the reverse order that they were added" do
source_list.add_git_source("uri" => "git://third-git.org/path.git")
source_list.add_rubygems_remote("https://fifth-rubygems.org")
source_list.add_path_source("path" => "/third/path/to/gem")
source_list.add_rubygems_remote("https://fourth-rubygems.org")
source_list.add_path_source("path" => "/second/path/to/gem")
source_list.add_rubygems_remote("https://third-rubygems.org")
source_list.add_git_source("uri" => "git://second-git.org/path.git")
source_list.add_rubygems_remote("https://second-rubygems.org")
source_list.add_path_source("path" => "/first/path/to/gem")
source_list.add_rubygems_remote("https://first-rubygems.org")
source_list.add_git_source("uri" => "git://first-git.org/path.git")
expect(source_list.path_sources).to eq [
Bundler::Source::Path.new("path" => "/first/path/to/gem"),
Bundler::Source::Path.new("path" => "/second/path/to/gem"),
Bundler::Source::Path.new("path" => "/third/path/to/gem"),
]
end
end
describe "#git_sources" do
it "returns an empty array when no git sources have been added" do
source_list.add_rubygems_remote("https://rubygems.org")
source_list.add_path_source("path" => "/path/to/gem")
expect(source_list.git_sources).to be_empty
end
it "returns git sources in the reverse order that they were added" do
source_list.add_git_source("uri" => "git://third-git.org/path.git")
source_list.add_rubygems_remote("https://fifth-rubygems.org")
source_list.add_path_source("path" => "/third/path/to/gem")
source_list.add_rubygems_remote("https://fourth-rubygems.org")
source_list.add_path_source("path" => "/second/path/to/gem")
source_list.add_rubygems_remote("https://third-rubygems.org")
source_list.add_git_source("uri" => "git://second-git.org/path.git")
source_list.add_rubygems_remote("https://second-rubygems.org")
source_list.add_path_source("path" => "/first/path/to/gem")
source_list.add_rubygems_remote("https://first-rubygems.org")
source_list.add_git_source("uri" => "git://first-git.org/path.git")
expect(source_list.git_sources).to eq [
Bundler::Source::Git.new("uri" => "git://first-git.org/path.git"),
Bundler::Source::Git.new("uri" => "git://second-git.org/path.git"),
Bundler::Source::Git.new("uri" => "git://third-git.org/path.git"),
]
end
end
describe "#rubygems_sources" do
it "includes the aggregate rubygems source when rubygems sources have been added" do
source_list.add_git_source("uri" => "git://host/path.git")
source_list.add_rubygems_source("remotes" => ["https://rubygems.org"])
source_list.add_path_source("path" => "/path/to/gem")
expect(source_list.rubygems_sources).to include rubygems_aggregate
end
it "returns only the aggregate rubygems source when no rubygems sources have been added" do
source_list.add_git_source("uri" => "git://host/path.git")
source_list.add_path_source("path" => "/path/to/gem")
expect(source_list.rubygems_sources).to eq [rubygems_aggregate]
end
it "returns rubygems sources in the reverse order that they were added" do
source_list.add_git_source("uri" => "git://third-git.org/path.git")
source_list.add_rubygems_source("remotes" => ["https://fifth-rubygems.org"])
source_list.add_path_source("path" => "/third/path/to/gem")
source_list.add_rubygems_source("remotes" => ["https://fourth-rubygems.org"])
source_list.add_path_source("path" => "/second/path/to/gem")
source_list.add_rubygems_source("remotes" => ["https://third-rubygems.org"])
source_list.add_git_source("uri" => "git://second-git.org/path.git")
source_list.add_rubygems_source("remotes" => ["https://second-rubygems.org"])
source_list.add_path_source("path" => "/first/path/to/gem")
source_list.add_rubygems_source("remotes" => ["https://first-rubygems.org"])
source_list.add_git_source("uri" => "git://first-git.org/path.git")
expect(source_list.rubygems_sources).to eq [
Bundler::Source::Rubygems.new("remotes" => ["https://first-rubygems.org"]),
Bundler::Source::Rubygems.new("remotes" => ["https://second-rubygems.org"]),
Bundler::Source::Rubygems.new("remotes" => ["https://third-rubygems.org"]),
Bundler::Source::Rubygems.new("remotes" => ["https://fourth-rubygems.org"]),
Bundler::Source::Rubygems.new("remotes" => ["https://fifth-rubygems.org"]),
rubygems_aggregate,
]
end
end
describe "#get" do
context "when it includes an equal source" do
let(:rubygems_source) { Bundler::Source::Rubygems.new("remotes" => ["https://rubygems.org"]) }
before { @equal_source = source_list.add_rubygems_remote("https://rubygems.org") }
it "returns the equal source" do
expect(source_list.get(rubygems_source)).to be @equal_source
end
end
context "when it does not include an equal source" do
let(:path_source) { Bundler::Source::Path.new("path" => "/path/to/gem") }
it "returns nil" do
expect(source_list.get(path_source)).to be_nil
end
end
end
describe "#lock_sources" do
it "combines the rubygems sources into a single instance, removing duplicate remotes from the end" do
source_list.add_git_source("uri" => "git://third-git.org/path.git")
source_list.add_rubygems_source("remotes" => ["https://duplicate-rubygems.org"])
source_list.add_path_source("path" => "/third/path/to/gem")
source_list.add_rubygems_source("remotes" => ["https://third-rubygems.org"])
source_list.add_path_source("path" => "/second/path/to/gem")
source_list.add_rubygems_source("remotes" => ["https://second-rubygems.org"])
source_list.add_git_source("uri" => "git://second-git.org/path.git")
source_list.add_rubygems_source("remotes" => ["https://first-rubygems.org"])
source_list.add_path_source("path" => "/first/path/to/gem")
source_list.add_rubygems_source("remotes" => ["https://duplicate-rubygems.org"])
source_list.add_git_source("uri" => "git://first-git.org/path.git")
expect(source_list.lock_sources).to eq [
Bundler::Source::Git.new("uri" => "git://first-git.org/path.git"),
Bundler::Source::Git.new("uri" => "git://second-git.org/path.git"),
Bundler::Source::Git.new("uri" => "git://third-git.org/path.git"),
Bundler::Source::Path.new("path" => "/first/path/to/gem"),
Bundler::Source::Path.new("path" => "/second/path/to/gem"),
Bundler::Source::Path.new("path" => "/third/path/to/gem"),
Bundler::Source::Rubygems.new("remotes" => [
"https://duplicate-rubygems.org",
"https://first-rubygems.org",
"https://second-rubygems.org",
"https://third-rubygems.org",
]),
]
end
end
describe "replace_sources!" do
let(:existing_locked_source) { Bundler::Source::Path.new("path" => "/existing/path") }
let(:removed_locked_source) { Bundler::Source::Path.new("path" => "/removed/path") }
let(:locked_sources) { [existing_locked_source, removed_locked_source] }
before do
@existing_source = source_list.add_path_source("path" => "/existing/path")
@new_source = source_list.add_path_source("path" => "/new/path")
source_list.replace_sources!(locked_sources)
end
it "maintains the order and number of sources" do
expect(source_list.path_sources).to eq [@new_source, @existing_source]
end
it "retains the same instance of the new source" do
expect(source_list.path_sources[0]).to be @new_source
end
it "replaces the instance of the existing source" do
expect(source_list.path_sources[1]).to be existing_locked_source
end
end
describe "#cached!" do
let(:rubygems_source) { source_list.add_rubygems_remote("https://rubygems.org") }
let(:git_source) { source_list.add_git_source("uri" => "git://host/path.git") }
let(:path_source) { source_list.add_path_source("path" => "/path/to/gem") }
it "calls #cached! on all the sources" do
expect(rubygems_source).to receive(:cached!)
expect(git_source).to receive(:cached!)
expect(path_source).to receive(:cached!)
source_list.cached!
end
end
describe "#remote!" do
let(:rubygems_source) { source_list.add_rubygems_remote("https://rubygems.org") }
let(:git_source) { source_list.add_git_source("uri" => "git://host/path.git") }
let(:path_source) { source_list.add_path_source("path" => "/path/to/gem") }
it "calls #remote! on all the sources" do
expect(rubygems_source).to receive(:remote!)
expect(git_source).to receive(:remote!)
expect(path_source).to receive(:remote!)
source_list.remote!
end
end
end
|