Skip to content

Commit 3e3ba2a

Browse files
authored
Merge pull request #6023 from tnir/tnir-6012-ignore-patchlevel-in-ruby-dsl
Bundler: ignore patchlevel kwarg in ruby DSL
2 parents dfa3e34 + a60329b commit 3e3ba2a

File tree

5 files changed

+63
-77
lines changed

5 files changed

+63
-77
lines changed

bundler/lib/bundler/definition.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -487,12 +487,6 @@ def validate_ruby!
487487
"Your Ruby version is #{actual}, but your Gemfile specified #{expected}"
488488
when :engine_version
489489
"Your #{Bundler::RubyVersion.system.engine} version is #{actual}, but your Gemfile specified #{ruby_version.engine} #{expected}"
490-
when :patchlevel
491-
if !expected.is_a?(String)
492-
"The Ruby patchlevel in your Gemfile must be a string"
493-
else
494-
"Your Ruby patchlevel is #{actual}, but your Gemfile specified #{expected}"
495-
end
496490
end
497491

498492
raise RubyVersionMismatch, msg

bundler/lib/bundler/ruby_version.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ def diff(other)
9696
[:version, versions_string(versions), versions_string(other.versions)]
9797
elsif @input_engine && !matches?(engine_versions, other.engine_gem_version)
9898
[:engine_version, versions_string(engine_versions), versions_string(other.engine_versions)]
99-
elsif patchlevel && (!patchlevel.is_a?(String) || !other.patchlevel.is_a?(String) || !matches?(patchlevel, other.patchlevel))
100-
[:patchlevel, patchlevel, other.patchlevel]
10199
end
102100
end
103101

spec/bundler/ruby_version_spec.rb

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
end
138138
end
139139

140-
context "the versions, pathlevels, engines, and engine_versions match" do
140+
shared_examples_for "the versions, engines, and engine_versions match" do
141141
it "should return true" do
142142
expect(subject).to eq(other_ruby_version)
143143
end
@@ -149,6 +149,12 @@
149149
it_behaves_like "two ruby versions are not equal"
150150
end
151151

152+
context "the patchlevels do not match" do
153+
let(:other_patchlevel) { "21" }
154+
155+
it_behaves_like "the versions, engines, and engine_versions match"
156+
end
157+
152158
context "the engines do not match" do
153159
let(:other_engine) { "ruby" }
154160

@@ -222,9 +228,9 @@
222228
end
223229
end
224230

225-
shared_examples_for "there is a difference in the patchlevels" do
226-
it "should return a tuple with :patchlevel and the two different patchlevels" do
227-
expect(ruby_version.diff(other_ruby_version)).to eq([:patchlevel, patchlevel, other_patchlevel])
231+
shared_examples_for "even there is a difference in the patchlevels" do
232+
it "should return nil" do
233+
expect(ruby_version.diff(other_ruby_version)).to be_nil
228234
end
229235
end
230236

@@ -281,10 +287,10 @@
281287
it_behaves_like "there is a difference in the engine versions"
282288
end
283289

284-
context "detects patchlevel discrepancies last" do
290+
context "ignores patchlevel discrepancies last" do
285291
let(:other_patchlevel) { "643" }
286292

287-
it_behaves_like "there is a difference in the patchlevels"
293+
it_behaves_like "even there is a difference in the patchlevels"
288294
end
289295

290296
context "successfully matches gem requirements" do
@@ -349,7 +355,7 @@
349355
let(:other_engine) { "ruby" }
350356
let(:other_engine_version) { "2.0.5" }
351357

352-
it_behaves_like "there is a difference in the patchlevels"
358+
it_behaves_like "even there is a difference in the patchlevels"
353359
end
354360

355361
context "successfully detects bad gem requirements with engine versions" do
@@ -383,7 +389,7 @@
383389
context "and comparing with a patchlevel that is not -1" do
384390
let(:other_patchlevel) { "642" }
385391

386-
it_behaves_like "there is a difference in the patchlevels"
392+
it_behaves_like "even there is a difference in the patchlevels"
387393
end
388394
end
389395
end

spec/commands/platform_spec.rb

Lines changed: 47 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,9 @@ def should_be_engine_version_incorrect
302302
expect(err).to be_include("Your #{local_ruby_engine} version is #{local_engine_version}, but your Gemfile specified #{local_ruby_engine} #{not_local_engine_version}")
303303
end
304304

305-
def should_be_patchlevel_incorrect
306-
expect(exitstatus).to eq(18)
307-
expect(err).to be_include("Your Ruby patchlevel is #{RUBY_PATCHLEVEL}, but your Gemfile specified #{not_local_patchlevel}")
305+
def should_ignore_patchlevel
306+
expect(exitstatus).to eq(0)
307+
expect(err).to eq("")
308308
end
309309

310310
def should_be_patchlevel_fixnum
@@ -382,16 +382,16 @@ def should_be_patchlevel_fixnum
382382
should_be_engine_version_incorrect
383383
end
384384

385-
it "doesn't install when patchlevel doesn't match" do
385+
it "does install even when patchlevel doesn't match" do
386386
install_gemfile <<-G, raise_on_error: false
387387
source "https://gem.repo1"
388388
gem "myrack"
389389
390390
#{patchlevel_incorrect}
391391
G
392392

393-
expect(bundled_app_lock).not_to exist
394-
should_be_patchlevel_incorrect
393+
expect(bundled_app_lock).to exist
394+
should_ignore_patchlevel
395395
end
396396
end
397397

@@ -481,7 +481,7 @@ def should_be_patchlevel_fixnum
481481
should_be_engine_version_incorrect
482482
end
483483

484-
it "fails when patchlevel doesn't match" do
484+
it "checks fine even when patchlevel doesn't match" do
485485
install_gemfile <<-G
486486
source "https://gem.repo1"
487487
gem "myrack"
@@ -494,8 +494,8 @@ def should_be_patchlevel_fixnum
494494
#{patchlevel_incorrect}
495495
G
496496

497-
bundle :check, raise_on_error: false
498-
should_be_patchlevel_incorrect
497+
bundle :check
498+
should_ignore_patchlevel
499499
end
500500
end
501501

@@ -598,19 +598,20 @@ def should_be_patchlevel_fixnum
598598
should_be_engine_version_incorrect
599599
end
600600

601-
it "fails when patchlevel doesn't match" do
601+
it "updates fine even when patchlevel doesn't match" do
602602
gemfile <<-G
603-
source "https://gem.repo1"
604-
gem "myrack"
603+
source "https://gem.repo2"
604+
gem "activesupport"
605605
606606
#{patchlevel_incorrect}
607607
G
608608
update_repo2 do
609609
build_gem "activesupport", "3.0"
610610
end
611611

612-
bundle :update, all: true, raise_on_error: false
613-
should_be_patchlevel_incorrect
612+
bundle :update, all: true
613+
should_ignore_patchlevel
614+
expect(the_bundle).to include_gems "activesupport 3.0"
614615
end
615616
end
616617

@@ -682,19 +683,17 @@ def should_be_patchlevel_fixnum
682683
should_be_engine_version_incorrect
683684
end
684685

685-
it "fails when patchlevel doesn't match" do
686+
it "prints path even when patchlevel doesn't match" do
686687
gemfile <<-G
687688
source "https://gem.repo1"
688-
gem "myrack"
689+
gem "rails"
689690
690691
#{patchlevel_incorrect}
691692
G
692-
update_repo2 do
693-
build_gem "activesupport", "3.0"
694-
end
695693

696-
bundle "show rails", raise_on_error: false
697-
should_be_patchlevel_incorrect
694+
bundle "show rails"
695+
should_ignore_patchlevel
696+
expect(out).to eq(default_bundle_path("gems", "rails-2.3.2").to_s)
698697
end
699698
end
700699

@@ -766,16 +765,17 @@ def should_be_patchlevel_fixnum
766765
should_be_engine_version_incorrect
767766
end
768767

769-
it "fails when patchlevel doesn't match" do
768+
it "copies the .gem file to vendor/cache even when patchlevel doesn't match" do
770769
gemfile <<-G
771770
source "https://gem.repo1"
772771
gem "myrack"
773772
774773
#{patchlevel_incorrect}
775774
G
776775

777-
bundle :cache, raise_on_error: false
778-
should_be_patchlevel_incorrect
776+
bundle :cache
777+
should_ignore_patchlevel
778+
expect(bundled_app("vendor/cache/myrack-1.0.0.gem")).to exist
779779
end
780780
end
781781

@@ -847,16 +847,17 @@ def should_be_patchlevel_fixnum
847847
should_be_engine_version_incorrect
848848
end
849849

850-
it "fails when patchlevel doesn't match" do
850+
it "copies the .gem file to vendor/cache even when patchlevel doesn't match" do
851851
gemfile <<-G
852852
source "https://gem.repo1"
853853
gem "myrack"
854854
855855
#{patchlevel_incorrect}
856856
G
857857

858-
bundle :cache, raise_on_error: false
859-
should_be_patchlevel_incorrect
858+
bundle :cache
859+
should_ignore_patchlevel
860+
expect(bundled_app("vendor/cache/myrack-1.0.0.gem")).to exist
860861
end
861862
end
862863

@@ -926,16 +927,17 @@ def should_be_patchlevel_fixnum
926927
should_be_engine_version_incorrect
927928
end
928929

929-
it "fails when patchlevel doesn't match" do
930+
it "activates the correct gem even when patchlevel doesn't match" do
930931
gemfile <<-G
931932
source "https://gem.repo1"
932933
gem "myrack"
933934
934935
#{patchlevel_incorrect}
935936
G
936937

937-
bundle "exec myrackup", raise_on_error: false
938-
should_be_patchlevel_incorrect
938+
bundle "exec myrackup"
939+
should_ignore_patchlevel
940+
expect(out).to include("1.0.0")
939941
end
940942
end
941943

@@ -995,11 +997,15 @@ def should_be_patchlevel_fixnum
995997
should_be_engine_version_incorrect
996998
end
997999

998-
it "fails when patchlevel doesn't match" do
1000+
it "starts IRB with the default group loaded even when patchlevel doesn't match", :readline do
9991001
gemfile gemfile + "\n\n#{patchlevel_incorrect}\n"
10001002

1001-
bundle "console", raise_on_error: false
1002-
should_be_patchlevel_incorrect
1003+
bundle "console" do |input, _, _|
1004+
input.puts("puts MYRACK")
1005+
input.puts("exit")
1006+
end
1007+
should_ignore_patchlevel
1008+
expect(out).to include("0.9.1")
10031009
end
10041010
end
10051011

@@ -1095,7 +1101,7 @@ def should_be_patchlevel_fixnum
10951101
should_be_engine_version_incorrect
10961102
end
10971103

1098-
it "fails when patchlevel doesn't match" do
1104+
it "makes a Gemfile.lock even when patchlevel doesn't match" do
10991105
install_gemfile <<-G, raise_on_error: false
11001106
source "https://gem.repo1"
11011107
gem "yard"
@@ -1106,10 +1112,10 @@ def should_be_patchlevel_fixnum
11061112

11071113
FileUtils.rm(bundled_app_lock)
11081114

1109-
ruby "require 'bundler/setup'", env: { "BUNDLER_VERSION" => Bundler::VERSION }, raise_on_error: false
1115+
ruby "require 'bundler/setup'", env: { "BUNDLER_VERSION" => Bundler::VERSION }
11101116

1111-
expect(bundled_app_lock).not_to exist
1112-
should_be_patchlevel_incorrect
1117+
should_ignore_patchlevel
1118+
expect(bundled_app_lock).to exist
11131119
end
11141120
end
11151121

@@ -1231,7 +1237,7 @@ def should_be_patchlevel_fixnum
12311237
should_be_engine_version_incorrect
12321238
end
12331239

1234-
it "fails when the patchlevel doesn't match", :jruby_only do
1240+
it "reports outdated gems even when patchlevel doesn't match" do
12351241
update_repo2 do
12361242
build_gem "activesupport", "3.0"
12371243
update_git "foo", path: lib_path("foo")
@@ -1246,25 +1252,9 @@ def should_be_patchlevel_fixnum
12461252
G
12471253

12481254
bundle "outdated", raise_on_error: false
1249-
should_be_patchlevel_incorrect
1250-
end
1251-
1252-
it "fails when the patchlevel is a fixnum", :jruby_only do
1253-
update_repo2 do
1254-
build_gem "activesupport", "3.0"
1255-
update_git "foo", path: lib_path("foo")
1256-
end
1257-
1258-
gemfile <<-G
1259-
source "https://gem.repo2"
1260-
gem "activesupport", "2.3.5"
1261-
gem "foo", :git => "#{lib_path("foo")}"
1262-
1263-
#{patchlevel_fixnum}
1264-
G
1265-
1266-
bundle "outdated", raise_on_error: false
1267-
should_be_patchlevel_fixnum
1255+
expect(err).not_to include("patchlevel")
1256+
expect(out).to include("activesupport")
1257+
expect(out).to include("foo")
12681258
end
12691259
end
12701260
end

spec/install/gemspecs_spec.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ module Persistent💎
122122
expect(the_bundle).to include_gems "foo 1.0"
123123
end
124124

125-
it "fails and complains about patchlevel on patchlevel mismatch",
125+
it "installs gems ignoring the mismatch even when patchlevel is mismatch",
126126
if: RUBY_PATCHLEVEL >= 0 do
127127
patchlevel = RUBY_PATCHLEVEL.to_i + 1
128128
build_lib("foo", path: bundled_app) do |s|
@@ -135,9 +135,7 @@ module Persistent💎
135135
gemspec
136136
G
137137

138-
expect(err).to include("Ruby patchlevel")
139-
expect(err).to include("but your Gemfile specified")
140-
expect(exitstatus).to eq(18)
138+
expect(the_bundle).to include_gems "foo 1.0"
141139
end
142140

143141
it "fails and complains about version on version mismatch" do

0 commit comments

Comments
 (0)