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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
|
# frozen_string_literal: true
RSpec.describe "bundler/inline#gemfile" do
def script(code, options = {})
options[:artifice] ||= "compact_index"
options[:env] ||= { "BUNDLER_SPEC_GEM_REPO" => gem_repo1.to_s }
ruby("require 'bundler/inline'\n\n" + code, options)
end
before :each do
build_lib "one", "1.0.0" do |s|
s.write "lib/baz.rb", "puts 'baz'"
s.write "lib/qux.rb", "puts 'qux'"
end
build_lib "two", "1.0.0" do |s|
s.write "lib/two.rb", "puts 'two'"
s.add_dependency "three", "= 1.0.0"
end
build_lib "three", "1.0.0" do |s|
s.write "lib/three.rb", "puts 'three'"
s.add_dependency "seven", "= 1.0.0"
end
build_lib "four", "1.0.0" do |s|
s.write "lib/four.rb", "puts 'four'"
end
build_lib "five", "1.0.0", no_default: true do |s|
s.write "lib/mofive.rb", "puts 'five'"
end
build_lib "six", "1.0.0" do |s|
s.write "lib/six.rb", "puts 'six'"
end
build_lib "seven", "1.0.0" do |s|
s.write "lib/seven.rb", "puts 'seven'"
end
build_lib "eight", "1.0.0" do |s|
s.write "lib/eight.rb", "puts 'eight'"
end
end
it "requires the gems" do
script <<-RUBY
gemfile do
source "https://gem.repo1"
path "#{lib_path}" do
gem "two"
end
end
RUBY
expect(out).to eq("two")
script <<-RUBY, raise_on_error: false
gemfile do
source "https://gem.repo1"
path "#{lib_path}" do
gem "eleven"
end
end
puts "success"
RUBY
expect(err).to include "Could not find gem 'eleven'"
expect(out).not_to include "success"
script <<-RUBY
gemfile(true) do
source "https://gem.repo1"
gem "myrack"
end
RUBY
expect(out).to include("Myrack's post install message")
script <<-RUBY, artifice: "endpoint"
gemfile(true) do
source "https://notaserver.test"
gem "activesupport", :require => true
end
RUBY
expect(out).to include("Installing activesupport")
err_lines = err.split("\n")
err_lines.reject! {|line| line =~ /\.rb:\d+: warning: / }
expect(err_lines).to be_empty
end
it "lets me use my own ui object" do
script <<-RUBY, artifice: "endpoint"
require 'bundler'
class MyBundlerUI < Bundler::UI::Shell
def confirm(msg, newline = nil)
puts "CONFIRMED!"
end
end
my_ui = MyBundlerUI.new
my_ui.level = "confirm"
gemfile(true, :ui => my_ui) do
source "https://notaserver.test"
gem "activesupport", :require => true
end
RUBY
expect(out).to eq("CONFIRMED!\nCONFIRMED!")
end
it "has an option for quiet installation" do
script <<-RUBY, artifice: "endpoint"
require 'bundler/inline'
gemfile(true, :quiet => true) do
source "https://notaserver.test"
gem "activesupport", :require => true
end
RUBY
expect(out).to be_empty
end
it "raises an exception if passed unknown arguments" do
script <<-RUBY, raise_on_error: false
gemfile(true, :arglebargle => true) do
path "#{lib_path}"
gem "two"
end
puts "success"
RUBY
expect(err).to include "Unknown options: arglebargle"
expect(out).not_to include "success"
end
it "does not mutate the option argument" do
script <<-RUBY
require 'bundler'
options = { :ui => Bundler::UI::Shell.new }
gemfile(false, options) do
source "https://gem.repo1"
path "#{lib_path}" do
gem "two"
end
end
puts "OKAY" if options.key?(:ui)
RUBY
expect(out).to match("OKAY")
end
it "installs quietly if necessary when the install option is not set" do
script <<-RUBY
gemfile do
source "https://gem.repo1"
gem "myrack"
end
puts MYRACK
RUBY
expect(out).to eq("1.0.0")
expect(err).to be_empty
end
it "installs subdependencies quietly if necessary when the install option is not set" do
build_repo4 do
build_gem "myrack" do |s|
s.add_dependency "myrackdep"
end
build_gem "myrackdep", "1.0.0"
end
script <<-RUBY, env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s }
gemfile do
source "https://gem.repo4"
gem "myrack"
end
require "myrackdep"
puts MYRACKDEP
RUBY
expect(out).to eq("1.0.0")
expect(err).to be_empty
end
it "installs subdependencies quietly if necessary when the install option is not set, and multiple sources used" do
build_repo4 do
build_gem "myrack" do |s|
s.add_dependency "myrackdep"
end
build_gem "myrackdep", "1.0.0"
end
script <<-RUBY, artifice: "compact_index_extra_api"
gemfile do
source "https://test.repo"
source "https://test.repo/extra" do
gem "myrack"
end
end
require "myrackdep"
puts MYRACKDEP
RUBY
expect(out).to eq("1.0.0")
expect(err).to be_empty
end
it "installs quietly from git if necessary when the install option is not set" do
build_git "foo", "1.0.0"
baz_ref = build_git("baz", "2.0.0").ref_for("HEAD")
script <<-RUBY
gemfile do
source "https://gem.repo1"
gem "foo", :git => #{lib_path("foo-1.0.0").to_s.dump}
gem "baz", :git => #{lib_path("baz-2.0.0").to_s.dump}, :ref => #{baz_ref.dump}
end
puts FOO
puts BAZ
RUBY
expect(out).to eq("1.0.0\n2.0.0")
expect(err).to be_empty
end
it "allows calling gemfile twice" do
script <<-RUBY
gemfile do
path "#{lib_path}" do
source "https://gem.repo1"
gem "two"
end
end
gemfile do
path "#{lib_path}" do
source "https://gem.repo1"
gem "four"
end
end
RUBY
expect(out).to eq("two\nfour")
expect(err).to be_empty
end
it "doesn't reinstall already installed gems" do
system_gems "myrack-1.0.0"
script <<-RUBY
require 'bundler'
ui = Bundler::UI::Shell.new
ui.level = "confirm"
gemfile(true, ui: ui) do
source "https://gem.repo1"
gem "activesupport"
gem "myrack"
end
RUBY
expect(out).to include("Installing activesupport")
expect(out).not_to include("Installing myrack")
expect(err).to be_empty
end
it "installs gems in later gemfile calls" do
system_gems "myrack-1.0.0"
script <<-RUBY
require 'bundler'
ui = Bundler::UI::Shell.new
ui.level = "confirm"
gemfile(true, ui: ui) do
source "https://gem.repo1"
gem "myrack"
end
gemfile(true, ui: ui) do
source "https://gem.repo1"
gem "activesupport"
end
RUBY
expect(out).to include("Installing activesupport")
expect(out).not_to include("Installing myrack")
expect(err).to be_empty
end
it "doesn't reinstall already installed gems in later gemfile calls" do
system_gems "myrack-1.0.0"
script <<-RUBY
require 'bundler'
ui = Bundler::UI::Shell.new
ui.level = "confirm"
gemfile(true, ui: ui) do
source "https://gem.repo1"
gem "activesupport"
end
gemfile(true, ui: ui) do
source "https://gem.repo1"
gem "myrack"
end
RUBY
expect(out).to include("Installing activesupport")
expect(out).not_to include("Installing myrack")
expect(err).to be_empty
end
it "installs gems with native extensions in later gemfile calls" do
system_gems "myrack-1.0.0"
build_git "foo" do |s|
s.add_dependency "rake"
s.extensions << "Rakefile"
s.write "Rakefile", <<-RUBY
task :default do
path = File.expand_path("lib", __dir__)
FileUtils.mkdir_p(path)
File.open("\#{path}/foo.rb", "w") do |f|
f.puts "FOO = 'YES'"
end
end
RUBY
end
script <<-RUBY
require 'bundler'
ui = Bundler::UI::Shell.new
ui.level = "confirm"
gemfile(true, ui: ui) do
source "https://gem.repo1"
gem "myrack"
end
gemfile(true, ui: ui) do
source "https://gem.repo1"
gem "foo", :git => "#{lib_path("foo-1.0")}"
end
require 'foo'
puts FOO
puts $:.grep(/ext/)
RUBY
expect(out).to include("YES")
expect(out).to include(Pathname.glob(default_bundle_path("bundler/gems/extensions/**/foo-1.0-*")).first.to_s)
expect(err).to be_empty
end
it "installs inline gems when a Gemfile.lock is present" do
gemfile <<-G
source "https://notaserver.test"
gem "rake"
G
lockfile <<-G
GEM
remote: https://rubygems.org/
specs:
rake (11.3.0)
PLATFORMS
ruby
DEPENDENCIES
rake
BUNDLED WITH
#{Bundler::VERSION}
G
script <<-RUBY
gemfile do
source "https://gem.repo1"
gem "myrack"
end
puts MYRACK
RUBY
expect(err).to be_empty
end
it "does not leak Gemfile.lock versions to the installation output" do
gemfile <<-G
source "https://notaserver.test"
gem "rake"
G
lockfile <<-G
GEM
remote: https://rubygems.org/
specs:
rake (11.3.0)
PLATFORMS
ruby
DEPENDENCIES
rake
BUNDLED WITH
#{Bundler::VERSION}
G
script <<-RUBY
gemfile(true) do
source "https://gem.repo1"
gem "rake", "#{rake_version}"
end
RUBY
expect(out).to include("Installing rake #{rake_version}")
expect(out).not_to include("was 11.3.0")
expect(err).to be_empty
end
it "installs inline gems when frozen is set" do
script <<-RUBY, env: { "BUNDLE_FROZEN" => "true", "BUNDLER_SPEC_GEM_REPO" => gem_repo1.to_s }
gemfile do
source "https://gem.repo1"
gem "myrack"
end
puts MYRACK
RUBY
expect(last_command.stderr).to be_empty
end
it "installs inline gems when deployment is set" do
script <<-RUBY, env: { "BUNDLE_DEPLOYMENT" => "true", "BUNDLER_SPEC_GEM_REPO" => gem_repo1.to_s }
gemfile do
source "https://gem.repo1"
gem "myrack"
end
puts MYRACK
RUBY
expect(last_command.stderr).to be_empty
end
it "installs inline gems when BUNDLE_GEMFILE is set to an empty string" do
ENV["BUNDLE_GEMFILE"] = ""
script <<-RUBY
gemfile do
source "https://gem.repo1"
gem "myrack"
end
puts MYRACK
RUBY
expect(err).to be_empty
end
it "installs inline gems when BUNDLE_BIN is set" do
ENV["BUNDLE_BIN"] = "/usr/local/bundle/bin"
script <<-RUBY
gemfile do
source "https://gem.repo1"
gem "myrack" # has the myrackup executable
end
puts MYRACK
RUBY
expect(last_command).to be_success
expect(out).to eq "1.0.0"
end
context "when BUNDLE_PATH is set" do
it "installs inline gems to the system path regardless" do
script <<-RUBY, env: { "BUNDLE_PATH" => "./vendor/inline", "BUNDLER_SPEC_GEM_REPO" => gem_repo1.to_s }
gemfile(true) do
source "https://gem.repo1"
gem "myrack"
end
RUBY
expect(last_command).to be_success
expect(system_gem_path("gems/myrack-1.0.0")).to exist
end
end
it "skips platform warnings" do
bundle "config set --local force_ruby_platform true"
script <<-RUBY
gemfile(true) do
source "https://gem.repo1"
gem "myrack", platform: :jruby
end
RUBY
expect(err).to be_empty
end
it "still installs if the application has `bundle package` no_install config set" do
bundle "config set --local no_install true"
script <<-RUBY
gemfile do
source "https://gem.repo1"
gem "myrack"
end
RUBY
expect(last_command).to be_success
expect(system_gem_path("gems/myrack-1.0.0")).to exist
end
it "preserves previous BUNDLE_GEMFILE value" do
ENV["BUNDLE_GEMFILE"] = ""
script <<-RUBY
gemfile do
source "https://gem.repo1"
gem "myrack"
end
puts "BUNDLE_GEMFILE is empty" if ENV["BUNDLE_GEMFILE"].empty?
system("#{Gem.ruby} -w -e '42'") # this should see original value of BUNDLE_GEMFILE
exit $?.exitstatus
RUBY
expect(last_command).to be_success
expect(out).to include("BUNDLE_GEMFILE is empty")
end
it "resets BUNDLE_GEMFILE to the empty string if it wasn't set previously" do
ENV["BUNDLE_GEMFILE"] = nil
script <<-RUBY
gemfile do
source "https://gem.repo1"
gem "myrack"
end
puts "BUNDLE_GEMFILE is empty" if ENV["BUNDLE_GEMFILE"].empty?
system("#{Gem.ruby} -w -e '42'") # this should see original value of BUNDLE_GEMFILE
exit $?.exitstatus
RUBY
expect(last_command).to be_success
expect(out).to include("BUNDLE_GEMFILE is empty")
end
it "does not error out if library requires optional dependencies" do
Dir.mkdir tmp("path_without_gemfile")
foo_code = <<~RUBY
begin
gem "bar"
rescue LoadError
end
puts "WIN"
RUBY
build_lib "foo", "1.0.0" do |s|
s.write "lib/foo.rb", foo_code
end
script <<-RUBY, dir: tmp("path_without_gemfile"), env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo2.to_s }
gemfile do
source "https://gem.repo2"
path "#{lib_path}" do
gem "foo", require: false
end
end
require "foo"
RUBY
expect(out).to eq("WIN")
expect(err).to be_empty
end
it "when requiring fileutils after does not show redefinition warnings" do
Dir.mkdir tmp("path_without_gemfile")
default_fileutils_version = ruby "gem 'fileutils', '< 999999'; require 'fileutils'; puts FileUtils::VERSION", raise_on_error: false
skip "fileutils isn't a default gem" if default_fileutils_version.empty?
realworld_system_gems "fileutils --version 1.4.1"
realworld_system_gems "pathname --version 0.2.0"
script <<-RUBY, dir: tmp("path_without_gemfile"), env: { "BUNDLER_GEM_DEFAULT_DIR" => system_gem_path.to_s, "BUNDLER_SPEC_GEM_REPO" => gem_repo2.to_s }
require "bundler/inline"
gemfile(true) do
source "https://gem.repo2"
end
require "fileutils"
RUBY
expect(err).to eq("The Gemfile specifies no dependencies")
end
it "does not load default timeout" do
default_timeout_version = ruby "gem 'timeout', '< 999999'; require 'timeout'; puts Timeout::VERSION", raise_on_error: false
skip "timeout isn't a default gem" if default_timeout_version.empty?
# This only works on RubyGems 3.5.0 or higher
ruby "require 'rubygems/timeout'", raise_on_error: false
skip "rubygems under test does not yet vendor timeout" unless last_command.success?
build_repo4 do
build_gem "timeout", "999"
end
script <<-RUBY, env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s }
require "bundler/inline"
gemfile(true) do
source "https://gem.repo4"
gem "timeout"
end
RUBY
expect(out).to include("Installing timeout 999")
end
it "does not upcase ENV" do
script <<-RUBY
require 'bundler/inline'
ENV['Test_Variable'] = 'value string'
puts("before: \#{ENV.each_key.select { |key| key.match?(/test_variable/i) }}")
gemfile do
source "https://gem.repo1"
end
puts("after: \#{ENV.each_key.select { |key| key.match?(/test_variable/i) }}")
RUBY
expect(out).to include("before: [\"Test_Variable\"]")
expect(out).to include("after: [\"Test_Variable\"]")
end
it "does not create a lockfile" do
script <<-RUBY
require 'bundler/inline'
gemfile do
source "https://gem.repo1"
end
puts Dir.glob("Gemfile.lock")
RUBY
expect(out).to be_empty
end
it "does not reset ENV" do
script <<-RUBY
require 'bundler/inline'
gemfile do
source "https://gem.repo1"
ENV['FOO'] = 'bar'
end
puts ENV['FOO']
RUBY
expect(out).to eq("bar")
end
it "does not load specified version of psych and stringio", :ruby_repo do
build_repo4 do
build_gem "psych", "999"
build_gem "stringio", "999"
end
script <<-RUBY, env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s }
require "bundler/inline"
gemfile(true) do
source "https://gem.repo4"
gem "psych"
gem "stringio"
end
RUBY
expect(out).to include("Installing psych 999")
expect(out).to include("Installing stringio 999")
expect(out).to include("The psych gem was resolved to 999")
expect(out).to include("The stringio gem was resolved to 999")
end
it "leaves a lockfile in the same directory as the inline script alone" do
install_gemfile <<~G
source "https://gem.repo1"
gem "foo"
G
original_lockfile = lockfile
script <<-RUBY, env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo1.to_s }
require "bundler/inline"
gemfile(true) do
source "https://gem.repo1"
gem "myrack"
end
RUBY
expect(lockfile).to eq(original_lockfile)
end
end
|