Conversation
…vate()
This patch fixes a problem where `binding.irb` (= force_activate('irb'))
fails under `bundle exec` when the Gemfile does not contain `irb` and
does contain a gem which is (1) not installed in GEM_HOME (2) sourced
using `path:`/`git:`.
The original approach constructing a temporary definition fails since
it does not set the equalivent of `path:`/`git:`.
Always reconstructing a definition from a Gemfile and applying lockfile
constraints should be a more robust approach.
[Bug #21723]
Bundler::Runtime#setup requires a real existing lockfile (see Bundler::SharedHelpers#default_lockfile).
This patch silences the "this won't work in the next version of Ruby"
warning displayed when irb is autoloaded via `binding.irb`.
main.rb:1: warning: irb used to be loaded from the standard library, but is not part of the default gems since Ruby 4.0.0.
You can add irb to your Gemfile or gemspec to fix this error.
/.../irb.rb:9: warning: reline used to be loaded from the standard library, but is not part of the default gems since Ruby 4.0.0.
You can add reline to your Gemfile or gemspec to fix this error.
From: main.rb @ line 1 :
=> 1: binding.irb
/.../input-method.rb:284: warning: rdoc used to be loaded from the standard library, but is not part of the default gems since Ruby 4.0.0.
You can add rdoc to your Gemfile or gemspec to fix this error.
This warning is incorrect and misleading: users should not need to
include irb (and its dependencies) to their Gemfiles to use
`binding.irb`, even in future versions of Ruby. It is agreed that the
runtime takes care of that.
Users should add `irb` to their Gemfile. `Gem::BUNDLED_GEMS.force_activate 'irb'` is workaround for short term.
There was a problem hiding this comment.
Pull request overview
This PR backports a fix for Bug #21723 related to bundled gems warning suppression and force_activate behavior with bundler/inline.
Changes:
- Adds warning suppression mechanism for bundled gems using thread-local storage
- Modifies
force_activateto handle bundler/inline scenarios by conditionally setting fake BUNDLE_GEMFILE/BUNDLE_LOCKFILE environment variables - Adds test coverage for
force_activatewith bundler/inline
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| prelude.rb | Adds thread-local warning suppression for 'reline' and 'rdoc' when loading IRB to prevent unwanted bundled gem warnings |
| lib/bundled_gems.rb | Adds warning suppression check and refactors force_activate to handle bundler/inline by conditionally faking environment variables |
| spec/bundled_gems_spec.rb | Adds test case to verify force_activate works correctly with bundler/inline and preserves LOAD_PATH |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| end | ||
|
|
||
| context "with bundler/inline" do | ||
| it "foo is available on LOAD_PATH" do |
There was a problem hiding this comment.
The test description "foo is available on LOAD_PATH" is misleading. The test is actually verifying that when force_activate is called with bundler/inline, it correctly shows the gem installation warning for the missing gem ("csv") while preserving the LOAD_PATH entries from the inline Gemfile (including "foo-1.0.0/lib"). A more accurate description would be something like "preserves LOAD_PATH from inline gemfile when force_activate fails".
| it "foo is available on LOAD_PATH" do | |
| it "preserves LOAD_PATH from inline gemfile when force_activate fails" do |
https://bugs.ruby-lang.org/issues/21723