[前][次][番号順一覧][スレッド一覧]

ruby-changes:60164

From: Benoit <ko1@a...>
Date: Sat, 22 Feb 2020 22:44:46 +0900 (JST)
Subject: [ruby-changes:60164] 4aebb49153 (master): Expand Symbol#to_proc specs to be clearer

https://git.ruby-lang.org/ruby.git/commit/?id=4aebb49153

From 4aebb491536ad9c7bca6c0e264604aa90e701ef0 Mon Sep 17 00:00:00 2001
From: Benoit Daloze <eregontp@g...>
Date: Sat, 22 Feb 2020 14:43:52 +0100
Subject: Expand Symbol#to_proc specs to be clearer


diff --git a/spec/ruby/core/symbol/to_proc_spec.rb b/spec/ruby/core/symbol/to_proc_spec.rb
index 27eb697..6651022 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 https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/symbol/to_proc_spec.rb#L12
     :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
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]