diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb index 5f151e8c80660b..8f2b6994edaf6d 100644 --- a/lib/bundler/rubygems_integration.rb +++ b/lib/bundler/rubygems_integration.rb @@ -233,13 +233,15 @@ def replace_require(specs) 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 039df0737b44b7..88ec1bcdc95a3a 100644 --- a/spec/bundler/runtime/setup_spec.rb +++ b/spec/bundler/runtime/setup_spec.rb @@ -1564,6 +1564,25 @@ def require(path) 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"