diff options
Diffstat (limited to 'spec/ruby/core/proc/shared')
-rw-r--r-- | spec/ruby/core/proc/shared/dup.rb | 23 | ||||
-rw-r--r-- | spec/ruby/core/proc/shared/equal.rb | 17 | ||||
-rw-r--r-- | spec/ruby/core/proc/shared/to_s.rb | 14 |
3 files changed, 30 insertions, 24 deletions
diff --git a/spec/ruby/core/proc/shared/dup.rb b/spec/ruby/core/proc/shared/dup.rb index 4480f3d0c9..c419a4078a 100644 --- a/spec/ruby/core/proc/shared/dup.rb +++ b/spec/ruby/core/proc/shared/dup.rb @@ -15,4 +15,27 @@ describe :proc_dup, shared: true do cl.new{}.send(@method).class.should == cl end end + + ruby_version_is "3.4" do + it "copies instance variables" do + proc = -> { "hello" } + proc.instance_variable_set(:@ivar, 1) + cl = proc.send(@method) + cl.instance_variables.should == [:@ivar] + end + + it "copies the finalizer" do + code = <<-RUBY + obj = Proc.new { } + + 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 diff --git a/spec/ruby/core/proc/shared/equal.rb b/spec/ruby/core/proc/shared/equal.rb index 0c0020ca7f..d0503fb064 100644 --- a/spec/ruby/core/proc/shared/equal.rb +++ b/spec/ruby/core/proc/shared/equal.rb @@ -81,20 +81,3 @@ describe :proc_equal, shared: true do p.send(@method, p2).should be_false end end - -describe :proc_equal_undefined, shared: true do - it "is not defined" do - Proc.should_not have_instance_method(@method, false) - end - - it "returns false if other is a dup of the original" do - p = proc { :foo } - p.send(@method, p.dup).should be_false - - p = Proc.new { :foo } - p.send(@method, p.dup).should be_false - - p = -> { :foo } - p.send(@method, p.dup).should be_false - end -end diff --git a/spec/ruby/core/proc/shared/to_s.rb b/spec/ruby/core/proc/shared/to_s.rb index f1e2f416fc..a52688a89f 100644 --- a/spec/ruby/core/proc/shared/to_s.rb +++ b/spec/ruby/core/proc/shared/to_s.rb @@ -31,13 +31,13 @@ describe :proc_to_s, shared: true do describe "for a proc created with UnboundMethod#to_proc" do it "returns a description including '(lambda)' and optionally including file and line number" do - def hello; end - s = method("hello").to_proc.send(@method) - if s.include? __FILE__ - s.should =~ /^#<Proc:([^ ]*?) #{Regexp.escape __FILE__}:#{__LINE__ - 3} \(lambda\)>$/ - else - s.should =~ /^#<Proc:([^ ]*?) \(lambda\)>$/ - end + def hello; end + s = method("hello").to_proc.send(@method) + if s.include? __FILE__ + s.should =~ /^#<Proc:([^ ]*?) #{Regexp.escape __FILE__}:#{__LINE__ - 3} \(lambda\)>$/ + else + s.should =~ /^#<Proc:([^ ]*?) \(lambda\)>$/ + end end it "has a binary encoding" do |