summaryrefslogtreecommitdiff
path: root/spec/ruby/language
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2020-05-04 16:56:45 +0200
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-05-26 14:10:33 +0900
commit385ac07fd8f5a50825aee8db459086e617f492aa (patch)
treefc1d12126f2f04cb5032e9e7329157dabb6ef6d6 /spec/ruby/language
parent4e1f2283b432e833bd4e6f7724ba0496760e68e8 (diff)
Use receiver #name rather than #inspect to build NameError message
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3080
Diffstat (limited to 'spec/ruby/language')
-rw-r--r--spec/ruby/language/constants_spec.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/spec/ruby/language/constants_spec.rb b/spec/ruby/language/constants_spec.rb
index 95b0dcace9..47897234b9 100644
--- a/spec/ruby/language/constants_spec.rb
+++ b/spec/ruby/language/constants_spec.rb
@@ -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