summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2019-09-26 10:41:43 +0200
committerBenoit Daloze <eregontp@gmail.com>2019-09-26 13:25:23 +0200
commit9d0866c7d7b9cbe36a851744a37806e747e0e7a8 (patch)
tree0a5feb4dc71cf8fd4604c4e524a7ee2c360b3138 /spec
parentc8f71686533cf068ad2f7a2e9fbb95a5c9f44642 (diff)
[EXPERIMENTAL] Make Module#name return a frozen String
* Always the same frozen String for a given Module or Class. * Avoids extra allocations whenever calling Module#name. * See [Feature #16150]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/2487
Diffstat (limited to 'spec')
-rw-r--r--spec/ruby/core/module/name_spec.rb24
1 files changed, 19 insertions, 5 deletions
diff --git a/spec/ruby/core/module/name_spec.rb b/spec/ruby/core/module/name_spec.rb
index d64684319c..36a91f5be5 100644
--- a/spec/ruby/core/module/name_spec.rb
+++ b/spec/ruby/core/module/name_spec.rb
@@ -102,13 +102,27 @@ describe "Module#name" do
m::N.name.should == "ModuleSpecs::Anonymous::E::N"
end
- it "returns a mutable string" do
- ModuleSpecs.name.frozen?.should be_false
+ ruby_version_is ""..."2.7" do
+ it "returns a mutable string" do
+ ModuleSpecs.name.frozen?.should be_false
+ end
+
+ it "returns a mutable string that when mutated does not modify the original module name" do
+ ModuleSpecs.name << "foo"
+
+ ModuleSpecs.name.should == "ModuleSpecs"
+ end
end
- it "returns a mutable string that when mutated does not modify the original module name" do
- ModuleSpecs.name << "foo"
+ ruby_version_is "2.7" do
+ it "returns a frozen String" do
+ ModuleSpecs.name.frozen?.should == true
+ end
- ModuleSpecs.name.should == "ModuleSpecs"
+ it "always returns the same String for a given Module" do
+ s1 = ModuleSpecs.name
+ s2 = ModuleSpecs.name
+ s1.should equal(s2)
+ end
end
end