1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Proc from Symbol needs a receiver

So its arity should be -2 instead of -1.

[Bug #16640]
https://bugs.ruby-lang.org/issues/16640#change-84337
This commit is contained in:
Nobuyoshi Nakada 2020-02-22 10:40:25 +09:00
parent 31748e69c8
commit 5b29ea0845
No known key found for this signature in database
GPG key ID: 4BC7D6DF58D8DF60
4 changed files with 19 additions and 8 deletions

View file

@ -12,18 +12,20 @@ describe "Symbol#to_proc" do
:to_s.to_proc.call(obj).should == "Received #to_s"
end
it "produces a proc with arity -1" do
expected_arity = ruby_version_is("2.8") {-2} || -1
it "produces a proc with arity #{expected_arity}" do
pr = :to_s.to_proc
pr.arity.should == -1
pr.arity.should == expected_arity
end
it "raises an ArgumentError when calling #call on the Proc without receiver" do
-> { :object_id.to_proc.call }.should raise_error(ArgumentError, "no receiver given")
end
it "produces a proc that always returns [[:rest]] for #parameters" do
expected_parameters = ruby_version_is("2.8") {[[:req], [:rest]]} || [[:rest]]
it "produces a proc that always returns #{expected_parameters} for #parameters" do
pr = :to_s.to_proc
pr.parameters.should == [[:rest]]
pr.parameters.should == expected_parameters
end
it "passes along the block passed to Proc#call" do