Skip to content

Commit

Permalink
Merge pull request #235 from alassek/fix-manifest-registrar
Browse files Browse the repository at this point in the history
[changelog]

version: unreleased
fixed: "Fix incorrect type in `ManifestRegistrar#finalize!` (@alassek)"
  • Loading branch information
solnic authored Jun 15, 2022
2 parents 1c5e3ae + 9266d0e commit 066c676
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/dry/system/manifest_registrar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def initialize(container)
# @api private
def finalize!
::Dir[registrations_dir.join(RB_GLOB)].sort.each do |file|
call(File.basename(file, RB_EXT))
call(Identifier.new(File.basename(file, RB_EXT)))
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
require "zeitwerk"

RSpec.describe "Component dir namespaces / Autoloading loader" do
include ZeitwerkHelpers

let(:container) {
root = @dir
dir_config = defined?(component_dir_config) ? component_dir_config : -> * {}
Expand All @@ -21,15 +23,7 @@

let(:loader) { Zeitwerk::Loader.new }

after do
Zeitwerk::Registry.loaders.each(&:unload)

Zeitwerk::Registry.loaders.clear
Zeitwerk::Registry.loaders_managing_gems.clear

Zeitwerk::ExplicitNamespace.cpaths.clear
Zeitwerk::ExplicitNamespace.tracer.disable
end
after { teardown_zeitwerk }

context "top-level constant namespace" do
let(:component_dir_config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,19 @@ class Container < Dry::System::Container
end
end

it "loads a registration manifest file if the component could not be found" do
expect(Test::Container["foo.special"]).to be_a(Test::Foo)
expect(Test::Container["foo.special"].name).to eq "special"
shared_examples "manifest component" do
it "loads a registration manifest file if the component could not be found" do
expect(Test::Container["foo.special"]).to be_a(Test::Foo)
expect(Test::Container["foo.special"].name).to eq "special"
end
end

context "Non-finalized container" do
include_examples "manifest component"
end

context "Finalized container" do
before { Test::Container.finalize! }
include_examples "manifest component"
end
end
10 changes: 9 additions & 1 deletion spec/support/zeitwerk_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ def teardown_zeitwerk
Zeitwerk::Registry.loaders.each(&:unload)

Zeitwerk::Registry.loaders.clear
Zeitwerk::Registry.loaders_managing_gems.clear

# This private interface changes between 2.5.4 and 2.6.0
if Zeitwerk::Registry.respond_to?(:loaders_managing_gems)
Zeitwerk::Registry.loaders_managing_gems.clear
else
Zeitwerk::Registry.gem_loaders_by_root_file.clear
Zeitwerk::Registry.autoloads.clear
Zeitwerk::Registry.inceptions.clear
end

Zeitwerk::ExplicitNamespace.cpaths.clear
Zeitwerk::ExplicitNamespace.tracer.disable
Expand Down

0 comments on commit 066c676

Please sign in to comment.