diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-06-19 08:45:17 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-06-19 08:45:17 +0000 |
commit | 9d556662256c43e3f405b4c852c326ed649ca88e (patch) | |
tree | ea7684760fa4fc4f962d0510006fc333e14276d6 /spec/ruby/language/constants_spec.rb | |
parent | 1b474b869ccc3e93335e5b7ad01513d58f1fe1a3 (diff) | |
download | ruby-9d556662256c43e3f405b4c852c326ed649ca88e.tar.gz |
describe about NameError by #private_constant
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63697 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/language/constants_spec.rb')
-rw-r--r-- | spec/ruby/language/constants_spec.rb | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/spec/ruby/language/constants_spec.rb b/spec/ruby/language/constants_spec.rb index 4e0df9fd6d..98077171ec 100644 --- a/spec/ruby/language/constants_spec.rb +++ b/spec/ruby/language/constants_spec.rb @@ -613,6 +613,41 @@ describe "Module#private_constant marked constants" do defined?(PRIVATE_CONSTANT_IN_OBJECT).should == "constant" end end + + describe "NameError by #private_constant" do + it "has :receiver and :name attributes" do + lambda do + ConstantVisibility::PrivConstClass::PRIVATE_CONSTANT_CLASS + end.should raise_error(NameError) {|e| + e.receiver.should == ConstantVisibility::PrivConstClass + e.name.should == :PRIVATE_CONSTANT_CLASS + } + + lambda do + ConstantVisibility::PrivConstModule::PRIVATE_CONSTANT_MODULE + end.should raise_error(NameError) {|e| + e.receiver.should == ConstantVisibility::PrivConstModule + e.name.should == :PRIVATE_CONSTANT_MODULE + } + end + + it "has the defined class as the :name attribute" do + exception = nil + lambda do + ConstantVisibility::PrivConstClassChild::PRIVATE_CONSTANT_CLASS + end.should raise_error(NameError) {|e| + e.receiver.should == ConstantVisibility::PrivConstClass + e.name.should == :PRIVATE_CONSTANT_CLASS + } + + lambda do + ConstantVisibility::PrivConstModuleChild::PRIVATE_CONSTANT_MODULE + end.should raise_error(NameError) {|e| + e.receiver.should == ConstantVisibility::PrivConstModule + e.name.should == :PRIVATE_CONSTANT_MODULE + } + end + end end describe "Module#public_constant marked constants" do |