From f208f78bdfc65341cb6547a378ff616b1928e48a Mon Sep 17 00:00:00 2001 From: Harshal Bhakta Date: Fri, 29 Sep 2023 15:42:16 +0530 Subject: [rubygems/rubygems] Support Ruby's preview version format (Ex: 3.3.0-preview2) in Gemfile https://github.com/rubygems/rubygems/commit/4c1a0511b6 --- lib/bundler/ruby_version.rb | 9 ++++++++- spec/bundler/bundler/ruby_dsl_spec.rb | 9 +++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/bundler/ruby_version.rb b/lib/bundler/ruby_version.rb index b5396abb6e..52868b5fb8 100644 --- a/lib/bundler/ruby_version.rb +++ b/lib/bundler/ruby_version.rb @@ -23,7 +23,7 @@ module Bundler # specified must match the version. @versions = Array(versions).map do |v| - op, v = Gem::Requirement.parse(v) + op, v = Gem::Requirement.parse(normalize_version(v)) op == "=" ? v.to_s : "#{op} #{v}" end @@ -112,6 +112,13 @@ module Bundler private + # Ruby's official preview version format uses a `-`: Example: 3.3.0-preview2 + # However, RubyGems recognizes preview version format with a `.`: Example: 3.3.0.preview2 + # Returns version string after replacing `-` with `.` + def normalize_version(version) + version.tr("-", ".") + end + def matches?(requirements, version) # Handles RUBY_PATCHLEVEL of -1 for instances like ruby-head return requirements == version if requirements.to_s == "-1" || version.to_s == "-1" diff --git a/spec/bundler/bundler/ruby_dsl_spec.rb b/spec/bundler/bundler/ruby_dsl_spec.rb index 6b00161571..c91804d96a 100644 --- a/spec/bundler/bundler/ruby_dsl_spec.rb +++ b/spec/bundler/bundler/ruby_dsl_spec.rb @@ -65,6 +65,15 @@ RSpec.describe Bundler::RubyDsl do it_behaves_like "it stores the ruby version" end + context "with a preview version" do + let(:ruby_version) { "3.3.0-preview2" } + + it "stores the version" do + expect(subject.versions).to eq(Array("3.3.0.preview2")) + expect(subject.gem_version.version).to eq("3.3.0.preview2") + end + end + context "with two requirements in the same string" do let(:ruby_version) { ">= 2.0.0, < 3.0" } it "raises an error" do -- cgit v1.2.3