File tree Expand file tree Collapse file tree 4 files changed +48
-1
lines changed
Expand file tree Collapse file tree 4 files changed +48
-1
lines changed Original file line number Diff line number Diff line change @@ -98,6 +98,17 @@ ruby file: "\.ruby\-version"
9898.
9999.IP " " 0
100100.
101+ .P
102+ The version file should conform to any of the following formats:
103+ .
104+ .IP " \(bu " 4
105+ \fB 3 \. 1 \. 2 \fR (\. ruby\- version)
106+ .
107+ .IP " \(bu " 4
108+ \fB ruby 3 \. 1 \. 2 \fR (\. tool\- versions, read: https://asdf\- vm\. com/manage/configuration\. html#tool\- versions)
109+ .
110+ .IP " " 0
111+ .
101112.SS "ENGINE"
102113Each application \fI may \fR specify a Ruby engine\. If an engine is specified, an engine version \fI must \fR also be specified\.
103114.
Original file line number Diff line number Diff line change @@ -74,6 +74,11 @@ you can use the `file` option instead.
7474
7575 ruby file: ".ruby-version"
7676
77+ The version file should conform to any of the following formats:
78+
79+ - ` 3.1.2 ` (.ruby-version)
80+ - ` ruby 3.1.2 ` (.tool-versions, read: https://asdf-vm.com/manage/configuration.html#tool-versions )
81+
7782### ENGINE
7883
7984Each application _ may_ specify a Ruby engine. If an engine is specified, an
Original file line number Diff line number Diff line change @@ -11,7 +11,12 @@ def ruby(*ruby_version)
1111
1212 if options [ :file ]
1313 raise GemfileError , "Cannot specify version when using the file option" if ruby_version . any?
14- ruby_version << Bundler . read_file ( Bundler . root . join ( options [ :file ] ) ) . strip
14+ file_content = Bundler . read_file ( Bundler . root . join ( options [ :file ] ) )
15+ if /^ruby\s +(.*)$/ . match ( file_content ) # match .tool-versions files
16+ ruby_version << $1. split ( "#" , 2 ) . first . strip # remove trailing comment
17+ else
18+ ruby_version << file_content . strip
19+ end
1520 end
1621
1722 if options [ :engine ] == "ruby" && options [ :engine_version ] &&
Original file line number Diff line number Diff line change @@ -121,5 +121,31 @@ class MockDSL
121121 end
122122 end
123123 end
124+
125+ context "with a (.tool-versions) file option" do
126+ let ( :options ) { { :file => "foo" } }
127+ let ( :version ) { "3.2.2" }
128+ let ( :ruby_version ) { "3.2.2" }
129+ let ( :ruby_version_arg ) { nil }
130+ let ( :engine_version ) { version }
131+ let ( :patchlevel ) { nil }
132+ let ( :engine ) { "ruby" }
133+ let ( :project_root ) { Pathname . new ( "/path/to/project" ) }
134+
135+ before do
136+ allow ( Bundler ) . to receive ( :read_file ) . with ( project_root . join ( "foo" ) ) . and_return ( "nodejs 18.16.0\n ruby #{ version } # This is a comment\n pnpm 8.6.12\n " )
137+ allow ( Bundler ) . to receive ( :root ) . and_return ( Pathname . new ( "/path/to/project" ) )
138+ end
139+
140+ it_behaves_like "it stores the ruby version"
141+
142+ context "and a version" do
143+ let ( :ruby_version_arg ) { "2.0.0" }
144+
145+ it "raises an error" do
146+ expect { subject } . to raise_error ( Bundler ::GemfileError , "Cannot specify version when using the file option" )
147+ end
148+ end
149+ end
124150 end
125151end
You can’t perform that action at this time.
0 commit comments