Closed
Description
I had a test setup that needs to clean up all but the first loader. This was the setup code for tests:
setup do
Zeitwerk::Registry.loaders[1..-1]
.each { Zeitwerk::Registry.unregister_loader(_1) }
end
The first loader shouldn't be unregistered because it's the gem's one (Zeitwerk::Loader.for_gem
).
I noticed that there's was a change on the registry; previously, it was using an array, and now it has its own class, which doesn't honour the #[]
protocol, thus breaking the API.
I updated the code to this:
setup do
Zeitwerk::Registry
.loaders.each.with_index do |loader, index|
Zeitwerk::Registry.unregister_loader(loader) if index > 0
end
end
For some reason, it looks like the loader is not being unregistered. Tests are failing with this:
Zeitwerk::Error: loader
#<Zeitwerk::Loader:0x00000001268d21c0
@autoloaded_dirs=[],
@autoloads={},
@collapse_dirs=#<Set: {}>,
@collapse_glob_patterns=#<Set: {}>,
@dirs_autoload_monitor=#<Monitor:0x00000001260d2e98>,
@eager_load_exclusions=#<Set: {}>,
@eager_loaded=false,
@ignored_glob_patterns=#<Set: {}>,
@ignored_paths=#<Set: {}>,
@inceptions=
#<Zeitwerk::Cref::Map:0x00000001260d2fb0
@map={},
@mutex=#<Thread::Mutex:0x00000001260d2f88>>,
@inflector=#<Zeitwerk::Inflector:0x00000001260d3118>,
@initialized_at=2025-05-29 16:15:54.839413 -0700,
@logger=nil,
@mutex=#<Thread::Mutex:0x00000001260d2ec0>,
@namespace_dirs=
#<Zeitwerk::Cref::Map:0x00000001260d2f38
@map={},
@mutex=#<Thread::Mutex:0x00000001260d2f10>>,
@on_load_callbacks={},
@on_setup_callbacks=[],
@on_unload_callbacks={},
@reloading_enabled=false,
@roots={},
@setup=false,
@shadowed_files=#<Set: {}>,
@tag="edbcc0",
@to_unload={}>
wants to manage directory /Users/fnando/Projects/personal/zee/test/fixtures/sample_app/app/controllers, which is already managed by
#<Zeitwerk::Loader:0x000000012281aa10
@autoloaded_dirs=[],
@autoloads=
{"/Users/fnando/Projects/personal/zee/test/fixtures/sample_app/app/controllers/admin.rb" =>
#<Zeitwerk::Cref:0x0000000122833240
@cname=:Admin,
@mod=Controllers,
@path=nil>,
"/Users/fnando/Projects/personal/zee/test/fixtures/sample_app/app/controllers/base.rb" =>
#<Zeitwerk::Cref:0x0000000122833038
@cname=:Base,
@mod=Controllers,
@path=nil>,
"/Users/fnando/Projects/personal/zee/test/fixtures/sample_app/app/controllers/categories.rb" =>
#<Zeitwerk::Cref:0x0000000122832e58
@cname=:Categories,
@mod=Controllers,
@path=nil>,
"/Users/fnando/Projects/personal/zee/test/fixtures/sample_app/app/controllers/feeds.rb" =>
#<Zeitwerk::Cref:0x0000000122832c78
@cname=:Feeds,
@mod=Controllers,
@path=nil>,
"/Users/fnando/Projects/personal/zee/test/fixtures/sample_app/app/controllers/formats.rb" =>
#<Zeitwerk::Cref:0x0000000122832a98
@cname=:Formats,
@mod=Controllers,
@path=nil>,
"/Users/fnando/Projects/personal/zee/test/fixtures/sample_app/app/controllers/helpers.rb" =>
#<Zeitwerk::Cref:0x0000000122832930
@cname=:Helpers,
@mod=Controllers,
@path=nil>,
"/Users/fnando/Projects/personal/zee/test/fixtures/sample_app/app/controllers/locales.rb" =>
#<Zeitwerk::Cref:0x0000000122832750
@cname=:Locales,
@mod=Controllers,
@path=nil>,
"/Users/fnando/Projects/personal/zee/test/fixtures/sample_app/app/controllers/messages.rb" =>
#<Zeitwerk::Cref:0x0000000122832570
@cname=:Messages,
@mod=Controllers,
@path=nil>,
"/Users/fnando/Projects/personal/zee/test/fixtures/sample_app/app/controllers/pages.rb" =>
#<Zeitwerk::Cref:0x0000000122832390
@cname=:Pages,
@mod=Controllers,
@path=nil>,
"/Users/fnando/Projects/personal/zee/test/fixtures/sample_app/app/controllers/posts.rb" =>
#<Zeitwerk::Cref:0x00000001228321b0
@cname=:Posts,
@mod=Controllers,
@path=nil>,
"/Users/fnando/Projects/personal/zee/test/fixtures/sample_app/app/controllers/sessions.rb" =>
#<Zeitwerk::Cref:0x0000000122831fd0
@cname=:Sessions,
@mod=Controllers,
@path=nil>,
"/Users/fnando/Projects/personal/zee/test/fixtures/sample_app/app/controllers/things.rb" =>
#<Zeitwerk::Cref:0x0000000122831df0
@cname=:Things,
@mod=Controllers,
@path=nil>,
"/Users/fnando/Projects/personal/zee/test/fixtures/sample_app/app/mailers/mailer.rb" =>
#<Zeitwerk::Cref:0x0000000122831710
@cname=:Mailer,
@mod=Mailers,
@path=nil>},
@collapse_dirs=#<Set: {}>,
@collapse_glob_patterns=#<Set: {}>,
@dirs_autoload_monitor=#<Monitor:0x0000000122837ea8>,
@eager_load_exclusions=#<Set: {}>,
@eager_loaded=false,
@ignored_glob_patterns=#<Set: {}>,
@ignored_paths=#<Set: {}>,
@inceptions=
#<Zeitwerk::Cref::Map:0x0000000122837fc0
@map={},
@mutex=#<Thread::Mutex:0x0000000122837f98>>,
@inflector=#<Zeitwerk::Inflector:0x00000001228381a0 @overrides={}>,
@initialized_at=2025-05-29 16:15:51.733076 -0700,
@logger=nil,
@mutex=#<Thread::Mutex:0x0000000122837ed0>,
@namespace_dirs=
#<Zeitwerk::Cref::Map:0x0000000122837f48
@map=
{Controllers =>
{Admin:
["/Users/fnando/Projects/personal/zee/test/fixtures/sample_app/app/controllers/admin"]}},
@mutex=#<Thread::Mutex:0x0000000122837f20>>,
@on_load_callbacks={},
@on_setup_callbacks=[],
@on_unload_callbacks={},
@reloading_enabled=false,
@roots=
{"/Users/fnando/Projects/personal/zee/test/fixtures/sample_app/app/controllers" =>
Controllers,
"/Users/fnando/Projects/personal/zee/test/fixtures/sample_app/app/helpers" =>
Helpers,
"/Users/fnando/Projects/personal/zee/test/fixtures/sample_app/app/mailers" =>
Mailers,
"/Users/fnando/Projects/personal/zee/test/fixtures/sample_app/app/views" =>
Views},
@setup=true,
@shadowed_files=#<Set: {}>,
@tag="c83ce3",
@to_unload={}>
/Users/fnando/.local/ruby/3.4.4/gems/zeitwerk-2.7.3/lib/zeitwerk/loader.rb:612:in 'block (3 levels) in Zeitwerk::Loader#raise_if_conflicting_directory'
/Users/fnando/.local/ruby/3.4.4/gems/zeitwerk-2.7.3/lib/zeitwerk/loader.rb:606:in 'Hash#each_key'
/Users/fnando/.local/ruby/3.4.4/gems/zeitwerk-2.7.3/lib/zeitwerk/loader.rb:606:in 'block (2 levels) in Zeitwerk::Loader#raise_if_conflicting_directory'
/Users/fnando/.local/ruby/3.4.4/gems/zeitwerk-2.7.3/lib/zeitwerk/registry/loaders.rb:10:in 'Array#each'
/Users/fnando/.local/ruby/3.4.4/gems/zeitwerk-2.7.3/lib/zeitwerk/registry/loaders.rb:10:in 'Zeitwerk::Registry::Loaders#each'
/Users/fnando/.local/ruby/3.4.4/gems/zeitwerk-2.7.3/lib/zeitwerk/loader.rb:602:in 'block in Zeitwerk::Loader#raise_if_conflicting_directory'
/Users/fnando/.local/ruby/3.4.4/gems/zeitwerk-2.7.3/lib/zeitwerk/loader.rb:599:in 'Thread::Mutex#synchronize'
/Users/fnando/.local/ruby/3.4.4/gems/zeitwerk-2.7.3/lib/zeitwerk/loader.rb:599:in 'Zeitwerk::Loader#raise_if_conflicting_directory'
/Users/fnando/.local/ruby/3.4.4/gems/zeitwerk-2.7.3/lib/zeitwerk/loader/config.rb:120:in 'Zeitwerk::Loader::Config#push_dir'
lib/zee/app.rb:278:in 'block in Zee::App#initialize!'
lib/zee/app.rb:284:in 'block in Zee::App#initialize!'
lib/zee/app.rb:281:in 'Array#each'
lib/zee/app.rb:281:in 'Zee::App#initialize!'
test/fixtures/sample_app/app.rb:84:in 'block in SampleApp.create'
test/fixtures/sample_app/app.rb:84:in 'Dir.chdir'
test/fixtures/sample_app/app.rb:84:in 'SampleApp.create'
Any tips on this? Is this a bug or am I using the wrong API in 2.7.3?
Metadata
Metadata
Assignees
Labels
No labels