diff options
Diffstat (limited to 'spec/ruby/core/method/shared')
-rw-r--r-- | spec/ruby/core/method/shared/dup.rb | 32 | ||||
-rw-r--r-- | spec/ruby/core/method/shared/to_s.rb | 56 |
2 files changed, 56 insertions, 32 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 diff --git a/spec/ruby/core/method/shared/to_s.rb b/spec/ruby/core/method/shared/to_s.rb index 0dcae41b59..b2d27d370f 100644 --- a/spec/ruby/core/method/shared/to_s.rb +++ b/spec/ruby/core/method/shared/to_s.rb @@ -24,19 +24,17 @@ describe :method_to_s, shared: true do @string.should =~ /\#bar/ end - ruby_version_is "2.7" do - it "returns a String containing method arguments" do - obj = MethodSpecs::Methods.new - obj.method(:zero).send(@method).should.include?("()") - obj.method(:one_req).send(@method).should.include?("(a)") - obj.method(:one_req_named).send(@method).should.include?("(a:)") - obj.method(:zero_with_block).send(@method).should.include?("(&blk)") - obj.method(:one_opt).send(@method).should.include?("(a=...)") - obj.method(:one_opt_named).send(@method).should.include?("(a: ...)") - obj.method(:zero_with_splat).send(@method).should.include?("(*a)") - obj.method(:zero_with_double_splat).send(@method).should.include?("(**a)") - obj.method(:one_req_one_opt_with_splat_and_block).send(@method).should.include?("(a, b=..., *c, &blk)") - end + it "returns a String containing method arguments" do + obj = MethodSpecs::Methods.new + obj.method(:zero).send(@method).should.include?("()") + obj.method(:one_req).send(@method).should.include?("(a)") + obj.method(:one_req_named).send(@method).should.include?("(a:)") + obj.method(:zero_with_block).send(@method).should.include?("(&blk)") + obj.method(:one_opt).send(@method).should.include?("(a=...)") + obj.method(:one_opt_named).send(@method).should.include?("(a: ...)") + obj.method(:zero_with_splat).send(@method).should.include?("(*a)") + obj.method(:zero_with_double_splat).send(@method).should.include?("(**a)") + obj.method(:one_req_one_opt_with_splat_and_block).send(@method).should.include?("(a, b=..., *c, &blk)") end it "returns a String containing the Module the method is defined in" do @@ -55,20 +53,18 @@ describe :method_to_s, shared: true do MethodSpecs::A.new.method(:baz).send(@method).should.start_with? "#<Method: MethodSpecs::A#baz" end - ruby_version_is '3.0' do - it "returns a String containing the Module containing the method if object has a singleton class but method is not defined in the singleton class" do - obj = MethodSpecs::MySub.new - obj.singleton_class - @m = obj.method(:bar) - @string = @m.send(@method) - @string.should.start_with? "#<Method: MethodSpecs::MySub(MethodSpecs::MyMod)#bar" + it "returns a String containing the Module containing the method if object has a singleton class but method is not defined in the singleton class" do + obj = MethodSpecs::MySub.new + obj.singleton_class + @m = obj.method(:bar) + @string = @m.send(@method) + @string.should.start_with? "#<Method: MethodSpecs::MySub(MethodSpecs::MyMod)#bar" - c = MethodSpecs::MySub.dup - m = Module.new{def bar; end} - c.extend(m) - @string = c.method(:bar).send(@method) - @string.should.start_with? "#<Method: #<Class:#{c.inspect}>(#{m.inspect})#bar" - end + c = MethodSpecs::MySub.dup + m = Module.new{def bar; end} + c.extend(m) + @string = c.method(:bar).send(@method) + @string.should.start_with? "#<Method: #<Class:#{c.inspect}>(#{m.inspect})#bar" end it "returns a String containing the singleton class if method is defined in the singleton class" do @@ -79,11 +75,7 @@ describe :method_to_s, shared: true do @string.should.start_with? "#<Method: #<MethodSpecs::MySub:0xXXXXXX>.bar" end - ruby_version_is '2.7' do - ruby_bug '#17428', '2.7'...'3.0' do - it "shows the metaclass and the owner for a Module instance method retrieved from a class" do - String.method(:include).inspect.should.start_with?("#<Method: #<Class:String>(Module)#include") - end - end + it "shows the metaclass and the owner for a Module instance method retrieved from a class" do + String.method(:include).inspect.should.start_with?("#<Method: #<Class:String>(Module)#include") end end |