diff --git a/CHANGELOG.md b/CHANGELOG.md index 01c3273..aae24a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## [Unreleased] +### Added + +- Increase compatibility of Kernel#require patch + ## [2.0.0] - 2024-02-29 ### Removed diff --git a/lib/mnemosyne/probes.rb b/lib/mnemosyne/probes.rb index f7526b1..8a7b738 100644 --- a/lib/mnemosyne/probes.rb +++ b/lib/mnemosyne/probes.rb @@ -21,20 +21,18 @@ def registry @registry ||= ::Mnemosyne::Registry.new end end - end -end -module Kernel - alias require_without_mn require + module Loader + module_function - def require(name) - ret = require_without_mn(name) - - begin - ::Mnemosyne::Probes.required(name) - rescue Exception # rubocop:disable Lint/RescueException,Lint/SuppressedException + def require(name) + super(name).tap do + ::Mnemosyne::Probes.required(name) + rescue Exception # rubocop:disable Lint/RescueException,Lint/SuppressedException + end + end end - ret + ::Kernel.prepend(Loader) end end diff --git a/spec/mnemosyne/probes_spec.rb b/spec/mnemosyne/probes_spec.rb new file mode 100644 index 0000000..f007ab3 --- /dev/null +++ b/spec/mnemosyne/probes_spec.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Mnemosyne::Probes do + it 'injects the loader into Kernel#require' do + expect(Mnemosyne::Probes).to receive(:required).with('mnemosyne/probes') + require 'mnemosyne/probes' + end + + it 'does not make objects respond to require' do + expect(Object.new).not_to respond_to(:require) + end +end