зеркало из https://github.com/github/ruby.git
Expand Symbol#to_proc specs to be clearer
This commit is contained in:
Родитель
c7b71af9e2
Коммит
4aebb49153
|
@ -12,22 +12,44 @@ describe "Symbol#to_proc" do
|
||||||
:to_s.to_proc.call(obj).should == "Received #to_s"
|
:to_s.to_proc.call(obj).should == "Received #to_s"
|
||||||
end
|
end
|
||||||
|
|
||||||
expected_arity = ruby_version_is("2.8") {-2} || -1
|
ruby_version_is ""..."2.8" do
|
||||||
it "produces a proc with arity #{expected_arity}" do
|
it "returns a Proc with #lambda? false" do
|
||||||
pr = :to_s.to_proc
|
pr = :to_s.to_proc
|
||||||
pr.arity.should == expected_arity
|
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
|
end
|
||||||
|
|
||||||
it "raises an ArgumentError when calling #call on the Proc without receiver" do
|
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")
|
-> { :object_id.to_proc.call }.should raise_error(ArgumentError, "no receiver given")
|
||||||
end
|
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
|
it "passes along the block passed to Proc#call" do
|
||||||
klass = Class.new do
|
klass = Class.new do
|
||||||
def m
|
def m
|
||||||
|
|
Загрузка…
Ссылка в новой задаче