diff options
author | Daniel Colson <danieljamescolson@gmail.com> | 2023-08-29 08:41:28 -0400 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2023-10-03 17:16:19 +0000 |
commit | accda74cbeb96a5539e0cf44741418654291d3c0 (patch) | |
tree | 947065b69109c1007300918791a6ff9eeb34862b /spec/bundler/install/gems/standalone_spec.rb | |
parent | 1992aef7225b864613b22be5bfb164f5c909a71c (diff) | |
download | ruby-accda74cbeb96a5539e0cf44741418654291d3c0.tar.gz |
[rubygems/rubygems] Prevent gem activation in standalone mode
As discussed in https://github.com/rubygems/rubygems/issues/6273#issuecomment-1449176658
The `gem` method behaves awkwardly in standalone mode. Assuming bundler
isn't loaded at all, a call to gem might activate a gem that is not part
of the bundle (because it's the gem method defined in
lib/rubygems/core_ext/kernel_gem.rb and not
lib/bundler/rubygems_integration.rb). And when running with
`--disable-gems`, the gem method won't be defined at all so we'll get a
NoMethodError.
Calls to `gem` can appear in dependencies outside an application's
control. To work around this at GitHub we defined our own `Kernel#gem`
that no-ops.
I agree with https://github.com/rubygems/rubygems/issues/6273#issuecomment-1440755882
> people using standalone mode don't want to activate gems like Kernel.gem
This commit redefines `Kernel#gem` in the standalone script to no-op.
https://github.com/rubygems/rubygems/commit/bea17b55f1
Diffstat (limited to 'spec/bundler/install/gems/standalone_spec.rb')
-rw-r--r-- | spec/bundler/install/gems/standalone_spec.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/spec/bundler/install/gems/standalone_spec.rb b/spec/bundler/install/gems/standalone_spec.rb index 4d08752256..edb7a0e6bc 100644 --- a/spec/bundler/install/gems/standalone_spec.rb +++ b/spec/bundler/install/gems/standalone_spec.rb @@ -101,6 +101,22 @@ RSpec.shared_examples "bundle install --standalone" do expect(out).to eq(expected_gems.values.join("\n")) end + + it "skips activating gems" do + testrb = String.new <<-RUBY + $:.unshift File.expand_path("bundle") + require "bundler/setup" + + gem "do_not_activate_me" + RUBY + expected_gems.each do |k, _| + testrb << "\nrequire \"#{k}\"" + testrb << "\nputs #{k.upcase}" + end + sys_exec %(#{Gem.ruby} -w -e #{testrb.shellescape}) + + expect(out).to eq(expected_gems.values.join("\n")) + end end describe "with simple gems" do |