Skip to content

Commit

Permalink
Add a test for Zeitwerk::NameError
Browse files Browse the repository at this point in the history
  • Loading branch information
fxn committed Apr 2, 2024
1 parent 4082b45 commit 36e44fc
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/lib/zeitwerk/test_exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ def assert_error_message(message, error)
end
end

test "raises NameError if the expected constant is not defined (namespace, overridden name)" do
files = [["m.rb", <<~RUBY], ["m/typo.rb", "M::TyPo = 1"]]
module M
def self.name
"OVERRIDDEN"
end
end
RUBY
with_setup(files) do
typo_rb = File.expand_path("m/typo.rb")
error = assert_raises(Zeitwerk::NameError) { M::Typo }
assert_error_message "expected #{typo_rb} to define Typo in the M namespace", error
assert_equal :Typo, error.name
end
end

test "eager loading raises NameError if files do not define the expected constants (top-level)" do
files = [["x.rb", ""]]
with_setup(files) do
Expand Down

0 comments on commit 36e44fc

Please sign in to comment.