1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Use receiver #name rather than #inspect to build NameError message

This commit is contained in:
Jean Boussier 2020-05-04 16:56:45 +02:00 committed by Nobuyoshi Nakada
parent 4e1f2283b4
commit 385ac07fd8
Notes: git 2020-05-26 14:10:58 +09:00
2 changed files with 44 additions and 1 deletions

View file

@ -154,6 +154,36 @@ describe "Literal (A::X) constant resolution" do
-> { ConstantSpecs::ParentA::CS_CONSTX }.should raise_error(NameError)
end
ruby_version_is "2.8" do
it "uses the module or class #name to craft the error message" do
mod = Module.new do
def self.name
"ModuleName"
end
def self.inspect
"<unusable info>"
end
end
-> { mod::DOES_NOT_EXIST }.should raise_error(NameError, /uninitialized constant ModuleName::DOES_NOT_EXIST/)
end
it "uses the module or class #inspect to craft the error message if they are anonymous" do
mod = Module.new do
def self.name
nil
end
def self.inspect
"<unusable info>"
end
end
-> { mod::DOES_NOT_EXIST }.should raise_error(NameError, /uninitialized constant <unusable info>::DOES_NOT_EXIST/)
end
end
it "sends #const_missing to the original class or module scope" do
ConstantSpecs::ClassA::CS_CONSTX.should == :CS_CONSTX
end