Expand Symbol#to_proc specs to be clearer

This commit is contained in:
Benoit Daloze 2020-02-22 14:43:52 +01:00
Родитель c7b71af9e2
Коммит 4aebb49153
1 изменённых файлов: 32 добавлений и 10 удалений

Просмотреть файл

@ -12,22 +12,44 @@ describe "Symbol#to_proc" do
:to_s.to_proc.call(obj).should == "Received #to_s"
end
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 == expected_arity
ruby_version_is ""..."2.8" do
it "returns a Proc with #lambda? false" do
pr = :to_s.to_proc
pr.lambda?.should == false
end
it "produces a Proc with arity -1" do
pr = :to_s.to_proc
pr.arity.should == -1
end
it "produces a Proc that always returns [[:rest]] for #parameters" do
pr = :to_s.to_proc
pr.parameters.should == [[:rest]]
end
end
ruby_version_is "2.8" do
it "returns a Proc with #lambda? true" do
pr = :to_s.to_proc
pr.lambda?.should == true
end
it "produces a Proc with arity -2" do
pr = :to_s.to_proc
pr.arity.should == -2
end
it "produces a Proc that always returns [[:req], [:rest]] for #parameters" do
pr = :to_s.to_proc
pr.parameters.should == [[:req], [:rest]]
end
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
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 == expected_parameters
end
it "passes along the block passed to Proc#call" do
klass = Class.new do
def m