From 6524ba5ea1a95818950215fd026cee5d8c72858e Mon Sep 17 00:00:00 2001 From: Chris Welham <71787007+apexatoll@users.noreply.github.com> Date: Fri, 22 Sep 2023 19:48:24 +0100 Subject: [PATCH] Update autoloader to push with namespace - This prevents a strange bug wherein Zeitwerk would load the target gems files, but raise a Zeitwerk::Name error as it expected the file to define the constant, but it didn't - This was fixed by specifying which namespace the pushed lib directory is part of during autoloading --- lib/kangaru/application.rb | 2 +- sig/zeitwerk/loader.rbs | 2 +- spec/kangaru/application_spec.rb | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/kangaru/application.rb b/lib/kangaru/application.rb index d1e0445..c753616 100644 --- a/lib/kangaru/application.rb +++ b/lib/kangaru/application.rb @@ -29,7 +29,7 @@ def run!(argv) def autoloader @autoloader ||= Zeitwerk::Loader.new.tap do |loader| loader.inflector = Zeitwerk::GemInflector.new(root_file) - loader.push_dir(app_dir) + loader.push_dir(app_dir, namespace:) end end end diff --git a/sig/zeitwerk/loader.rbs b/sig/zeitwerk/loader.rbs index 953a25e..9079d8e 100755 --- a/sig/zeitwerk/loader.rbs +++ b/sig/zeitwerk/loader.rbs @@ -6,7 +6,7 @@ module Zeitwerk def collapse: (Array[String]) -> void - def push_dir: (String dir) -> void + def push_dir: (String dir, ?namespace: Module) -> void def setup: -> void end diff --git a/spec/kangaru/application_spec.rb b/spec/kangaru/application_spec.rb index eeca991..3d31142 100644 --- a/spec/kangaru/application_spec.rb +++ b/spec/kangaru/application_spec.rb @@ -47,7 +47,11 @@ it "configures the loader to load the app dir" do setup - expect(loader).to have_received(:push_dir).with(application.app_dir).once + + expect(loader) + .to have_received(:push_dir) + .with(application.app_dir, namespace:) + .once end it "enables the instantiated loader" do