[rubygems/rubygems] Support ruby file: ".tool-versions"
in Gemfile
(https://github.com/rubygems/rubygems/pull/6898) Supports .tool-versions (ASDF) by checking for a line starting with "ruby" before falling back to reading the entire file, as in .ruby-version. https://github.com/rubygems/rubygems/commit/6c0a3e793a
This commit is contained in:
parent
95e29b0423
commit
b9ef819116
@ -98,6 +98,17 @@ ruby file: "\.ruby\-version"
|
|||||||
.
|
.
|
||||||
.IP "" 0
|
.IP "" 0
|
||||||
.
|
.
|
||||||
|
.P
|
||||||
|
The version file should conform to any of the following formats:
|
||||||
|
.
|
||||||
|
.IP "\(bu" 4
|
||||||
|
\fB3\.1\.2\fR (\.ruby\-version)
|
||||||
|
.
|
||||||
|
.IP "\(bu" 4
|
||||||
|
\fBruby 3\.1\.2\fR (\.tool\-versions, read: https://asdf\-vm\.com/manage/configuration\.html#tool\-versions)
|
||||||
|
.
|
||||||
|
.IP "" 0
|
||||||
|
.
|
||||||
.SS "ENGINE"
|
.SS "ENGINE"
|
||||||
Each application \fImay\fR specify a Ruby engine\. If an engine is specified, an engine version \fImust\fR also be specified\.
|
Each application \fImay\fR specify a Ruby engine\. If an engine is specified, an engine version \fImust\fR also be specified\.
|
||||||
.
|
.
|
||||||
|
@ -74,6 +74,11 @@ you can use the `file` option instead.
|
|||||||
|
|
||||||
ruby file: ".ruby-version"
|
ruby file: ".ruby-version"
|
||||||
|
|
||||||
|
The version file should conform to any of the following formats:
|
||||||
|
|
||||||
|
- `3.1.2` (.ruby-version)
|
||||||
|
- `ruby 3.1.2` (.tool-versions, read: https://asdf-vm.com/manage/configuration.html#tool-versions)
|
||||||
|
|
||||||
### ENGINE
|
### ENGINE
|
||||||
|
|
||||||
Each application _may_ specify a Ruby engine. If an engine is specified, an
|
Each application _may_ specify a Ruby engine. If an engine is specified, an
|
||||||
|
@ -11,7 +11,12 @@ module Bundler
|
|||||||
|
|
||||||
if options[:file]
|
if options[:file]
|
||||||
raise GemfileError, "Cannot specify version when using the file option" if ruby_version.any?
|
raise GemfileError, "Cannot specify version when using the file option" if ruby_version.any?
|
||||||
ruby_version << Bundler.read_file(Bundler.root.join(options[:file])).strip
|
file_content = Bundler.read_file(Bundler.root.join(options[:file]))
|
||||||
|
if /^ruby\s+(.*)$/.match(file_content) # match .tool-versions files
|
||||||
|
ruby_version << $1.split("#", 2).first.strip # remove trailing comment
|
||||||
|
else
|
||||||
|
ruby_version << file_content.strip
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if options[:engine] == "ruby" && options[:engine_version] &&
|
if options[:engine] == "ruby" && options[:engine_version] &&
|
||||||
|
@ -121,5 +121,31 @@ RSpec.describe Bundler::RubyDsl do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "with a (.tool-versions) file option" do
|
||||||
|
let(:options) { { :file => "foo" } }
|
||||||
|
let(:version) { "3.2.2" }
|
||||||
|
let(:ruby_version) { "3.2.2" }
|
||||||
|
let(:ruby_version_arg) { nil }
|
||||||
|
let(:engine_version) { version }
|
||||||
|
let(:patchlevel) { nil }
|
||||||
|
let(:engine) { "ruby" }
|
||||||
|
let(:project_root) { Pathname.new("/path/to/project") }
|
||||||
|
|
||||||
|
before do
|
||||||
|
allow(Bundler).to receive(:read_file).with(project_root.join("foo")).and_return("nodejs 18.16.0\nruby #{version} # This is a comment\npnpm 8.6.12\n")
|
||||||
|
allow(Bundler).to receive(:root).and_return(Pathname.new("/path/to/project"))
|
||||||
|
end
|
||||||
|
|
||||||
|
it_behaves_like "it stores the ruby version"
|
||||||
|
|
||||||
|
context "and a version" do
|
||||||
|
let(:ruby_version_arg) { "2.0.0" }
|
||||||
|
|
||||||
|
it "raises an error" do
|
||||||
|
expect { subject }.to raise_error(Bundler::GemfileError, "Cannot specify version when using the file option")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user