Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test for "Better Method#inspect" introduced in Ruby 2.7 #793

Merged
merged 2 commits into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions core/method/fixtures/classes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
15 changes: 15 additions & 0 deletions core/method/shared/to_s.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@
@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
end

it "returns a String containing the Module the method is defined in" do
@string.should =~ /MethodSpecs::MyMod/
end
Expand Down