diff options
author | Marc-Andre Lafortune <github@marc-andre.ca> | 2020-09-01 21:22:20 -0400 |
---|---|---|
committer | Marc-André Lafortune <github@marc-andre.ca> | 2020-09-02 00:05:14 -0400 |
commit | 5e16857315bf55307c5fc887ca6f03bfa0630a93 (patch) | |
tree | d42bcc39f4cdfb958d620f3d1389f2aa677b77cb /spec/ruby/core | |
parent | 11922b5e030808b16fd2c604637e046b2d01b0f0 (diff) | |
download | ruby-5e16857315bf55307c5fc887ca6f03bfa0630a93.tar.gz |
Fix constant names set using const_set on a singleton class
Fixes [Bug #14895]
Diffstat (limited to 'spec/ruby/core')
-rw-r--r-- | spec/ruby/core/module/const_set_spec.rb | 18 | ||||
-rw-r--r-- | spec/ruby/core/module/name_spec.rb | 18 |
2 files changed, 28 insertions, 8 deletions
diff --git a/spec/ruby/core/module/const_set_spec.rb b/spec/ruby/core/module/const_set_spec.rb index 77a2e59a13..b537d3f133 100644 --- a/spec/ruby/core/module/const_set_spec.rb +++ b/spec/ruby/core/module/const_set_spec.rb @@ -20,10 +20,20 @@ describe "Module#const_set" do m.name.should == "ConstantSpecs::CS_CONST1000" end - it "does not set the name of a module scoped by an anonymous module" do - a, b = Module.new, Module.new - a.const_set :B, b - b.name.should be_nil + ruby_version_is ""..."3.0" do + it "does not set the name of a module scoped by an anonymous module" do + a, b = Module.new, Module.new + a.const_set :B, b + b.name.should be_nil + end + end + + ruby_version_is "3.0" do + it "sets the name of a module scoped by an anonymous module" do + a, b = Module.new, Module.new + a.const_set :B, b + b.name.should.end_with? '::B' + end end it "sets the name of contained modules when assigning a toplevel anonymous module" do diff --git a/spec/ruby/core/module/name_spec.rb b/spec/ruby/core/module/name_spec.rb index ae8037555b..ca9106a973 100644 --- a/spec/ruby/core/module/name_spec.rb +++ b/spec/ruby/core/module/name_spec.rb @@ -6,10 +6,20 @@ describe "Module#name" do Module.new.name.should be_nil end - it "is nil when assigned to a constant in an anonymous module" do - m = Module.new - m::N = Module.new - m::N.name.should be_nil + ruby_version_is ""..."3.0" do + it "is nil when assigned to a constant in an anonymous module" do + m = Module.new + m::N = Module.new + m::N.name.should be_nil + end + end + + ruby_version_is "3.0" do + it "is not nil when assigned to a constant in an anonymous module" do + m = Module.new + m::N = Module.new + m::N.name.should.end_with? '::N' + end end it "is not nil for a nested module created with the module keyword" do |