summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2023-07-21 10:21:39 +0900
committergit <svn-admin@ruby-lang.org>2023-07-25 06:23:28 +0000
commit8fbe7d0295fd38496b61e2e1a93c920f93892aa4 (patch)
tree9d7858b76edb337c11f2a710b706aac6dd07705f
parent422144d220e8cfec38c0b07b2ba142aa5fa9066b (diff)
[rubygems/rubygems] Skip warnings if bundled gems is already loaded
https://github.com/rubygems/rubygems/commit/9583a7eb82
-rw-r--r--lib/bundler/rubygems_integration.rb16
-rw-r--r--spec/bundler/runtime/setup_spec.rb19
2 files changed, 28 insertions, 7 deletions
diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb
index 5f151e8c80..8f2b6994ed 100644
--- a/lib/bundler/rubygems_integration.rb
+++ b/lib/bundler/rubygems_integration.rb
@@ -233,13 +233,15 @@ module Bundler
kernel_class.send(:define_method, :require) do |file|
name = file.tr("/", "-")
if (::Gem::BUNDLED_GEMS.keys - specs.to_a.map(&:name)).include?(name)
- target_file = begin
- Bundler.default_gemfile.basename
- rescue GemfileNotFound
- "inline Gemfile"
- end
- warn "#{name} is not part of the default gems since Ruby #{::Gem::BUNDLED_GEMS[file]}." \
- " Add it to your #{target_file}."
+ unless $LOADED_FEATURES.any?{|f| f.end_with?("#{name}.rb", "#{name}.#{RbConfig::CONFIG['DLEXT']}")}
+ target_file = begin
+ Bundler.default_gemfile.basename
+ rescue GemfileNotFound
+ "inline Gemfile"
+ end
+ warn "#{name} is not part of the default gems since Ruby #{::Gem::BUNDLED_GEMS[file]}." \
+ " Add it to your #{target_file}."
+ end
end
kernel_class.send(:no_warning_require, file)
end
diff --git a/spec/bundler/runtime/setup_spec.rb b/spec/bundler/runtime/setup_spec.rb
index 2b2656be5a..dde418bf1d 100644
--- a/spec/bundler/runtime/setup_spec.rb
+++ b/spec/bundler/runtime/setup_spec.rb
@@ -1574,6 +1574,25 @@ end
expect(err).to include("csv is not part of the default gems")
end
+ it "don't warn with bundled gems when it's loaded twice" do
+ build_repo4 do
+ build_gem "rack"
+ end
+
+ install_gemfile <<-G
+ source "#{file_uri_for(gem_repo4)}"
+ gem "rack"
+ G
+
+ ruby <<-R
+ require 'csv'
+ require 'bundler/setup'
+ require 'csv'
+ R
+
+ expect(err).to be_empty
+ end
+
it "don't warn with bundled gems when it's declared in Gemfile" do
build_repo4 do
build_gem "csv"