1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[rubygems/rubygems] Use correct way to detect default gems

The other way, in particular matching a substring in the gemspec
summary, is brittle and no longer used since Ruby 2.0.

This needed rewriting the specs that depended on that way.

059dbfa971
This commit is contained in:
David Rodríguez 2021-10-11 19:59:46 +02:00 committed by git
parent d6627ab85c
commit bd87397f73
2 changed files with 13 additions and 23 deletions

View file

@ -135,7 +135,7 @@ module Bundler
force = opts[:force] force = opts[:force]
ensure_builtin_gems_cached = opts[:ensure_builtin_gems_cached] ensure_builtin_gems_cached = opts[:ensure_builtin_gems_cached]
if ensure_builtin_gems_cached && builtin_gem?(spec) if ensure_builtin_gems_cached && spec.default_gem?
if !cached_path(spec) if !cached_path(spec)
cached_built_in_gem(spec) unless spec.remote cached_built_in_gem(spec) unless spec.remote
force = true force = true
@ -233,7 +233,7 @@ module Bundler
end end
def cache(spec, custom_path = nil) def cache(spec, custom_path = nil)
if builtin_gem?(spec) if spec.default_gem?
cached_path = cached_built_in_gem(spec) cached_path = cached_built_in_gem(spec)
else else
cached_path = cached_gem(spec) cached_path = cached_gem(spec)
@ -479,14 +479,6 @@ module Bundler
Bundler.rm_rf(download_path) if requires_sudo? Bundler.rm_rf(download_path) if requires_sudo?
end end
def builtin_gem?(spec)
# Ruby 2.1, where all included gems have this summary
return true if spec.summary =~ /is bundled with Ruby/
# Ruby 2.0, where gemspecs are stored in specifications/default/
spec.loaded_from && spec.loaded_from.include?("specifications/default/")
end
def installed?(spec) def installed?(spec)
installed_specs[spec].any? installed_specs[spec].any?
end end

View file

@ -89,35 +89,33 @@ RSpec.describe "bundle cache" do
it_behaves_like "when there are only gemsources" it_behaves_like "when there are only gemsources"
end end
describe "when there is a built-in gem" do describe "when there is a built-in gem", :ruby_repo do
let(:default_json_version) { ruby "gem 'json'; require 'json'; puts JSON::VERSION" }
before :each do before :each do
build_repo2 do build_repo2 do
build_gem "builtin_gem", "1.0.2" build_gem "json", default_json_version
end end
build_gem "builtin_gem", "1.0.2", :to_system => true do |s| build_gem "json", default_json_version, :to_system => true, :default => true
s.summary = "This builtin_gem is bundled with Ruby"
end
FileUtils.rm("#{system_gem_path}/cache/builtin_gem-1.0.2.gem")
end end
it "uses builtin gems when installing to system gems" do it "uses builtin gems when installing to system gems" do
bundle "config set path.system true" bundle "config set path.system true"
install_gemfile %(source "#{file_uri_for(gem_repo1)}"; gem 'builtin_gem', '1.0.2') install_gemfile %(source "#{file_uri_for(gem_repo1)}"; gem 'json', '#{default_json_version}'), :verbose => true
expect(the_bundle).to include_gems("builtin_gem 1.0.2") expect(out).to include("Using json #{default_json_version}")
end end
it "caches remote and builtin gems" do it "caches remote and builtin gems" do
install_gemfile <<-G install_gemfile <<-G
source "#{file_uri_for(gem_repo2)}" source "#{file_uri_for(gem_repo2)}"
gem 'builtin_gem', '1.0.2' gem 'json', '#{default_json_version}'
gem 'rack', '1.0.0' gem 'rack', '1.0.0'
G G
bundle :cache bundle :cache
expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist
expect(bundled_app("vendor/cache/builtin_gem-1.0.2.gem")).to exist expect(bundled_app("vendor/cache/json-#{default_json_version}.gem")).to exist
end end
it "doesn't make remote request after caching the gem" do it "doesn't make remote request after caching the gem" do
@ -139,12 +137,12 @@ RSpec.describe "bundle cache" do
install_gemfile <<-G install_gemfile <<-G
source "#{file_uri_for(gem_repo1)}" source "#{file_uri_for(gem_repo1)}"
gem 'builtin_gem', '1.0.2' gem 'json', '#{default_json_version}'
G G
bundle :cache, :raise_on_error => false bundle :cache, :raise_on_error => false
expect(exitstatus).to_not eq(0) expect(exitstatus).to_not eq(0)
expect(err).to include("builtin_gem-1.0.2 is built in to Ruby, and can't be cached") expect(err).to include("json-#{default_json_version} is built in to Ruby, and can't be cached")
end end
end end