summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2017-07-05 16:05:53 +0200
committerSamuel Giddins <segiddins@segiddins.me>2017-07-07 17:52:00 -0500
commitb7387ed537274c061834bc466433dbd49aee0dd8 (patch)
tree9387a09919894766efe190f53fc864c28717b49b
parent59190fa216210b9f236128b58dea8fd4e45f3be8 (diff)
downloadbundler-seg-make-gem-private.tar.gz
Make Bundler.setup not make Kernel#gem public in Bundler 2seg-make-gem-private
-rw-r--r--lib/bundler/feature_flag.rb1
-rw-r--r--lib/bundler/rubygems_integration.rb5
-rw-r--r--lib/bundler/settings.rb1
-rw-r--r--spec/runtime/setup_spec.rb36
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 3025b502ae..89dd152932 100644
--- a/spec/runtime/setup_spec.rb
+++ b/spec/runtime/setup_spec.rb
@@ -1338,17 +1338,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