summaryrefslogtreecommitdiff
path: root/spec/ruby/core/method/shared
diff options
context:
space:
mode:
authorJean Boussier <[email protected]>2024-02-12 12:03:36 +0100
committerJean Boussier <[email protected]>2024-02-12 18:31:48 +0100
commitde1a586ecc2ee7f465f0c0a69291054136a3a819 (patch)
treed6825acfea6f796b5f5dbb2746fe7fcb1c07d580 /spec/ruby/core/method/shared
parentc04782c2cb56c512e1d1b34630cb942da3aeb366 (diff)
proc.c: get rid of `CLONESETUP`
[Bug #20253] All the way down to Ruby 1.9, `Proc`, `Method`, `UnboundMethod` and `Binding` always had their own specific clone and dup routine. This caused various discrepancies with how other objects behave on `dup` and `clone. [Bug #20250], [Bug #20253]. This commit get rid of `CLONESETUP` and use the the same codepath as all other types, so ensure consistency. NB: It's still not accepting the `freeze` keyword argument on `clone`. Co-Authored-By: Étienne Barrié <[email protected]>
Diffstat (limited to 'spec/ruby/core/method/shared')
-rw-r--r--spec/ruby/core/method/shared/dup.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/spec/ruby/core/method/shared/dup.rb b/spec/ruby/core/method/shared/dup.rb
new file mode 100644
index 0000000000..1a10b90689
--- /dev/null
+++ b/spec/ruby/core/method/shared/dup.rb
@@ -0,0 +1,32 @@
+describe :method_dup, shared: true do
+ it "returns a copy of self" do
+ a = Object.new.method(:method)
+ b = a.send(@method)
+
+ a.should == b
+ a.should_not equal(b)
+ end
+
+ ruby_version_is "3.4" do
+ it "copies instance variables" do
+ method = Object.new.method(:method)
+ method.instance_variable_set(:@ivar, 1)
+ cl = method.send(@method)
+ cl.instance_variables.should == [:@ivar]
+ end
+
+ it "copies the finalizer" do
+ code = <<-RUBY
+ obj = Object.new.method(:method)
+
+ ObjectSpace.define_finalizer(obj, Proc.new { STDOUT.write "finalized\n" })
+
+ obj.clone
+
+ exit 0
+ RUBY
+
+ ruby_exe(code).lines.sort.should == ["finalized\n", "finalized\n"]
+ end
+ end
+end