-
Notifications
You must be signed in to change notification settings - Fork 5.3k
/
lock_spec.rb
1577 lines (1273 loc) · 42.6 KB
/
lock_spec.rb
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
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# frozen_string_literal: true
RSpec.describe "bundle lock" do
let(:repo) { gem_repo1 }
before :each do
gemfile <<-G
source "#{file_uri_for(repo)}"
gem "rails"
gem "weakling"
gem "foo"
G
checksums = checksums_section_when_existing do |c|
c.checksum repo, "actionmailer", "2.3.2"
c.checksum repo, "actionpack", "2.3.2"
c.checksum repo, "activerecord", "2.3.2"
c.checksum repo, "activeresource", "2.3.2"
c.checksum repo, "activesupport", "2.3.2"
c.checksum repo, "foo", "1.0"
c.checksum repo, "rails", "2.3.2"
c.checksum repo, "rake", "13.0.1"
c.checksum repo, "weakling", "0.0.3"
end
@lockfile = <<~L
GEM
remote: #{file_uri_for(repo)}/
specs:
actionmailer (2.3.2)
activesupport (= 2.3.2)
actionpack (2.3.2)
activesupport (= 2.3.2)
activerecord (2.3.2)
activesupport (= 2.3.2)
activeresource (2.3.2)
activesupport (= 2.3.2)
activesupport (2.3.2)
foo (1.0)
rails (2.3.2)
actionmailer (= 2.3.2)
actionpack (= 2.3.2)
activerecord (= 2.3.2)
activeresource (= 2.3.2)
rake (= 13.0.1)
rake (13.0.1)
weakling (0.0.3)
PLATFORMS
#{lockfile_platforms}
DEPENDENCIES
foo
rails
weakling
#{checksums}
BUNDLED WITH
#{Bundler::VERSION}
L
end
it "prints a lockfile when there is no existing lockfile with --print" do
bundle "lock --print"
expect(out).to eq(@lockfile.chomp)
end
it "prints a lockfile when there is an existing lockfile with --print" do
lockfile remove_checksums_section_from_lockfile(@lockfile)
bundle "lock --print"
expect(out).to eq(remove_checksums_section_from_lockfile(@lockfile).chomp)
end
it "prints a lockfile when there is an existing checksums lockfile with --print" do
lockfile @lockfile
bundle "lock --print"
expect(out).to eq(@lockfile.chomp)
end
it "writes a lockfile when there is no existing lockfile" do
bundle "lock"
expect(read_lockfile).to eq(@lockfile)
end
it "prints a lockfile without fetching new checksums if the existing lockfile had no checksums" do
lockfile remove_checksums_from_lockfile(@lockfile)
bundle "lock --print"
expect(out).to eq(remove_checksums_from_lockfile(@lockfile).chomp)
end
it "touches the lockfile when there is an existing lockfile that does not need changes" do
lockfile @lockfile
expect do
bundle "lock"
end.to change { bundled_app_lock.mtime }
end
it "does not touch lockfile with --print" do
lockfile @lockfile
expect do
bundle "lock --print"
end.not_to change { bundled_app_lock.mtime }
end
it "writes a lockfile when there is an outdated lockfile using --update" do
lockfile remove_checksums_from_lockfile(@lockfile.gsub("2.3.2", "2.3.1"), " (2.3.1)")
bundle "lock --update"
expect(read_lockfile).to eq(remove_checksums_from_lockfile(@lockfile))
end
it "writes a lockfile with checksums on --update when checksums exist" do
lockfile @lockfile.gsub("2.3.2", "2.3.1")
bundle "lock --update"
expect(read_lockfile).to eq(@lockfile)
end
it "writes a lockfile when there is an outdated lockfile and bundle is frozen" do
lockfile @lockfile.gsub("2.3.2", "2.3.1")
bundle "lock --update", env: { "BUNDLE_FROZEN" => "true" }
expect(read_lockfile).to eq(@lockfile)
end
it "does not fetch remote specs when using the --local option" do
bundle "lock --update --local", raise_on_error: false
expect(err).to match(/locally installed gems/)
end
it "does not fetch remote checksums with --local" do
lockfile remove_checksums_from_lockfile(@lockfile)
bundle "lock --print --local"
# No checksums because --local prevents fetching them
expect(out).to eq(remove_checksums_from_lockfile(@lockfile).chomp)
end
it "works with --gemfile flag" do
create_file "CustomGemfile", <<-G
source "#{file_uri_for(repo)}"
gem "foo"
G
checksums = checksums_section_when_existing do |c|
c.no_checksum "foo", "1.0"
end
lockfile = <<~L
GEM
remote: #{file_uri_for(repo)}/
specs:
foo (1.0)
PLATFORMS
#{lockfile_platforms}
DEPENDENCIES
foo
#{checksums}
BUNDLED WITH
#{Bundler::VERSION}
L
bundle "lock --gemfile CustomGemfile"
expect(out).to match(/Writing lockfile to.+CustomGemfile\.lock/)
expect(read_lockfile("CustomGemfile.lock")).to eq(lockfile)
expect { read_lockfile }.to raise_error(Errno::ENOENT)
end
it "writes to a custom location using --lockfile" do
bundle "lock --lockfile=lock"
expect(out).to match(/Writing lockfile to.+lock/)
expect(read_lockfile("lock")).to eq(remove_checksums_from_lockfile(@lockfile))
expect { read_lockfile }.to raise_error(Errno::ENOENT)
end
it "writes to custom location using --lockfile when a default lockfile is present" do
bundle "install"
bundle "lock --lockfile=lock"
checksums = checksums_section_when_existing do |c|
c.checksum repo, "actionmailer", "2.3.2"
c.checksum repo, "actionpack", "2.3.2"
c.checksum repo, "activerecord", "2.3.2"
c.checksum repo, "activeresource", "2.3.2"
c.checksum repo, "activesupport", "2.3.2"
c.checksum repo, "foo", "1.0"
c.checksum repo, "rails", "2.3.2"
c.checksum repo, "rake", "13.0.1"
c.checksum repo, "weakling", "0.0.3"
end
lockfile = <<~L
GEM
remote: #{file_uri_for(repo)}/
specs:
actionmailer (2.3.2)
activesupport (= 2.3.2)
actionpack (2.3.2)
activesupport (= 2.3.2)
activerecord (2.3.2)
activesupport (= 2.3.2)
activeresource (2.3.2)
activesupport (= 2.3.2)
activesupport (2.3.2)
foo (1.0)
rails (2.3.2)
actionmailer (= 2.3.2)
actionpack (= 2.3.2)
activerecord (= 2.3.2)
activeresource (= 2.3.2)
rake (= 13.0.1)
rake (13.0.1)
weakling (0.0.3)
PLATFORMS
#{lockfile_platforms}
DEPENDENCIES
foo
rails
weakling
#{checksums}
BUNDLED WITH
#{Bundler::VERSION}
L
expect(out).to match(/Writing lockfile to.+lock/)
expect(read_lockfile("lock")).to eq(lockfile)
end
it "update specific gems using --update" do
lockfile @lockfile.gsub("2.3.2", "2.3.1").gsub("13.0.1", "10.0.1")
bundle "lock --update rails rake"
expect(read_lockfile).to eq(remove_checksums_from_lockfile(@lockfile, "(2.3.2)", "(13.0.1)"))
end
it "preserves unknown checksum algorithms" do
lockfile @lockfile.gsub(/(sha256=[a-f0-9]+)$/, "constant=true,\\1,xyz=123")
previous_lockfile = read_lockfile
bundle "lock"
expect(read_lockfile).to eq(previous_lockfile)
end
it "does not unlock git sources when only uri shape changes" do
build_git("foo")
install_gemfile <<-G
source "#{file_uri_for(gem_repo1)}"
gem "foo", :git => "#{file_uri_for(lib_path("foo-1.0"))}"
G
# Change uri format to end with "/" and reinstall
install_gemfile <<-G, verbose: true
source "#{file_uri_for(gem_repo1)}"
gem "foo", :git => "#{file_uri_for(lib_path("foo-1.0"))}/"
G
expect(out).to include("using resolution from the lockfile")
expect(out).not_to include("re-resolving dependencies because the list of sources changed")
end
it "updates specific gems using --update using the locked revision of unrelated git gems for resolving" do
ref = build_git("foo").ref_for("HEAD")
gemfile <<-G
source "#{file_uri_for(gem_repo1)}"
gem "rake"
gem "foo", :git => "#{file_uri_for(lib_path("foo-1.0"))}", :branch => "deadbeef"
G
lockfile <<~L
GIT
remote: #{file_uri_for(lib_path("foo-1.0"))}
revision: #{ref}
branch: deadbeef
specs:
foo (1.0)
GEM
remote: #{file_uri_for(gem_repo1)}/
specs:
rake (10.0.1)
PLATFORMS
#{lockfile_platforms}
DEPENDENCIES
foo!
rake
BUNDLED WITH
#{Bundler::VERSION}
L
bundle "lock --update rake --verbose"
expect(out).to match(/Writing lockfile to.+lock/)
expect(lockfile).to include("rake (13.0.1)")
end
it "errors when updating a missing specific gems using --update" do
lockfile @lockfile
bundle "lock --update blahblah", raise_on_error: false
expect(err).to eq("Could not find gem 'blahblah'.")
expect(read_lockfile).to eq(@lockfile)
end
it "can lock without downloading gems" do
gemfile <<-G
source "#{file_uri_for(gem_repo1)}"
gem "thin"
gem "rack_middleware", :group => "test"
G
bundle "config set without test"
bundle "config set path vendor/bundle"
bundle "lock", verbose: true
expect(bundled_app("vendor/bundle")).not_to exist
end
# see update_spec for more coverage on same options. logic is shared so it's not necessary
# to repeat coverage here.
context "conservative updates" do
before do
build_repo4 do
build_gem "foo", %w[1.4.3 1.4.4] do |s|
s.add_dependency "bar", "~> 2.0"
end
build_gem "foo", %w[1.4.5 1.5.0] do |s|
s.add_dependency "bar", "~> 2.1"
end
build_gem "foo", %w[1.5.1] do |s|
s.add_dependency "bar", "~> 3.0"
end
build_gem "foo", %w[2.0.0.pre] do |s|
s.add_dependency "bar"
end
build_gem "bar", %w[2.0.3 2.0.4 2.0.5 2.1.0 2.1.1 2.1.2.pre 3.0.0 3.1.0.pre 4.0.0.pre]
build_gem "qux", %w[1.0.0 1.0.1 1.1.0 2.0.0]
end
# establish a lockfile set to 1.4.3
install_gemfile <<-G
source "#{file_uri_for(gem_repo4)}"
gem 'foo', '1.4.3'
gem 'bar', '2.0.3'
gem 'qux', '1.0.0'
G
# remove 1.4.3 requirement and bar altogether
# to setup update specs below
gemfile <<-G
source "#{file_uri_for(gem_repo4)}"
gem 'foo'
gem 'qux'
G
allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
end
it "single gem updates dependent gem to minor" do
bundle "lock --update foo --patch"
expect(the_bundle.locked_gems.specs.map(&:full_name)).to eq(%w[foo-1.4.5 bar-2.1.1 qux-1.0.0].sort)
end
it "minor preferred with strict" do
bundle "lock --update --minor --strict"
expect(the_bundle.locked_gems.specs.map(&:full_name)).to eq(%w[foo-1.5.0 bar-2.1.1 qux-1.1.0].sort)
end
context "pre" do
it "defaults to major" do
bundle "lock --update --pre"
expect(the_bundle.locked_gems.specs.map(&:full_name)).to eq(%w[foo-2.0.0.pre bar-4.0.0.pre qux-2.0.0].sort)
end
it "patch preferred" do
bundle "lock --update --patch --pre"
expect(the_bundle.locked_gems.specs.map(&:full_name)).to eq(%w[foo-1.4.5 bar-2.1.2.pre qux-1.0.1].sort)
end
it "minor preferred" do
bundle "lock --update --minor --pre"
expect(the_bundle.locked_gems.specs.map(&:full_name)).to eq(%w[foo-1.5.1 bar-3.1.0.pre qux-1.1.0].sort)
end
it "major preferred" do
bundle "lock --update --major --pre"
expect(the_bundle.locked_gems.specs.map(&:full_name)).to eq(%w[foo-2.0.0.pre bar-4.0.0.pre qux-2.0.0].sort)
end
end
end
context "conservative updates when minor update adds a new dependency" do
before do
build_repo4 do
build_gem "sequel", "5.71.0"
build_gem "sequel", "5.72.0" do |s|
s.add_dependency "bigdecimal", ">= 0"
end
build_gem "bigdecimal", %w[1.4.4 99.1.4]
end
gemfile <<~G
source "#{file_uri_for(gem_repo4)}"
gem 'sequel'
G
lockfile <<~L
GEM
remote: #{file_uri_for(gem_repo4)}/
specs:
sequel (5.71.0)
PLATFORMS
ruby
DEPENDENCIES
sequel
BUNDLED WITH
#{Bundler::VERSION}
L
allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
end
it "adds the latest version of the new dependency" do
bundle "lock --minor --update sequel"
expect(the_bundle.locked_gems.specs.map(&:full_name)).to eq(%w[sequel-5.72.0 bigdecimal-99.1.4].sort)
end
end
it "updates the bundler version in the lockfile to the latest bundler version" do
build_repo4 do
build_gem "bundler", "55"
end
system_gems "bundler-55", gem_repo: gem_repo4
install_gemfile <<-G, artifice: "compact_index", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s }
source "https://gems.repo4"
G
lockfile lockfile.sub(/(^\s*)#{Bundler::VERSION}($)/, '\11.0.0\2')
bundle "lock --update --bundler --verbose", artifice: "compact_index", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s }
expect(lockfile).to end_with("BUNDLED WITH\n 55\n")
update_repo4 do
build_gem "bundler", "99"
end
bundle "lock --update --bundler --verbose", artifice: "compact_index", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s }
expect(lockfile).to end_with("BUNDLED WITH\n 99\n")
end
it "supports adding new platforms" do
bundle "lock --add-platform java x86-mingw32"
allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
lockfile = Bundler::LockfileParser.new(read_lockfile)
expect(lockfile.platforms).to match_array(default_platform_list(java, x86_mingw32))
end
it "supports adding new platforms with force_ruby_platform = true" do
lockfile <<-L
GEM
remote: #{file_uri_for(gem_repo1)}/
specs:
platform_specific (1.0)
platform_specific (1.0-x86-64_linux)
PLATFORMS
ruby
x86_64-linux
DEPENDENCIES
platform_specific
L
bundle "config set force_ruby_platform true"
bundle "lock --add-platform java x86-mingw32"
allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
lockfile = Bundler::LockfileParser.new(read_lockfile)
expect(lockfile.platforms).to contain_exactly(rb, linux, java, x86_mingw32)
end
it "supports adding the `ruby` platform" do
bundle "lock --add-platform ruby"
allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
lockfile = Bundler::LockfileParser.new(read_lockfile)
expect(lockfile.platforms).to match_array(default_platform_list("ruby"))
end
it "warns when adding an unknown platform" do
bundle "lock --add-platform foobarbaz"
expect(err).to include("The platform `foobarbaz` is unknown to RubyGems and adding it will likely lead to resolution errors")
end
it "allows removing platforms" do
bundle "lock --add-platform java x86-mingw32"
allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
lockfile = Bundler::LockfileParser.new(read_lockfile)
expect(lockfile.platforms).to match_array(default_platform_list(java, x86_mingw32))
bundle "lock --remove-platform java"
lockfile = Bundler::LockfileParser.new(read_lockfile)
expect(lockfile.platforms).to match_array(default_platform_list(x86_mingw32))
end
it "also cleans up redundant platform gems when removing platforms" do
build_repo4 do
build_gem "nokogiri", "1.12.0"
build_gem "nokogiri", "1.12.0" do |s|
s.platform = "x86_64-darwin"
end
end
checksums = checksums_section_when_existing do |c|
c.checksum gem_repo4, "nokogiri", "1.12.0"
c.checksum gem_repo4, "nokogiri", "1.12.0", "x86_64-darwin"
end
simulate_platform "x86_64-darwin-22" do
install_gemfile <<~G
source "#{file_uri_for(gem_repo4)}"
gem "nokogiri"
G
end
lockfile <<~L
GEM
remote: #{file_uri_for(gem_repo4)}/
specs:
nokogiri (1.12.0)
nokogiri (1.12.0-x86_64-darwin)
PLATFORMS
ruby
x86_64-darwin
DEPENDENCIES
nokogiri
#{checksums}
BUNDLED WITH
#{Bundler::VERSION}
L
checksums.delete("nokogiri", Gem::Platform::RUBY)
simulate_platform "x86_64-darwin-22" do
bundle "lock --remove-platform ruby"
end
expect(lockfile).to eq <<~L
GEM
remote: #{file_uri_for(gem_repo4)}/
specs:
nokogiri (1.12.0-x86_64-darwin)
PLATFORMS
x86_64-darwin
DEPENDENCIES
nokogiri
#{checksums}
BUNDLED WITH
#{Bundler::VERSION}
L
end
it "errors when removing all platforms" do
bundle "lock --remove-platform #{local_platform}", raise_on_error: false
expect(err).to include("Removing all platforms from the bundle is not allowed")
end
# from https://github.com/rubygems/bundler/issues/4896
it "properly adds platforms when platform requirements come from different dependencies" do
build_repo4 do
build_gem "ffi", "1.9.14"
build_gem "ffi", "1.9.14" do |s|
s.platform = x86_mingw32
end
build_gem "gssapi", "0.1"
build_gem "gssapi", "0.2"
build_gem "gssapi", "0.3"
build_gem "gssapi", "1.2.0" do |s|
s.add_dependency "ffi", ">= 1.0.1"
end
build_gem "mixlib-shellout", "2.2.6"
build_gem "mixlib-shellout", "2.2.6" do |s|
s.platform = "universal-mingw32"
s.add_dependency "win32-process", "~> 0.8.2"
end
# we need all these versions to get the sorting the same as it would be
# pulling from rubygems.org
%w[0.8.3 0.8.2 0.8.1 0.8.0].each do |v|
build_gem "win32-process", v do |s|
s.add_dependency "ffi", ">= 1.0.0"
end
end
end
gemfile <<-G
source "#{file_uri_for(gem_repo4)}"
gem "mixlib-shellout"
gem "gssapi"
G
checksums = checksums_section_when_existing do |c|
c.no_checksum "ffi", "1.9.14", "x86-mingw32"
c.no_checksum "gssapi", "1.2.0"
c.no_checksum "mixlib-shellout", "2.2.6", "universal-mingw32"
c.no_checksum "win32-process", "0.8.3"
end
simulate_platform(x86_mingw32) { bundle :lock }
expect(lockfile).to eq <<~G
GEM
remote: #{file_uri_for(gem_repo4)}/
specs:
ffi (1.9.14-x86-mingw32)
gssapi (1.2.0)
ffi (>= 1.0.1)
mixlib-shellout (2.2.6-universal-mingw32)
win32-process (~> 0.8.2)
win32-process (0.8.3)
ffi (>= 1.0.0)
PLATFORMS
x86-mingw32
DEPENDENCIES
gssapi
mixlib-shellout
#{checksums}
BUNDLED WITH
#{Bundler::VERSION}
G
bundle "config set --local force_ruby_platform true"
bundle :lock
checksums.no_checksum "ffi", "1.9.14"
checksums.no_checksum "mixlib-shellout", "2.2.6"
expect(lockfile).to eq <<~G
GEM
remote: #{file_uri_for(gem_repo4)}/
specs:
ffi (1.9.14)
ffi (1.9.14-x86-mingw32)
gssapi (1.2.0)
ffi (>= 1.0.1)
mixlib-shellout (2.2.6)
mixlib-shellout (2.2.6-universal-mingw32)
win32-process (~> 0.8.2)
win32-process (0.8.3)
ffi (>= 1.0.0)
PLATFORMS
ruby
x86-mingw32
DEPENDENCIES
gssapi
mixlib-shellout
#{checksums}
BUNDLED WITH
#{Bundler::VERSION}
G
end
it "doesn't crash when an update candidate doesn't have any matching platform" do
build_repo4 do
build_gem "libv8", "8.4.255.0"
build_gem "libv8", "8.4.255.0" do |s|
s.platform = "x86_64-darwin-19"
end
build_gem "libv8", "15.0.71.48.1beta2" do |s|
s.platform = "x86_64-linux"
end
end
gemfile <<-G
source "#{file_uri_for(gem_repo4)}"
gem "libv8"
G
lockfile <<-G
GEM
remote: #{file_uri_for(gem_repo4)}/
specs:
libv8 (8.4.255.0)
libv8 (8.4.255.0-x86_64-darwin-19)
PLATFORMS
ruby
x86_64-darwin-19
DEPENDENCIES
libv8
BUNDLED WITH
#{Bundler::VERSION}
G
simulate_platform(Gem::Platform.new("x86_64-darwin-19")) { bundle "lock --update" }
expect(out).to match(/Writing lockfile to.+Gemfile\.lock/)
end
it "adds all more specific candidates when they all have the same dependencies" do
build_repo4 do
build_gem "libv8", "8.4.255.0" do |s|
s.platform = "x86_64-darwin-19"
end
build_gem "libv8", "8.4.255.0" do |s|
s.platform = "x86_64-darwin-20"
end
end
gemfile <<-G
source "#{file_uri_for(gem_repo4)}"
gem "libv8"
G
simulate_platform(Gem::Platform.new("x86_64-darwin-19")) { bundle "lock" }
checksums = checksums_section_when_existing do |c|
c.no_checksum "libv8", "8.4.255.0", "x86_64-darwin-19"
c.no_checksum "libv8", "8.4.255.0", "x86_64-darwin-20"
end
expect(lockfile).to eq <<~G
GEM
remote: #{file_uri_for(gem_repo4)}/
specs:
libv8 (8.4.255.0-x86_64-darwin-19)
libv8 (8.4.255.0-x86_64-darwin-20)
PLATFORMS
x86_64-darwin-19
x86_64-darwin-20
DEPENDENCIES
libv8
#{checksums}
BUNDLED WITH
#{Bundler::VERSION}
G
end
it "respects the previous lockfile if it had a matching less specific platform already locked, and installs the best variant for each platform" do
build_repo4 do
build_gem "libv8", "8.4.255.0" do |s|
s.platform = "x86_64-darwin-19"
end
build_gem "libv8", "8.4.255.0" do |s|
s.platform = "x86_64-darwin-20"
end
end
checksums = checksums_section_when_existing do |c|
c.checksum gem_repo4, "libv8", "8.4.255.0", "x86_64-darwin-19"
c.checksum gem_repo4, "libv8", "8.4.255.0", "x86_64-darwin-20"
end
gemfile <<-G
source "#{file_uri_for(gem_repo4)}"
gem "libv8"
G
lockfile <<-G
GEM
remote: #{file_uri_for(gem_repo4)}/
specs:
libv8 (8.4.255.0-x86_64-darwin-19)
libv8 (8.4.255.0-x86_64-darwin-20)
PLATFORMS
x86_64-darwin
DEPENDENCIES
libv8
#{checksums}
BUNDLED WITH
#{Bundler::VERSION}
G
previous_lockfile = lockfile
%w[x86_64-darwin-19 x86_64-darwin-20].each do |platform|
simulate_platform(Gem::Platform.new(platform)) do
bundle "lock"
expect(lockfile).to eq(previous_lockfile)
bundle "install"
expect(the_bundle).to include_gem("libv8 8.4.255.0 #{platform}")
end
end
end
it "does not conflict on ruby requirements when adding new platforms" do
build_repo4 do
build_gem "raygun-apm", "1.0.78" do |s|
s.platform = "x86_64-linux"
s.required_ruby_version = "< #{next_ruby_minor}.dev"
end
build_gem "raygun-apm", "1.0.78" do |s|
s.platform = "universal-darwin"
s.required_ruby_version = "< #{next_ruby_minor}.dev"
end
build_gem "raygun-apm", "1.0.78" do |s|
s.platform = "x64-mingw32"
s.required_ruby_version = "< #{next_ruby_minor}.dev"
end
build_gem "raygun-apm", "1.0.78" do |s|
s.platform = "x64-mingw-ucrt"
s.required_ruby_version = "< #{next_ruby_minor}.dev"
end
end
gemfile <<-G
source "https://localgemserver.test"
gem "raygun-apm"
G
lockfile <<-L
GEM
remote: https://localgemserver.test/
specs:
raygun-apm (1.0.78-universal-darwin)
PLATFORMS
x86_64-darwin-19
DEPENDENCIES
raygun-apm
BUNDLED WITH
#{Bundler::VERSION}
L
bundle "lock --add-platform x86_64-linux", artifice: "compact_index", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s }
end
it "does not crash on conflicting ruby requirements between platform versions in two different gems" do
build_repo4 do
build_gem "unf_ext", "0.0.8.2"
build_gem "unf_ext", "0.0.8.2" do |s|
s.required_ruby_version = [">= 2.4", "< #{previous_ruby_minor}"]
s.platform = "x64-mingw32"
end
build_gem "unf_ext", "0.0.8.2" do |s|
s.required_ruby_version = [">= #{previous_ruby_minor}", "< #{current_ruby_minor}"]
s.platform = "x64-mingw-ucrt"
end
build_gem "google-protobuf", "3.21.12"
build_gem "google-protobuf", "3.21.12" do |s|
s.required_ruby_version = [">= 2.5", "< #{previous_ruby_minor}"]
s.platform = "x64-mingw32"
end
build_gem "google-protobuf", "3.21.12" do |s|
s.required_ruby_version = [">= #{previous_ruby_minor}", "< #{current_ruby_minor}"]
s.platform = "x64-mingw-ucrt"
end
end
gemfile <<~G
source "https://gem.repo4"
gem "google-protobuf"
gem "unf_ext"
G
lockfile <<~L
GEM
remote: https://gem.repo4/
specs:
google-protobuf (3.21.12)
unf_ext (0.0.8.2)
PLATFORMS
x64-mingw-ucrt
x64-mingw32
DEPENDENCIES
google-protobuf
unf_ext
BUNDLED WITH
#{Bundler::VERSION}
L
bundle "install --verbose", artifice: "compact_index", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s, "DEBUG_RESOLVER" => "1" }
end
it "respects lower bound ruby requirements" do
build_repo4 do
build_gem "our_private_gem", "0.1.0" do |s|
s.required_ruby_version = ">= #{Gem.ruby_version}"
end
end
gemfile <<-G
source "https://localgemserver.test"
gem "our_private_gem"
G
lockfile <<-L
GEM
remote: https://localgemserver.test/
specs:
our_private_gem (0.1.0)
PLATFORMS
#{lockfile_platforms}
DEPENDENCIES
our_private_gem
BUNDLED WITH
#{Bundler::VERSION}
L
bundle "install", artifice: "compact_index", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s }
end
context "when an update is available" do
let(:repo) do
build_repo2 do
build_gem "foo", "2.0"
end
gem_repo2
end
before do
lockfile(@lockfile)
end
it "does not implicitly update" do
bundle "lock"
checksums = checksums_section_when_existing do |c|