diff options
author | The Bundler Bot <bot@bundler.io> | 2017-07-08 23:28:23 +0000 |
---|---|---|
committer | The Bundler Bot <bot@bundler.io> | 2017-07-08 23:28:23 +0000 |
commit | 757664c0048a53f65724e76319449680e124d2bc (patch) | |
tree | e7961efb370ce83ca2ddb4851d9ca6cb653e7fb6 | |
parent | 288b3c90d9db4e3f367748e9ae29c276db95e941 (diff) | |
parent | b7387ed537274c061834bc466433dbd49aee0dd8 (diff) | |
download | bundler-757664c0048a53f65724e76319449680e124d2bc.tar.gz |
Auto merge of #5838 - bundler:seg-make-gem-private, r=indirect
Make Bundler.setup not make Kernel#gem public in Bundler 2
### What was the end-user problem that led to this PR?
The problem was Bundler 1 accidentally made `Kernel#gem` public, even though RubyGems declares it as private. Oops. We tried to make it private in 1.13, it broke stuff, so we added in a hack to keep it public.
### What was your diagnosis of the problem?
My diagnosis was we could delete that hack in 2.0.
### What is your fix for the problem, implemented in this PR?
My fix implements a feature flag that skips making `Kernel#gem` public, and adds regression tests for `gem` or `require` accidentally being made public.
-rw-r--r-- | lib/bundler/feature_flag.rb | 1 | ||||
-rw-r--r-- | lib/bundler/rubygems_integration.rb | 5 | ||||
-rw-r--r-- | lib/bundler/settings.rb | 1 | ||||
-rw-r--r-- | spec/runtime/setup_spec.rb | 36 |
4 files changed, 39 insertions, 4 deletions
diff --git a/lib/bundler/feature_flag.rb b/lib/bundler/feature_flag.rb index 1bc9d0b44c..c8c5894c96 100644 --- a/lib/bundler/feature_flag.rb +++ b/lib/bundler/feature_flag.rb @@ -38,6 +38,7 @@ module Bundler settings_flag(:only_update_to_newer_versions) { bundler_2_mode? } settings_flag(:plugins) { @bundler_version >= Gem::Version.new("1.14") } settings_flag(:prefer_gems_rb) { bundler_2_mode? } + settings_flag(:setup_makes_kernel_gem_public) { !bundler_2_mode? } settings_flag(:skip_default_git_sources) { bundler_2_mode? } settings_flag(:specific_platform) { bundler_2_mode? } settings_flag(:suppress_install_using_messages) { bundler_2_mode? } diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb index edc931e79f..d94abf838f 100644 --- a/lib/bundler/rubygems_integration.rb +++ b/lib/bundler/rubygems_integration.rb @@ -393,9 +393,8 @@ module Bundler raise e end - # TODO: delete this in 2.0, it's a backwards compatibility shim - # see https://github.com/bundler/bundler/issues/5102 - kernel_class.send(:public, :gem) + # backwards compatibility shim, see https://github.com/bundler/bundler/issues/5102 + kernel_class.send(:public, :gem) if Bundler.feature_flag.setup_makes_kernel_gem_public? end end diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb index 07325636b5..9bce931734 100644 --- a/lib/bundler/settings.rb +++ b/lib/bundler/settings.rb @@ -35,6 +35,7 @@ module Bundler only_update_to_newer_versions plugins prefer_gems_rb + setup_makes_kernel_gem_public silence_root_warning skip_default_git_sources specific_platform diff --git a/spec/runtime/setup_spec.rb b/spec/runtime/setup_spec.rb index 5e8d652497..c6b2d1ff3f 100644 --- a/spec/runtime/setup_spec.rb +++ b/spec/runtime/setup_spec.rb @@ -1342,17 +1342,51 @@ end end describe "after setup" do - it "allows calling #gem on random objects" do + it "allows calling #gem on random objects", :bundler => "< 2" do install_gemfile <<-G source "file:#{gem_repo1}" gem "rack" G + ruby! <<-RUBY require "bundler/setup" Object.new.gem "rack" puts Gem.loaded_specs["rack"].full_name RUBY + expect(out).to eq("rack-1.0.0") end + + it "keeps Kernel#gem private", :bundler => "2" do + install_gemfile! <<-G + source "file:#{gem_repo1}" + gem "rack" + G + + ruby <<-RUBY + require "bundler/setup" + Object.new.gem "rack" + puts "FAIL" + RUBY + + expect(last_command.stdboth).not_to include "FAIL" + expect(last_command.stderr).to include "private method `gem'" + end + + it "keeps Kernel#require private" do + install_gemfile! <<-G + source "file:#{gem_repo1}" + gem "rack" + G + + ruby <<-RUBY + require "bundler/setup" + Object.new.require "rack" + puts "FAIL" + RUBY + + expect(last_command.stdboth).not_to include "FAIL" + expect(last_command.stderr).to include "private method `require'" + end end end |