Skip to content

Commit f091fc2

Browse files
committed
Use Zeitwerk::Registry to unload loaders in tests
Previously I enabled ObjectSpace in JRuby in zeitwerk_helpers.rb programatically, but it did not fully work. ObjectSpace.each_object(Zeitwerk::Loader) kept returning empty list. I suppose this was because the ObjectSpace was enabled too late. It worked correctly when JRUBY_OPTS="-X+O" wever passed in the command line. However, because the CI config is set via repo automation, it was hard to configure it just for dry-systems and would have a performance penalty if we enabled it for all gems. So instead, I figured out a way to drop usage of ObjectSpace in favour of Zeitwer's Registry module, which does the same thing (presumably even better).
1 parent 8d0bfab commit f091fc2

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

spec/support/zeitwerk_helpers.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
# frozen_string_literal: true
22

3-
if RUBY_ENGINE == "jruby"
4-
require "jruby"
5-
JRuby.objectspace = true
6-
end
7-
83
module ZeitwerkHelpers
94
def teardown_zeitwerk
10-
ObjectSpace.each_object(Zeitwerk::Loader) do |loader|
5+
Zeitwerk::Registry.loaders.each do |loader|
116
if loader.dirs.any? { |dir| dir.include?("/spec/") || dir.include?(Dir.tmpdir) }
127
loader.unregister
138
end

0 commit comments

Comments
 (0)