From 2f87f61cc35e9d52cb25c781e297a9cb622d8172 Mon Sep 17 00:00:00 2001 From: lxxxvi Date: Wed, 7 Oct 2020 13:11:56 +0200 Subject: [PATCH 1/2] add test for "Better Method#inspect" introduced in Ruby >= 2.7 https://bugs.ruby-lang.org/issues/14145 --- core/method/shared/to_s.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/method/shared/to_s.rb b/core/method/shared/to_s.rb index 0c0edc2f8c..8f86745abe 100644 --- a/core/method/shared/to_s.rb +++ b/core/method/shared/to_s.rb @@ -24,6 +24,13 @@ @string.should =~ /\#bar/ end + ruby_version_is "2.7" do + it "returns a String containing method arguments" do + m = MethodSpecs::Methods.new.method :two_req + m.send(@method).should =~ /\#two_req\(a, b\)/ + end + end + it "returns a String containing the Module the method is defined in" do @string.should =~ /MethodSpecs::MyMod/ end From be3f8c1cb6ac0a6e44842b2afe89488e0f7d0df7 Mon Sep 17 00:00:00 2001 From: lxxxvi Date: Wed, 7 Oct 2020 21:04:23 +0200 Subject: [PATCH 2/2] add tests for each kind of argument --- core/method/fixtures/classes.rb | 6 ++++++ core/method/shared/to_s.rb | 12 ++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/core/method/fixtures/classes.rb b/core/method/fixtures/classes.rb index f3b7ff921c..be96f65e25 100644 --- a/core/method/fixtures/classes.rb +++ b/core/method/fixtures/classes.rb @@ -50,6 +50,8 @@ def zero; end def one_req(a); end def two_req(a, b); end + def one_req_named(a:); end + def zero_with_block(&blk); end def one_req_with_block(a, &blk); end def two_req_with_block(a, b, &blk); end @@ -59,6 +61,8 @@ def one_req_one_opt(a, b=nil); end def one_req_two_opt(a, b=nil, c=nil); end def two_req_one_opt(a, b, c=nil); end + def one_opt_named(a: nil); end + def one_opt_with_block(a=nil, &blk); end def one_req_one_opt_with_block(a, b=nil, &blk); end def one_req_two_opt_with_block(a, b=nil, c=nil, &blk); end @@ -71,6 +75,8 @@ def one_req_one_opt_with_splat(a, b=nil, *c); end def two_req_one_opt_with_splat(a, b, c=nil, *d); end def one_req_two_opt_with_splat(a, b=nil, c=nil, *d); end + def zero_with_double_splat(**a); end + def zero_with_splat_and_block(*a, &blk); end def one_req_with_splat_and_block(a, *b, &blk); end def two_req_with_splat_and_block(a, b, *c, &blk); end diff --git a/core/method/shared/to_s.rb b/core/method/shared/to_s.rb index 8f86745abe..4354e7b98b 100644 --- a/core/method/shared/to_s.rb +++ b/core/method/shared/to_s.rb @@ -26,8 +26,16 @@ ruby_version_is "2.7" do it "returns a String containing method arguments" do - m = MethodSpecs::Methods.new.method :two_req - m.send(@method).should =~ /\#two_req\(a, b\)/ + 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 end