Skip to content

Commit

Permalink
Allow the with_setup loader to receive no files
Browse files Browse the repository at this point in the history
This use case has appeared more frequently, deserves this refactor.
  • Loading branch information
fxn committed Nov 5, 2022
1 parent 8898781 commit fbf0b21
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions test/lib/zeitwerk/test_eager_load_dir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ class TestEagerLoadDir < LoaderTest
end

test "shortcircuits if eager loaded" do
with_setup([]) do
with_setup do
loader.eager_load

# Dirty way to prove we shortcircuit.
Expand All @@ -298,14 +298,14 @@ def loader.actual_eager_load_dir(*)
end

test "raises Zeitwerk::Error if the argument is not a directory" do
with_setup([]) do
with_setup do
e = assert_raises(Zeitwerk::Error) { loader.eager_load_dir(__FILE__) }
assert_equal "#{__FILE__} is not a directory", e.message
end
end

test "raises if the argument is not managed by the loader" do
with_setup([]) do
with_setup do
e = assert_raises(Zeitwerk::Error) { loader.eager_load_dir(__dir__) }
assert_equal "I do not manage #{__dir__}", e.message
end
Expand Down
6 changes: 3 additions & 3 deletions test/lib/zeitwerk/test_eager_load_namespace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class TestEagerLoadNamespaceWithObjectRootNamespace < LoaderTest
end

test "shortcircuits if eager loaded" do
with_setup([]) do
with_setup do
loader.eager_load

# Dirty way to prove we shortcircuit.
Expand Down Expand Up @@ -166,7 +166,7 @@ def loader.actual_eager_load_dir(*)
end

test "raises if the argument is not a class or module object" do
with_setup([]) do
with_setup do
e = assert_raises(Zeitwerk::Error) do
loader.eager_load_namespace(self.class.name)
end
Expand All @@ -175,7 +175,7 @@ def loader.actual_eager_load_dir(*)
end

test "raises if the argument is not a class or module object, even if eager loaded" do
with_setup([]) do
with_setup do
loader.eager_load
e = assert_raises(Zeitwerk::Error) do
loader.eager_load_namespace(self.class.name)
Expand Down
2 changes: 1 addition & 1 deletion test/lib/zeitwerk/test_load_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class TestLoadFile < LoaderTest

class TestLoadFileErrors < LoaderTest
test "raises if the argument does not exist" do
with_setup([]) do
with_setup do
e = assert_raises { loader.load_file("foo.rb") }
assert_equal "#{File.expand_path('foo.rb')} does not exist", e.message
end
Expand Down
4 changes: 2 additions & 2 deletions test/lib/zeitwerk/test_logging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,15 @@ def logger.debug(message)
end

test "logs when eager loading starts" do
with_setup([]) do
with_setup do
assert_logged(/eager load start/) do
loader.eager_load
end
end
end

test "logs when eager loading ends" do
with_setup([]) do
with_setup do
assert_logged(/eager load end/) do
loader.eager_load
end
Expand Down
2 changes: 1 addition & 1 deletion test/support/loader_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def with_load_path(dirs = loader.dirs)
dirs.each { |dir| $LOAD_PATH.delete(dir) }
end

def with_setup(files, dirs: ".", namespace: Object, load_path: nil, rm: true)
def with_setup(files = [], dirs: ".", namespace: Object, load_path: nil, rm: true)
with_files(files, rm: rm) do
Array(dirs).each { |dir| loader.push_dir(dir, namespace: namespace) }
loader.setup
Expand Down

0 comments on commit fbf0b21

Please sign in to comment.