-
Notifications
You must be signed in to change notification settings - Fork 942
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Properly parse .ruby-version file (#9012)
In ccb965e, I used Bundler::RubyVersion.from_string, but this method is used to parse the Ruby version present in the Gemfile, of the form `ruby 3.3.0p0`, while we want to parse `3.3.0` or `ruby-3.3.0`. The code is lifted from `Bundler::RubyDsl#normalize_ruby_file`, so it only supports either `ruby-{version}` or `ruby {version}` or a plain version. That's what `ruby file: ".ruby-version"` supports. Co-authored-by: Jenny Shen <jenny.shen@shopify.com>
- Loading branch information
1 parent
5c637ec
commit 935ab99
Showing
5 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# typed: false | ||
# frozen_string_literal: true | ||
|
||
require "native_spec_helper" | ||
require "shared_contexts" | ||
|
||
RSpec.describe BundlerDefinitionRubyVersionPatch do | ||
include_context "in a temporary bundler directory" | ||
include_context "stub rubygems compact index" | ||
|
||
let(:project_name) { "ruby_version_implied" } | ||
before do | ||
@ui = Bundler.ui | ||
Bundler.ui = Bundler::UI::Silent.new | ||
end | ||
after { Bundler.ui = @ui } | ||
|
||
it "updates to the most recent version" do | ||
in_tmp_folder do | ||
File.delete(".ruby-version") | ||
definition = Bundler::Definition.build("Gemfile", "Gemfile.lock", gems: ["statesman"]) | ||
definition.resolve_remotely! | ||
specs = definition.resolve["statesman"] | ||
expect(specs.size).to eq(1) | ||
spec = specs.first | ||
expect(spec.version).to eq("7.2.0") | ||
end | ||
end | ||
|
||
it "doesn't update to a version that is not compatible with the Ruby version implied by .ruby-version" do | ||
in_tmp_folder do | ||
definition = Bundler::Definition.build("Gemfile", "Gemfile.lock", gems: ["statesman"]) | ||
definition.resolve_remotely! | ||
specs = definition.resolve["statesman"] | ||
expect(specs.size).to eq(1) | ||
spec = specs.first | ||
expect(spec.version).to eq("2.0.1") | ||
end | ||
end | ||
end |
1 change: 1 addition & 0 deletions
1
bundler/spec/fixtures/projects/bundler2/ruby_version_implied/.ruby-version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
2.1.10 |
4 changes: 4 additions & 0 deletions
4
bundler/spec/fixtures/projects/bundler2/ruby_version_implied/Gemfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source "https://rubygems.org" | ||
|
||
gem "business" | ||
gem "statesman" |
15 changes: 15 additions & 0 deletions
15
bundler/spec/fixtures/projects/bundler2/ruby_version_implied/Gemfile.lock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
business (1.12.0) | ||
statesman (2.0.1) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
business | ||
statesman | ||
|
||
BUNDLED WITH | ||
2.5.3 |