Skip to content

Commit 68503fa

Browse files
committed
fix(detection): handle partially-loaded Bundler in BundlerDefaults
RubyGems 4.0 defines the Bundler module without loading Bundler.settings, causing NoMethodError when running as an installed gem. Explicitly require bundler before accessing settings, with fallback to defaults on failure.
1 parent 108435f commit 68503fa

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ and [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/).
88

99
## [Unreleased]
1010

11+
### Fixed
12+
13+
- Crash on Ruby 4.0 / RubyGems 4.0 where `Bundler.settings` was unavailable because Bundler was only partially loaded.
14+
1115
## [0.1.0] - 2026-02-10
1216

1317
### Added

lib/create_ruby_gem/detection/bundler_defaults.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ def detect
6666

6767
# @return [Bundler::Settings, nil]
6868
def default_settings
69-
return nil unless defined?(::Bundler)
70-
69+
require 'bundler'
7170
::Bundler.settings
71+
rescue LoadError, StandardError
72+
nil
7273
end
7374

7475
# @param value [String, Object, nil]

spec/create_ruby_gem/detection/bundler_defaults_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ def settings.[](_key) = raise(StandardError, 'boom')
4747
expect(defaults).to eq(described_class::FALLBACKS)
4848
end
4949

50+
it 'returns fallbacks when Bundler.settings raises NoMethodError' do
51+
stub_const('Bundler', Module.new)
52+
defaults = described_class.new.detect
53+
54+
expect(defaults).to eq(described_class::FALLBACKS)
55+
end
56+
5057
it 'normalizes string booleans to actual booleans' do
5158
settings = { 'gem.coc' => 'true', 'gem.mit' => 'false' }
5259
defaults = described_class.new(settings: settings).detect

0 commit comments

Comments
 (0)