diff options
author | Benoit Daloze <eregontp@gmail.com> | 2023-07-06 13:32:23 +0200 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2023-07-06 18:27:13 +0200 |
commit | e76022f41cd74d297189d85d74a18d9e7821fd94 (patch) | |
tree | e8e575df7749e466623d1be9f3c40f23eb6aa272 /spec | |
parent | 2acb44e0440327ee5fea8d324fa6c121214e6b96 (diff) | |
download | ruby-e76022f41cd74d297189d85d74a18d9e7821fd94.tar.gz |
Specs for Module#set_temporary_name should be in their own file
Diffstat (limited to 'spec')
-rw-r--r-- | spec/ruby/core/module/name_spec.rb | 49 | ||||
-rw-r--r-- | spec/ruby/core/module/set_temporary_name_spec.rb | 53 |
2 files changed, 53 insertions, 49 deletions
diff --git a/spec/ruby/core/module/name_spec.rb b/spec/ruby/core/module/name_spec.rb index bb7fa1761c..0d1f4e24d5 100644 --- a/spec/ruby/core/module/name_spec.rb +++ b/spec/ruby/core/module/name_spec.rb @@ -6,55 +6,6 @@ describe "Module#name" do Module.new.name.should be_nil end - ruby_version_is "3.3" do - it "can assign a temporary name" do - m = Module.new - m.name.should be_nil - - m.set_temporary_name("fake_name") - m.name.should == "fake_name" - - m.set_temporary_name(nil) - m.name.should be_nil - end - - it "can't assign empty string as name" do - m = Module.new - -> { m.set_temporary_name("") }.should raise_error(ArgumentError, "empty class/module name") - end - - it "can't assign a constant name as a temporary name" do - m = Module.new - -> { m.set_temporary_name("Object") }.should raise_error(ArgumentError, "name must not be valid constant name") - end - - it "can't assign name to permanent module" do - -> { Object.set_temporary_name("fake_name") }.should raise_error(RuntimeError, "can't change permanent name") - end - - it "can assign a temporary name to a nested module" do - m = Module.new - module m::N; end - m::N.name.should =~ /\A#<Module:0x\h+>::N\z/ - - m::N.set_temporary_name("fake_name") - m::N.name.should == "fake_name" - - m::N.set_temporary_name(nil) - m::N.name.should be_nil - end - - it "can update the name when assigned to a constant" do - m = Module.new - m::N = Module.new - m::N.name.should =~ /\A#<Module:0x\h+>::N\z/ - m::N.set_temporary_name(nil) - - m::M = m::N - m::M.name.should =~ /\A#<Module:0x\h+>::M\z/m - end - end - it "is not nil when assigned to a constant in an anonymous module" do m = Module.new m::N = Module.new diff --git a/spec/ruby/core/module/set_temporary_name_spec.rb b/spec/ruby/core/module/set_temporary_name_spec.rb new file mode 100644 index 0000000000..891a363ea2 --- /dev/null +++ b/spec/ruby/core/module/set_temporary_name_spec.rb @@ -0,0 +1,53 @@ +require_relative '../../spec_helper' +require_relative 'fixtures/module' + +ruby_version_is "3.3" do + describe "Module#set_temporary_name" do + it "can assign a temporary name" do + m = Module.new + m.name.should be_nil + + m.set_temporary_name("fake_name") + m.name.should == "fake_name" + + m.set_temporary_name(nil) + m.name.should be_nil + end + + it "can't assign empty string as name" do + m = Module.new + -> { m.set_temporary_name("") }.should raise_error(ArgumentError, "empty class/module name") + end + + it "can't assign a constant name as a temporary name" do + m = Module.new + -> { m.set_temporary_name("Object") }.should raise_error(ArgumentError, "name must not be valid constant name") + end + + it "can't assign name to permanent module" do + -> { Object.set_temporary_name("fake_name") }.should raise_error(RuntimeError, "can't change permanent name") + end + + it "can assign a temporary name to a nested module" do + m = Module.new + module m::N; end + m::N.name.should =~ /\A#<Module:0x\h+>::N\z/ + + m::N.set_temporary_name("fake_name") + m::N.name.should == "fake_name" + + m::N.set_temporary_name(nil) + m::N.name.should be_nil + end + + it "can update the name when assigned to a constant" do + m = Module.new + m::N = Module.new + m::N.name.should =~ /\A#<Module:0x\h+>::N\z/ + m::N.set_temporary_name(nil) + + m::M = m::N + m::M.name.should =~ /\A#<Module:0x\h+>::M\z/m + end + end +end |