diff options
author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2022-07-29 14:59:56 +0900 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2022-07-29 15:46:15 +0900 |
commit | bfd09b1116bcc747bab922b23c7322e4ec66c2c2 (patch) | |
tree | 38c52d7a1f5790f8902eb585267e5da5f9e76399 | |
parent | f29f1d22c3d62b72b8943eefb384cd7a52251ea1 (diff) | |
download | ruby-bfd09b1116bcc747bab922b23c7322e4ec66c2c2.tar.gz |
Merge rubygems master from https://github.com/rubygems/rubygems/commit/446cc57a7ccdf1924deb291be9571219e7ba8523
26 files changed, 174 insertions, 58 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index e1c284130b..e9ef47f9ba 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -218,6 +218,8 @@ module Bundler "Specify the number of jobs to run in parallel" method_option "local", :type => :boolean, :banner => "Do not attempt to fetch gems remotely and use the gem cache instead" + method_option "prefer-local", :type => :boolean, :banner => + "Only attempt to fetch gems remotely if not present locally, even if newer versions are available remotely" method_option "no-cache", :type => :boolean, :banner => "Don't update the existing gem cache." method_option "redownload", :type => :boolean, :aliases => "--force", :banner => diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 4cb829470a..3e93b45171 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -70,6 +70,7 @@ module Bundler @unlock = unlock @optional_groups = optional_groups @remote = false + @prefer_local = false @specs = nil @ruby_version = ruby_version @gemfiles = gemfiles @@ -170,6 +171,13 @@ module Bundler resolve end + def resolve_prefering_local! + @prefer_local = true + @remote = true + sources.remote! + resolve + end + def resolve_with_cache! sources.cached! resolve @@ -528,6 +536,19 @@ module Bundler @remote && sources.non_global_rubygems_sources.all?(&:dependency_api_available?) && !sources.aggregate_global_source? end + def pin_locally_available_names(source_requirements) + source_requirements.each_with_object({}) do |(name, original_source), new_source_requirements| + local_source = original_source.dup + local_source.local_only! + + new_source_requirements[name] = if local_source.specs.search(name).any? + local_source + else + original_source + end + end + end + def current_ruby_platform_locked? return false unless generic_local_platform == Gem::Platform::RUBY return false if Bundler.settings[:force_ruby_platform] && !@platforms.include?(Gem::Platform::RUBY) @@ -765,7 +786,7 @@ module Bundler def metadata_dependencies @metadata_dependencies ||= [ - Dependency.new("Ruby\0", RubyVersion.system.gem_version), + Dependency.new("Ruby\0", Gem.ruby_version), Dependency.new("RubyGems\0", Gem::VERSION), ] end @@ -792,7 +813,9 @@ module Bundler # specs will be available later when the resolver knows where to # look for that gemspec (or its dependencies) source_requirements = if precompute_source_requirements_for_indirect_dependencies? - { :default => sources.default_source }.merge(source_map.all_requirements) + all_requirements = source_map.all_requirements + all_requirements = pin_locally_available_names(all_requirements) if @prefer_local + { :default => sources.default_source }.merge(all_requirements) else { :default => Source::RubygemsAggregate.new(sources, source_map) }.merge(source_map.direct_requirements) end @@ -806,7 +829,9 @@ module Bundler end def requested_groups - groups - Bundler.settings[:without] - @optional_groups + Bundler.settings[:with] + values = groups - Bundler.settings[:without] - @optional_groups + Bundler.settings[:with] + values &= Bundler.settings[:only] unless Bundler.settings[:only].empty? + values end def lockfiles_equal?(current, proposed, preserve_unknown_sections) diff --git a/lib/bundler/installer.rb b/lib/bundler/installer.rb index f195d36600..b7b0e36dfd 100644 --- a/lib/bundler/installer.rb +++ b/lib/bundler/installer.rb @@ -268,7 +268,14 @@ module Bundler return false if @definition.nothing_changed? && !@definition.missing_specs? end - options["local"] ? @definition.resolve_with_cache! : @definition.resolve_remotely! + if options["local"] + @definition.resolve_with_cache! + elsif options["prefer-local"] + @definition.resolve_prefering_local! + else + @definition.resolve_remotely! + end + true end diff --git a/lib/bundler/man/bundle-config.1 b/lib/bundler/man/bundle-config.1 index 76b444d8c6..b5cee57f29 100644 --- a/lib/bundler/man/bundle-config.1 +++ b/lib/bundler/man/bundle-config.1 @@ -74,6 +74,10 @@ Creates a directory (defaults to \fB~/bin\fR) and place any executables from the In deployment mode, Bundler will \'roll\-out\' the bundle for \fBproduction\fR use\. Please check carefully if you want to have this option enabled in \fBdevelopment\fR or \fBtest\fR environments\. . .TP +\fBonly\fR +A space\-separated list of groups to install only gems of the specified groups\. +. +.TP \fBpath\fR The location to install the specified gems to\. This defaults to Rubygems\' setting\. Bundler shares this location with Rubygems, \fBgem install \.\.\.\fR will have gem installed there, too\. Therefore, gems installed without a \fB\-\-path \.\.\.\fR setting will show up by calling \fBgem list\fR\. Accordingly, gems installed to other locations will not get listed\. . @@ -223,6 +227,9 @@ The following is a list of all configuration keys and their purpose\. You can le \fBno_prune\fR (\fBBUNDLE_NO_PRUNE\fR): Whether Bundler should leave outdated gems unpruned when caching\. . .IP "\(bu" 4 +\fBonly\fR (\fBBUNDLE_ONLY\fR): A space\-separated list of groups to install only gems of the specified groups\. +. +.IP "\(bu" 4 \fBpath\fR (\fBBUNDLE_PATH\fR): The location on disk where all gems in your bundle will be located regardless of \fB$GEM_HOME\fR or \fB$GEM_PATH\fR values\. Bundle gems not found in this location will be installed by \fBbundle install\fR\. Defaults to \fBGem\.dir\fR\. When \-\-deployment is used, defaults to vendor/bundle\. . .IP "\(bu" 4 diff --git a/lib/bundler/man/bundle-config.1.ronn b/lib/bundler/man/bundle-config.1.ronn index 8a636641c0..e2af773141 100644 --- a/lib/bundler/man/bundle-config.1.ronn +++ b/lib/bundler/man/bundle-config.1.ronn @@ -74,6 +74,9 @@ The options that can be configured are: `production` use. Please check carefully if you want to have this option enabled in `development` or `test` environments. +* `only`: + A space-separated list of groups to install only gems of the specified groups. + * `path`: The location to install the specified gems to. This defaults to Rubygems' setting. Bundler shares this location with Rubygems, `gem install ...` will @@ -218,6 +221,8 @@ learn more about their operation in [bundle install(1)](bundle-install.1.html). Whether `bundle package` should skip installing gems. * `no_prune` (`BUNDLE_NO_PRUNE`): Whether Bundler should leave outdated gems unpruned when caching. +* `only` (`BUNDLE_ONLY`): + A space-separated list of groups to install only gems of the specified groups. * `path` (`BUNDLE_PATH`): The location on disk where all gems in your bundle will be located regardless of `$GEM_HOME` or `$GEM_PATH` values. Bundle gems not found in this location diff --git a/lib/bundler/man/bundle-inject.1 b/lib/bundler/man/bundle-inject.1 index 0f6627d9a3..53f2eaae0a 100644 --- a/lib/bundler/man/bundle-inject.1 +++ b/lib/bundler/man/bundle-inject.1 @@ -30,4 +30,7 @@ bundle inject \'rack\' \'> 0\' .IP "" 0 . .P -This will inject the \'rack\' gem with a version greater than 0 in your [\fBGemfile(5)\fR][Gemfile(5)] and Gemfile\.lock +This will inject the \'rack\' gem with a version greater than 0 in your [\fBGemfile(5)\fR][Gemfile(5)] and Gemfile\.lock\. +. +.P +The \fBbundle inject\fR command was deprecated in Bundler 2\.1 and will be removed in Bundler 3\.0\. diff --git a/lib/bundler/man/bundle-inject.1.ronn b/lib/bundler/man/bundle-inject.1.ronn index f454341896..95704eddad 100644 --- a/lib/bundler/man/bundle-inject.1.ronn +++ b/lib/bundler/man/bundle-inject.1.ronn @@ -19,4 +19,6 @@ Example: bundle inject 'rack' '> 0' This will inject the 'rack' gem with a version greater than 0 in your -[`Gemfile(5)`][Gemfile(5)] and Gemfile.lock +[`Gemfile(5)`][Gemfile(5)] and Gemfile.lock. + +The `bundle inject` command was deprecated in Bundler 2.1 and will be removed in Bundler 3.0. diff --git a/lib/bundler/man/bundle-install.1 b/lib/bundler/man/bundle-install.1 index c742efd142..8e94fe2437 100644 --- a/lib/bundler/man/bundle-install.1 +++ b/lib/bundler/man/bundle-install.1 @@ -70,6 +70,10 @@ The maximum number of parallel download and install jobs\. The default is the nu Do not attempt to connect to \fBrubygems\.org\fR\. Instead, Bundler will use the gems already present in Rubygems\' cache or in \fBvendor/cache\fR\. Note that if an appropriate platform\-specific gem exists on \fBrubygems\.org\fR it will not be found\. . .TP +\fB\-\-prefer\-local\fR +Force using locally installed gems, or gems already present in Rubygems\' cache or in \fBvendor/cache\fR, when resolving, even if newer versions are available remotely\. Only attempt to connect to \fBrubygems\.org\fR for gems that are not present locally\. +. +.TP \fB\-\-no\-cache\fR Do not update the cache in \fBvendor/cache\fR with the newly bundled gems\. This does not remove any gems in the cache but keeps the newly bundled gems from being cached during the install\. . diff --git a/lib/bundler/man/bundle-install.1.ronn b/lib/bundler/man/bundle-install.1.ronn index bec05187f3..47200ac2d5 100644 --- a/lib/bundler/man/bundle-install.1.ronn +++ b/lib/bundler/man/bundle-install.1.ronn @@ -109,6 +109,12 @@ automatically and that requires `bundler` to silently remember them. Since appropriate platform-specific gem exists on `rubygems.org` it will not be found. +* `--prefer-local`: + Force using locally installed gems, or gems already present in Rubygems' cache + or in `vendor/cache`, when resolving, even if newer versions are available + remotely. Only attempt to connect to `rubygems.org` for gems that are not + present locally. + * `--no-cache`: Do not update the cache in `vendor/cache` with the newly bundled gems. This does not remove any gems in the cache but keeps the newly bundled gems from diff --git a/lib/bundler/man/bundle.1 b/lib/bundler/man/bundle.1 index c80ef51992..efc4d7e93f 100644 --- a/lib/bundler/man/bundle.1 +++ b/lib/bundler/man/bundle.1 @@ -81,7 +81,7 @@ Show the source location of a particular gem in the bundle Show all of the outdated gems in the current bundle . .TP -\fBbundle console(1)\fR +\fBbundle console(1)\fR (deprecated) Start an IRB session in the current bundle . .TP @@ -129,5 +129,8 @@ These commands are obsolete and should no longer be used: .IP "\(bu" 4 \fBbundle cache(1)\fR . +.IP "\(bu" 4 +\fBbundle inject(1)\fR +. .IP "" 0 diff --git a/lib/bundler/man/bundle.1.ronn b/lib/bundler/man/bundle.1.ronn index 86d771f024..52a00d43ee 100644 --- a/lib/bundler/man/bundle.1.ronn +++ b/lib/bundler/man/bundle.1.ronn @@ -67,7 +67,7 @@ We divide `bundle` subcommands into primary commands and utilities: * [`bundle outdated(1)`](bundle-outdated.1.html): Show all of the outdated gems in the current bundle -* `bundle console(1)`: +* `bundle console(1)` (deprecated): Start an IRB session in the current bundle * [`bundle open(1)`](bundle-open.1.html): @@ -108,3 +108,4 @@ and execute it, passing down any extra arguments to it. These commands are obsolete and should no longer be used: * `bundle cache(1)` +* `bundle inject(1)` diff --git a/lib/bundler/ruby_version.rb b/lib/bundler/ruby_version.rb index 3f51cf4528..9161c6afde 100644 --- a/lib/bundler/ruby_version.rb +++ b/lib/bundler/ruby_version.rb @@ -32,12 +32,12 @@ module Bundler @engine = engine && engine.to_s || "ruby" @engine_versions = (engine_version && Array(engine_version)) || @versions @engine_gem_version = Gem::Requirement.create(@engine_versions.first).requirements.first.last - @patchlevel = patchlevel + @patchlevel = patchlevel || (@gem_version.prerelease? ? "-1" : nil) end def to_s(versions = self.versions) output = String.new("ruby #{versions_string(versions)}") - output << "p#{patchlevel}" if patchlevel + output << "p#{patchlevel}" if patchlevel && patchlevel != "-1" output << " (#{engine} #{versions_string(engine_versions)})" unless engine == "ruby" output @@ -46,7 +46,7 @@ module Bundler # @private PATTERN = / ruby\s - ([\d.]+) # ruby version + (\d+\.\d+\.\d+(?:\.\S+)?) # ruby version (?:p(-?\d+))? # optional patchlevel (?:\s\((\S+)\s(.+)\))? # optional engine info /xo.freeze @@ -103,8 +103,8 @@ module Bundler def self.system ruby_engine = RUBY_ENGINE.dup - ruby_version = RUBY_VERSION.dup - ruby_engine_version = RUBY_ENGINE_VERSION.dup + ruby_version = Gem.ruby_version.to_s + ruby_engine_version = RUBY_ENGINE == "ruby" ? ruby_version : RUBY_ENGINE_VERSION.dup patchlevel = RUBY_PATCHLEVEL.to_s @ruby_version ||= RubyVersion.new(ruby_version, patchlevel, ruby_engine, ruby_engine_version) diff --git a/lib/bundler/rubygems_ext.rb b/lib/bundler/rubygems_ext.rb index a47692d1f2..e8e03fcf8f 100644 --- a/lib/bundler/rubygems_ext.rb +++ b/lib/bundler/rubygems_ext.rb @@ -17,6 +17,15 @@ require "rubygems/source" require_relative "match_platform" +# Cherry-pick fixes to `Gem.ruby_version` to be useful for modern Bundler +# versions and ignore patchlevels +# (https://github.com/rubygems/rubygems/pull/5472, +# https://github.com/rubygems/rubygems/pull/5486). May be removed once RubyGems +# 3.3.12 support is dropped. +unless Gem.ruby_version.to_s == RUBY_VERSION || RUBY_PATCHLEVEL == -1 + Gem.instance_variable_set(:@ruby_version, Gem::Version.new(RUBY_VERSION)) +end + module Gem class Specification include ::Bundler::MatchPlatform diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb index 398c66055a..cf5675274e 100644 --- a/lib/bundler/settings.rb +++ b/lib/bundler/settings.rb @@ -57,6 +57,7 @@ module Bundler ].freeze ARRAY_KEYS = %w[ + only with without ].freeze diff --git a/lib/bundler/source/metadata.rb b/lib/bundler/source/metadata.rb index 185fe70824..23531b8bd4 100644 --- a/lib/bundler/source/metadata.rb +++ b/lib/bundler/source/metadata.rb @@ -5,7 +5,7 @@ module Bundler class Metadata < Source def specs @specs ||= Index.build do |idx| - idx << Gem::Specification.new("Ruby\0", RubyVersion.system.gem_version) + idx << Gem::Specification.new("Ruby\0", Gem.ruby_version) idx << Gem::Specification.new("RubyGems\0", Gem::VERSION) do |s| s.required_rubygems_version = Gem::Requirement.default end diff --git a/spec/bundler/bundler/ruby_version_spec.rb b/spec/bundler/bundler/ruby_version_spec.rb index 3e3850031c..f1df12294d 100644 --- a/spec/bundler/bundler/ruby_version_spec.rb +++ b/spec/bundler/bundler/ruby_version_spec.rb @@ -427,9 +427,8 @@ RSpec.describe "Bundler::RubyVersion and its subclasses" do end describe "#version" do - it "should return a copy of the value of RUBY_VERSION" do - expect(subject.versions).to eq([RUBY_VERSION]) - expect(subject.versions.first).to_not be(RUBY_VERSION) + it "should return the value of Gem.ruby_version as a string" do + expect(subject.versions).to eq([Gem.ruby_version.to_s]) end end @@ -446,13 +445,12 @@ RSpec.describe "Bundler::RubyVersion and its subclasses" do describe "#engine_version" do context "engine is ruby" do before do - stub_const("RUBY_ENGINE_VERSION", "2.2.4") + allow(Gem).to receive(:ruby_version).and_return(Gem::Version.new("2.2.4")) stub_const("RUBY_ENGINE", "ruby") end - it "should return a copy of the value of RUBY_ENGINE_VERSION" do + it "should return the value of Gem.ruby_version as a string" do expect(bundler_system_ruby_version.engine_versions).to eq(["2.2.4"]) - expect(bundler_system_ruby_version.engine_versions.first).to_not be(RUBY_ENGINE_VERSION) end end diff --git a/spec/bundler/commands/install_spec.rb b/spec/bundler/commands/install_spec.rb index 57cff4e3b3..7bf36ee020 100644 --- a/spec/bundler/commands/install_spec.rb +++ b/spec/bundler/commands/install_spec.rb @@ -522,14 +522,14 @@ RSpec.describe "bundle install with gem sources" do ruby '~> 1.2' source "#{file_uri_for(gem_repo1)}" G - expect(err).to include("Your Ruby version is #{RUBY_VERSION}, but your Gemfile specified ~> 1.2") + expect(err).to include("Your Ruby version is #{Gem.ruby_version}, but your Gemfile specified ~> 1.2") end end context "and using a supported Ruby version" do before do install_gemfile <<-G - ruby '~> #{RUBY_VERSION}' + ruby '~> #{Gem.ruby_version}' source "#{file_uri_for(gem_repo1)}" G end @@ -555,7 +555,7 @@ RSpec.describe "bundle install with gem sources" do it "updates Gemfile.lock with updated yet still compatible ruby version" do install_gemfile <<-G - ruby '~> #{RUBY_VERSION[0..2]}' + ruby '~> #{current_ruby_minor}' source "#{file_uri_for(gem_repo1)}" G @@ -913,7 +913,7 @@ RSpec.describe "bundle install with gem sources" do gemfile <<-G source "https://gem.repo4" - ruby "#{RUBY_VERSION}" + ruby "#{Gem.ruby_version}" gem "loofah", "~> 2.12.0" G @@ -1000,6 +1000,50 @@ RSpec.describe "bundle install with gem sources" do end end + context "with only option" do + before do + bundle "config set only a:b" + end + + it "installs only gems of the specified groups" do + install_gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "rails" + gem "rack", group: :a + gem "rake", group: :b + gem "yard", group: :c + G + + expect(out).to include("Installing rack") + expect(out).to include("Installing rake") + expect(out).not_to include("Installing yard") + end + end + + context "with --prefer-local flag" do + before do + build_repo4 do + build_gem "foo", "1.0.1" + build_gem "foo", "1.0.0" + build_gem "bar", "1.0.0" + end + + system_gems "foo-1.0.0", :path => default_bundle_path, :gem_repo => gem_repo4 + end + + it "fetches remote sources only when not available locally" do + install_gemfile <<-G, :"prefer-local" => true, :verbose => true + source "#{file_uri_for(gem_repo4)}" + + gem "foo" + gem "bar" + G + + expect(out).to include("Using foo 1.0.0").and include("Fetching bar 1.0.0").and include("Installing bar 1.0.0") + expect(last_command).to be_success + end + end + context "with a symlinked configured as bundle path and a gem with symlinks" do before do symlinked_bundled_app = tmp("bundled_app-symlink") diff --git a/spec/bundler/commands/lock_spec.rb b/spec/bundler/commands/lock_spec.rb index b20a6ded43..b314169a98 100644 --- a/spec/bundler/commands/lock_spec.rb +++ b/spec/bundler/commands/lock_spec.rb @@ -541,11 +541,9 @@ RSpec.describe "bundle lock" do end it "respects lower bound ruby requirements" do - skip "this spec does not work with prereleases because their version is actually lower than their reported `RUBY_VERSION`" if RUBY_PATCHLEVEL == -1 - build_repo4 do build_gem "our_private_gem", "0.1.0" do |s| - s.required_ruby_version = ">= #{RUBY_VERSION}" + s.required_ruby_version = ">= #{Gem.ruby_version}" end end diff --git a/spec/bundler/commands/update_spec.rb b/spec/bundler/commands/update_spec.rb index d45a565475..8ca537ac10 100644 --- a/spec/bundler/commands/update_spec.rb +++ b/spec/bundler/commands/update_spec.rb @@ -983,7 +983,7 @@ RSpec.describe "bundle update --ruby" do context "when the Gemfile removes the ruby" do before do install_gemfile <<-G - ruby '~> #{RUBY_VERSION}' + ruby '~> #{Gem.ruby_version}' source "#{file_uri_for(gem_repo1)}" G @@ -1013,12 +1013,12 @@ RSpec.describe "bundle update --ruby" do context "when the Gemfile specified an updated Ruby version" do before do install_gemfile <<-G - ruby '~> #{RUBY_VERSION}' + ruby '~> #{Gem.ruby_version}' source "#{file_uri_for(gem_repo1)}" G gemfile <<-G - ruby '~> #{RUBY_VERSION[0..2]}' + ruby '~> #{current_ruby_minor}' source "#{file_uri_for(gem_repo1)}" G end @@ -1047,7 +1047,7 @@ RSpec.describe "bundle update --ruby" do context "when a different Ruby is being used than has been versioned" do before do install_gemfile <<-G - ruby '~> #{RUBY_VERSION}' + ruby '~> #{Gem.ruby_version}' source "#{file_uri_for(gem_repo1)}" G @@ -1083,7 +1083,7 @@ RSpec.describe "bundle update --ruby" do L gemfile <<-G - ruby '~> #{RUBY_VERSION}' + ruby '~> #{Gem.ruby_version}' source "#{file_uri_for(gem_repo1)}" G end diff --git a/spec/bundler/install/gemfile/ruby_spec.rb b/spec/bundler/install/gemfile/ruby_spec.rb index ba250acfdd..39f09031b7 100644 --- a/spec/bundler/install/gemfile/ruby_spec.rb +++ b/spec/bundler/install/gemfile/ruby_spec.rb @@ -11,13 +11,13 @@ RSpec.describe "ruby requirement" do it "allows adding gems" do install_gemfile <<-G source "#{file_uri_for(gem_repo1)}" - ruby "#{RUBY_VERSION}" + ruby "#{Gem.ruby_version}" gem "rack" G install_gemfile <<-G source "#{file_uri_for(gem_repo1)}" - ruby "#{RUBY_VERSION}" + ruby "#{Gem.ruby_version}" gem "rack" gem "rack-obama" G @@ -28,7 +28,7 @@ RSpec.describe "ruby requirement" do it "allows removing the ruby version requirement" do install_gemfile <<-G source "#{file_uri_for(gem_repo1)}" - ruby "~> #{RUBY_VERSION}" + ruby "~> #{Gem.ruby_version}" gem "rack" G @@ -46,7 +46,7 @@ RSpec.describe "ruby requirement" do it "allows changing the ruby version requirement to something compatible" do install_gemfile <<-G source "#{file_uri_for(gem_repo1)}" - ruby ">= #{RUBY_VERSION[0..2]}.0" + ruby ">= #{current_ruby_minor}" gem "rack" G @@ -55,7 +55,7 @@ RSpec.describe "ruby requirement" do install_gemfile <<-G source "#{file_uri_for(gem_repo1)}" - ruby ">= #{RUBY_VERSION}" + ruby ">= #{Gem.ruby_version}" gem "rack" G @@ -93,7 +93,7 @@ RSpec.describe "ruby requirement" do install_gemfile <<-G source "#{file_uri_for(gem_repo1)}" - ruby ">= #{RUBY_VERSION[0..2]}.0" + ruby ">= #{current_ruby_minor}" gem "rack" G @@ -104,7 +104,7 @@ RSpec.describe "ruby requirement" do it "allows requirements with trailing whitespace" do install_gemfile <<-G source "#{file_uri_for(gem_repo1)}" - ruby "#{RUBY_VERSION}\\n \t\\n" + ruby "#{Gem.ruby_version}\\n \t\\n" gem "rack" G diff --git a/spec/bundler/install/gems/resolving_spec.rb b/spec/bundler/install/gems/resolving_spec.rb index b136dea8bd..1679ad4460 100644 --- a/spec/bundler/install/gems/resolving_spec.rb +++ b/spec/bundler/install/gems/resolving_spec.rb @@ -211,7 +211,7 @@ RSpec.describe "bundle install with install-time dependencies" do end install_gemfile <<-G, :artifice => "compact_index", :env => { "BUNDLER_SPEC_GEM_REPO" => gem_repo2.to_s } - ruby "#{RUBY_VERSION}" + ruby "#{Gem.ruby_version}" source "http://localgemserver.test/" gem 'rack' G @@ -232,7 +232,7 @@ RSpec.describe "bundle install with install-time dependencies" do end install_gemfile <<-G, :artifice => "endpoint", :env => { "BUNDLER_SPEC_GEM_REPO" => gem_repo2.to_s } - ruby "#{RUBY_VERSION}" + ruby "#{Gem.ruby_version}" source "http://localgemserver.test/" gem 'rack' G @@ -309,7 +309,7 @@ RSpec.describe "bundle install with install-time dependencies" do end install_gemfile <<-G, :artifice => "compact_index_rate_limited", :env => { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s } - ruby "#{RUBY_VERSION}" + ruby "#{Gem.ruby_version}" source "http://localgemserver.test/" gem 'rack' gem 'foo1' @@ -333,7 +333,7 @@ RSpec.describe "bundle install with install-time dependencies" do simulate_platform mingw do install_gemfile <<-G, :artifice => "compact_index", :env => { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s } - ruby "#{RUBY_VERSION}" + ruby "#{Gem.ruby_version}" source "http://localgemserver.test/" gem 'rack' G @@ -354,8 +354,8 @@ RSpec.describe "bundle install with install-time dependencies" do end end - let(:ruby_requirement) { %("#{RUBY_VERSION}") } - let(:error_message_requirement) { "= #{RUBY_VERSION}" } + let(:ruby_requirement) { %("#{Gem.ruby_version}") } + let(:error_message_requirement) { "= #{Gem.ruby_version}" } it "raises a proper error that mentions the current Ruby version during resolution" do install_gemfile <<-G, :artifice => "compact_index", :env => { "BUNDLER_SPEC_GEM_REPO" => gem_repo2.to_s }, :raise_on_error => false diff --git a/spec/bundler/install/gemspecs_spec.rb b/spec/bundler/install/gemspecs_spec.rb index 3684d8749d..7b58ea9839 100644 --- a/spec/bundler/install/gemspecs_spec.rb +++ b/spec/bundler/install/gemspecs_spec.rb @@ -94,7 +94,8 @@ RSpec.describe "bundle install" do end context "when ruby version is specified in gemspec and gemfile" do - it "installs when patch level is not specified and the version matches" do + it "installs when patch level is not specified and the version matches", + :if => RUBY_PATCHLEVEL >= 0 do build_lib("foo", :path => bundled_app) do |s| s.required_ruby_version = "~> #{RUBY_VERSION}.0" end diff --git a/spec/bundler/lock/lockfile_spec.rb b/spec/bundler/lock/lockfile_spec.rb index b21765ec4d..29f8863591 100644 --- a/spec/bundler/lock/lockfile_spec.rb +++ b/spec/bundler/lock/lockfile_spec.rb @@ -1174,7 +1174,7 @@ RSpec.describe "the lockfile format" do it "captures the Ruby version in the lockfile" do install_gemfile <<-G source "#{file_uri_for(gem_repo2)}/" - ruby '#{RUBY_VERSION}' + ruby '#{Gem.ruby_version}' gem "rack", "> 0.9", "< 1.0" G @@ -1191,7 +1191,7 @@ RSpec.describe "the lockfile format" do rack (> 0.9, < 1.0) RUBY VERSION - ruby #{RUBY_VERSION}p#{RUBY_PATCHLEVEL} + #{Bundler::RubyVersion.system} BUNDLED WITH #{Bundler::VERSION} diff --git a/spec/bundler/other/platform_spec.rb b/spec/bundler/other/platform_spec.rb index c157345cab..691a219e62 100644 --- a/spec/bundler/other/platform_spec.rb +++ b/spec/bundler/other/platform_spec.rb @@ -19,7 +19,7 @@ Your app has gems that work on these platforms: * #{specific_local_platform} Your Gemfile specifies a Ruby version requirement: -* ruby #{RUBY_VERSION} +* ruby #{Gem.ruby_version} Your current platform satisfies the Ruby version requirement. G @@ -42,7 +42,7 @@ Your app has gems that work on these platforms: * #{specific_local_platform} Your Gemfile specifies a Ruby version requirement: -* ruby #{RUBY_VERSION}p#{RUBY_PATCHLEVEL} +* #{Bundler::RubyVersion.system.single_version_string} Your current platform satisfies the Ruby version requirement. G @@ -85,7 +85,7 @@ Your app has gems that work on these platforms: Your Gemfile specifies a Ruby version requirement: * ruby #{not_local_ruby_version} -Your Ruby version is #{RUBY_VERSION}, but your Gemfile specified #{not_local_ruby_version} +Your Ruby version is #{Gem.ruby_version}, but your Gemfile specified #{not_local_ruby_version} G end end @@ -255,18 +255,18 @@ G end end - let(:ruby_version_correct) { "ruby \"#{RUBY_VERSION}\", :engine => \"#{local_ruby_engine}\", :engine_version => \"#{local_engine_version}\"" } - let(:ruby_version_correct_engineless) { "ruby \"#{RUBY_VERSION}\"" } + let(:ruby_version_correct) { "ruby \"#{Gem.ruby_version}\", :engine => \"#{local_ruby_engine}\", :engine_version => \"#{local_engine_version}\"" } + let(:ruby_version_correct_engineless) { "ruby \"#{Gem.ruby_version}\"" } let(:ruby_version_correct_patchlevel) { "#{ruby_version_correct}, :patchlevel => '#{RUBY_PATCHLEVEL}'" } let(:ruby_version_incorrect) { "ruby \"#{not_local_ruby_version}\", :engine => \"#{local_ruby_engine}\", :engine_version => \"#{not_local_ruby_version}\"" } - let(:engine_incorrect) { "ruby \"#{RUBY_VERSION}\", :engine => \"#{not_local_tag}\", :engine_version => \"#{RUBY_VERSION}\"" } - let(:engine_version_incorrect) { "ruby \"#{RUBY_VERSION}\", :engine => \"#{local_ruby_engine}\", :engine_version => \"#{not_local_engine_version}\"" } + let(:engine_incorrect) { "ruby \"#{Gem.ruby_version}\", :engine => \"#{not_local_tag}\", :engine_version => \"#{Gem.ruby_version}\"" } + let(:engine_version_incorrect) { "ruby \"#{Gem.ruby_version}\", :engine => \"#{local_ruby_engine}\", :engine_version => \"#{not_local_engine_version}\"" } let(:patchlevel_incorrect) { "#{ruby_version_correct}, :patchlevel => '#{not_local_patchlevel}'" } let(:patchlevel_fixnum) { "#{ruby_version_correct}, :patchlevel => #{RUBY_PATCHLEVEL}1" } def should_be_ruby_version_incorrect expect(exitstatus).to eq(18) - expect(err).to be_include("Your Ruby version is #{RUBY_VERSION}, but your Gemfile specified #{not_local_ruby_version}") + expect(err).to be_include("Your Ruby version is #{Gem.ruby_version}, but your Gemfile specified #{not_local_ruby_version}") end def should_be_engine_incorrect diff --git a/spec/bundler/support/helpers.rb b/spec/bundler/support/helpers.rb index 03c0df3b50..af6e338853 100644 --- a/spec/bundler/support/helpers.rb +++ b/spec/bundler/support/helpers.rb @@ -476,7 +476,7 @@ module Spec end def current_ruby_minor - Gem.ruby_version.segments[0..1].join(".") + Gem.ruby_version.segments.tap {|s| s.delete_at(2) }.join(".") end def next_ruby_minor diff --git a/spec/bundler/support/platforms.rb b/spec/bundler/support/platforms.rb index 48479723e4..1ad7778403 100644 --- a/spec/bundler/support/platforms.rb +++ b/spec/bundler/support/platforms.rb @@ -71,7 +71,7 @@ module Spec end def local_engine_version - RUBY_ENGINE_VERSION + RUBY_ENGINE == "ruby" ? Gem.ruby_version : RUBY_ENGINE_VERSION end def not_local_engine_version |