diff options
author | The Bundler Bot <bot@bundler.io> | 2017-04-05 23:43:10 +0000 |
---|---|---|
committer | The Bundler Bot <bot@bundler.io> | 2017-04-05 23:43:10 +0000 |
commit | 456b34b828130733b144052e485e25feed5dce50 (patch) | |
tree | 8c0e30adf6be7581fd38f91610559a371539fd5a | |
parent | cd8e00b0b9e579821ebe7c931dd6a1300f0e8b0a (diff) | |
parent | 4766aa7dbb7cb6ede44856a7ba74c3d9e50341f0 (diff) | |
download | bundler-456b34b828130733b144052e485e25feed5dce50.tar.gz |
Auto merge of #5454 - bundler:seg-setup-activate-no-gems, r=indirect
Add a spec for not activating any gems during Bundler.setup
This is failing on ruby 2.5, since more of the stdlib is being gemified (fileutils in particular)
We can wait to merge until it passes if you'd like, @indirect, but this will likely also require changes in RubyGems
-rw-r--r-- | lib/bundler/rubygems_integration.rb | 8 | ||||
-rw-r--r-- | spec/runtime/setup_spec.rb | 60 |
2 files changed, 67 insertions, 1 deletions
diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb index 1e71d1adfa..86912376c1 100644 --- a/lib/bundler/rubygems_integration.rb +++ b/lib/bundler/rubygems_integration.rb @@ -758,7 +758,13 @@ module Bundler end def backport_ext_builder_monitor - require "rubygems/ext" + # So we can avoid requiring "rubygems/ext" in its entirety + Gem.module_eval <<-RB, __FILE__, __LINE__ + 1 + module Ext + end + RB + + require "rubygems/ext/builder" Gem::Ext::Builder.class_eval do unless const_defined?(:CHDIR_MONITOR) diff --git a/spec/runtime/setup_spec.rb b/spec/runtime/setup_spec.rb index 809b0a15fd..14f973dc97 100644 --- a/spec/runtime/setup_spec.rb +++ b/spec/runtime/setup_spec.rb @@ -1132,6 +1132,66 @@ end RUBY expect(out).to eq("undefined\nconstant") end + + describe "default gem activation" do + let(:exemptions) do + if Gem::Version.new(Gem::VERSION) >= Gem::Version.new("2.7") || ENV["RGV"] == "master" + [] + else + %w(io-console openssl) + end << "bundler" + end + + let(:code) { strip_whitespace(<<-RUBY) } + require "rubygems" + + if Gem::Specification.instance_methods.map(&:to_sym).include?(:activate) + Gem::Specification.send(:alias_method, :bundler_spec_activate, :activate) + Gem::Specification.send(:define_method, :activate) do + unless #{exemptions.inspect}.include?(name) + warn '-' * 80 + warn "activating \#{full_name}" + warn *caller + warn '*' * 80 + end + bundler_spec_activate + end + end + + require "bundler/setup" + require "pp" + loaded_specs = Gem.loaded_specs.dup + #{exemptions.inspect}.each {|s| loaded_specs.delete(s) } + pp loaded_specs + RUBY + + it "activates no gems with -rbundler/setup" do + install_gemfile! "" + ruby!(code) + expect(err).to eq("") + expect(out).to eq("{}") + end + + it "activates no gems with bundle exec" do + install_gemfile! "" + create_file("script.rb", code) + bundle! "exec ruby ./script.rb" + expect(err).to eq("") + expect(out).to eq("{}") + end + + it "activates no gems with bundle exec that is loaded" do + # TODO: remove once https://github.com/erikhuda/thor/pull/539 is released + exemptions << "io-console" + + install_gemfile! "" + create_file("script.rb", "#!/usr/bin/env ruby\n\n#{code}") + FileUtils.chmod(0o777, bundled_app("script.rb")) + bundle! "exec ./script.rb", :artifice => nil + expect(err).to eq("") + expect(out).to eq("{}") + end + end end describe "after setup" do |