diff options
author | Benoit Daloze <eregontp@gmail.com> | 2020-02-22 14:43:52 +0100 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2020-02-22 14:43:52 +0100 |
commit | 4aebb491536ad9c7bca6c0e264604aa90e701ef0 (patch) | |
tree | 1921e6966013528bc740a7a10ea47209011428bd /spec | |
parent | c7b71af9e21b3f0b8fe413a3c20cf4bd633c40d0 (diff) | |
download | ruby-4aebb491536ad9c7bca6c0e264604aa90e701ef0.tar.gz |
Expand Symbol#to_proc specs to be clearer
Diffstat (limited to 'spec')
-rw-r--r-- | spec/ruby/core/symbol/to_proc_spec.rb | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/spec/ruby/core/symbol/to_proc_spec.rb b/spec/ruby/core/symbol/to_proc_spec.rb index 27eb6970c4..6651022375 100644 --- a/spec/ruby/core/symbol/to_proc_spec.rb +++ b/spec/ruby/core/symbol/to_proc_spec.rb @@ -12,20 +12,42 @@ 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 - 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") + 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 - 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 + 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 "passes along the block passed to Proc#call" do |