summaryrefslogtreecommitdiff
path: root/spec/ruby/core/proc
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/proc')
-rw-r--r--spec/ruby/core/proc/call_spec.rb142
-rw-r--r--spec/ruby/core/proc/case_compare_spec.rb15
-rw-r--r--spec/ruby/core/proc/element_reference_spec.rb24
-rw-r--r--spec/ruby/core/proc/eql_spec.rb5
-rw-r--r--spec/ruby/core/proc/equal_value_spec.rb81
-rw-r--r--spec/ruby/core/proc/fixtures/proc_aref.rb10
-rw-r--r--spec/ruby/core/proc/fixtures/proc_aref_frozen.rb10
-rw-r--r--spec/ruby/core/proc/fixtures/proc_call.rb10
-rw-r--r--spec/ruby/core/proc/fixtures/proc_call_frozen.rb10
-rw-r--r--spec/ruby/core/proc/inspect_spec.rb5
-rw-r--r--spec/ruby/core/proc/shared/call.rb99
-rw-r--r--spec/ruby/core/proc/shared/call_arguments.rb29
-rw-r--r--spec/ruby/core/proc/shared/equal.rb83
-rw-r--r--spec/ruby/core/proc/shared/to_s.rb60
-rw-r--r--spec/ruby/core/proc/to_s_spec.rb60
-rw-r--r--spec/ruby/core/proc/yield_spec.rb15
16 files changed, 303 insertions, 355 deletions
diff --git a/spec/ruby/core/proc/call_spec.rb b/spec/ruby/core/proc/call_spec.rb
index 6ec2fc8682..8b65be97c9 100644
--- a/spec/ruby/core/proc/call_spec.rb
+++ b/spec/ruby/core/proc/call_spec.rb
@@ -1,16 +1,138 @@
require_relative '../../spec_helper'
-require_relative 'shared/call'
-require_relative 'shared/call_arguments'
+require_relative 'fixtures/common'
+require_relative 'fixtures/proc_call'
+require_relative 'fixtures/proc_call_frozen'
describe "Proc#call" do
- it_behaves_like :proc_call, :call
- it_behaves_like :proc_call_block_args, :call
-end
+ it "invokes self" do
+ Proc.new { "test!" }.call.should == "test!"
+ -> { "test!" }.call.should == "test!"
+ proc { "test!" }.call.should == "test!"
+ end
-describe "Proc#call on a Proc created with Proc.new" do
- it_behaves_like :proc_call_on_proc_new, :call
-end
+ it "sets self's parameters to the given values" do
+ Proc.new { |a, b| a + b }.call(1, 2).should == 3
+ Proc.new { |*args| args }.call(1, 2, 3, 4).should == [1, 2, 3, 4]
+ Proc.new { |_, *args| args }.call(1, 2, 3).should == [2, 3]
+
+ -> a, b { a + b }.call(1, 2).should == 3
+ -> *args { args }.call(1, 2, 3, 4).should == [1, 2, 3, 4]
+ -> _, *args { args }.call(1, 2, 3).should == [2, 3]
+
+ proc { |a, b| a + b }.call(1, 2).should == 3
+ proc { |*args| args }.call(1, 2, 3, 4).should == [1, 2, 3, 4]
+ proc { |_, *args| args }.call(1, 2, 3).should == [2, 3]
+ end
+
+ it "can receive block arguments" do
+ Proc.new {|&b| b.call}.call {1 + 1}.should == 2
+ -> &b { b.call}.call {1 + 1}.should == 2
+ proc {|&b| b.call}.call {1 + 1}.should == 2
+ end
+
+ it "yields to the block given at declaration and not to the block argument" do
+ proc_creator = Object.new
+ def proc_creator.create
+ Proc.new do |&b|
+ yield
+ end
+ end
+ a_proc = proc_creator.create { 7 }
+ a_proc.call { 3 }.should == 7
+ end
+
+ it "can call its block argument declared with a block argument" do
+ proc_creator = Object.new
+ def proc_creator.create(method_name)
+ Proc.new do |&b|
+ yield + b.send(method_name)
+ end
+ end
+ a_proc = proc_creator.create(:call) { 7 }
+ a_proc.call { 3 }.should == 10
+ end
+
+ describe "on a Proc created with frozen_string_literal: true/false" do
+ it "doesn't duplicate frozen strings" do
+ ProcCallSpecs.call.frozen?.should == false
+ ProcCallSpecs.call_freeze.frozen?.should == true
+ ProcCallFrozenSpecs.call.frozen?.should == true
+ ProcCallFrozenSpecs.call_freeze.frozen?.should == true
+ end
+ end
+
+ context "on a Proc created with Proc.new" do
+ it "replaces missing arguments with nil" do
+ Proc.new { |a, b| [a, b] }.call.should == [nil, nil]
+ Proc.new { |a, b| [a, b] }.call(1).should == [1, nil]
+ end
+
+ it "silently ignores extra arguments" do
+ Proc.new { |a, b| a + b }.call(1, 2, 5).should == 3
+ end
+
+ it "auto-explodes a single Array argument" do
+ p = Proc.new { |a, b| [a, b] }
+ p.call(1, 2).should == [1, 2]
+ p.call([1, 2]).should == [1, 2]
+ p.call([1, 2, 3]).should == [1, 2]
+ p.call([1, 2, 3], 4).should == [[1, 2, 3], 4]
+ end
+ end
+
+ context "on a Proc created with Kernel#lambda or Kernel#proc" do
+ it "ignores excess arguments when self is a proc" do
+ a = proc {|x| x}.call(1, 2)
+ a.should == 1
+
+ a = proc {|x| x}.call(1, 2, 3)
+ a.should == 1
+
+ a = proc {|x:| x}.call(2, x: 1)
+ a.should == 1
+ end
+
+ it "will call #to_ary on argument and return self if return is nil" do
+ argument = ProcSpecs::ToAryAsNil.new
+ result = proc { |x, _| x }.call(argument)
+ result.should == argument
+ end
+
+ it "substitutes nil for missing arguments when self is a proc" do
+ proc {|x,y| [x,y]}.call.should == [nil,nil]
+
+ a = proc {|x,y| [x, y]}.call(1)
+ a.should == [1,nil]
+ end
+
+ it "raises an ArgumentError on excess arguments when self is a lambda" do
+ -> {
+ -> x { x }.call(1, 2)
+ }.should.raise(ArgumentError)
+
+ -> {
+ -> x { x }.call(1, 2, 3)
+ }.should.raise(ArgumentError)
+ end
+
+ it "raises an ArgumentError on missing arguments when self is a lambda" do
+ -> {
+ -> x { x }.call
+ }.should.raise(ArgumentError)
+
+ -> {
+ -> x, y { [x,y] }.call(1)
+ }.should.raise(ArgumentError)
+ end
+
+ it "treats a single Array argument as a single argument when self is a lambda" do
+ -> a { a }.call([1, 2]).should == [1, 2]
+ -> a, b { [a, b] }.call([1, 2], 3).should == [[1,2], 3]
+ end
-describe "Proc#call on a Proc created with Kernel#lambda or Kernel#proc" do
- it_behaves_like :proc_call_on_proc_or_lambda, :call
+ it "treats a single Array argument as a single argument when self is a proc" do
+ proc { |a| a }.call([1, 2]).should == [1, 2]
+ proc { |a, b| [a, b] }.call([1, 2], 3).should == [[1,2], 3]
+ end
+ end
end
diff --git a/spec/ruby/core/proc/case_compare_spec.rb b/spec/ruby/core/proc/case_compare_spec.rb
index f11513cdb9..421afb24f0 100644
--- a/spec/ruby/core/proc/case_compare_spec.rb
+++ b/spec/ruby/core/proc/case_compare_spec.rb
@@ -1,16 +1,7 @@
require_relative '../../spec_helper'
-require_relative 'shared/call'
-require_relative 'shared/call_arguments'
describe "Proc#===" do
- it_behaves_like :proc_call, :===
- it_behaves_like :proc_call_block_args, :===
-end
-
-describe "Proc#=== on a Proc created with Proc.new" do
- it_behaves_like :proc_call_on_proc_new, :===
-end
-
-describe "Proc#=== on a Proc created with Kernel#lambda or Kernel#proc" do
- it_behaves_like :proc_call_on_proc_or_lambda, :===
+ it "is an alias of Proc#call" do
+ Proc.instance_method(:===).should == Proc.instance_method(:call)
+ end
end
diff --git a/spec/ruby/core/proc/element_reference_spec.rb b/spec/ruby/core/proc/element_reference_spec.rb
index ea3a915a11..ac14292464 100644
--- a/spec/ruby/core/proc/element_reference_spec.rb
+++ b/spec/ruby/core/proc/element_reference_spec.rb
@@ -1,27 +1,7 @@
require_relative '../../spec_helper'
-require_relative 'shared/call'
-require_relative 'shared/call_arguments'
-require_relative 'fixtures/proc_aref'
-require_relative 'fixtures/proc_aref_frozen'
describe "Proc#[]" do
- it_behaves_like :proc_call, :[]
- it_behaves_like :proc_call_block_args, :[]
-end
-
-describe "Proc#call on a Proc created with Proc.new" do
- it_behaves_like :proc_call_on_proc_new, :call
-end
-
-describe "Proc#call on a Proc created with Kernel#lambda or Kernel#proc" do
- it_behaves_like :proc_call_on_proc_or_lambda, :call
-end
-
-describe "Proc#[] with frozen_string_literal: true/false" do
- it "doesn't duplicate frozen strings" do
- ProcArefSpecs.aref.frozen?.should == false
- ProcArefSpecs.aref_freeze.frozen?.should == true
- ProcArefFrozenSpecs.aref.frozen?.should == true
- ProcArefFrozenSpecs.aref_freeze.frozen?.should == true
+ it "is an alias of Proc#call" do
+ Proc.instance_method(:[]).should == Proc.instance_method(:call)
end
end
diff --git a/spec/ruby/core/proc/eql_spec.rb b/spec/ruby/core/proc/eql_spec.rb
index ad8f6749fc..1a5fb42a0e 100644
--- a/spec/ruby/core/proc/eql_spec.rb
+++ b/spec/ruby/core/proc/eql_spec.rb
@@ -1,6 +1,7 @@
require_relative '../../spec_helper'
-require_relative 'shared/equal'
describe "Proc#eql?" do
- it_behaves_like :proc_equal, :eql?
+ it "is an alias of Proc#==" do
+ Proc.instance_method(:eql?).should == Proc.instance_method(:==)
+ end
end
diff --git a/spec/ruby/core/proc/equal_value_spec.rb b/spec/ruby/core/proc/equal_value_spec.rb
index ec7f274732..92e462152e 100644
--- a/spec/ruby/core/proc/equal_value_spec.rb
+++ b/spec/ruby/core/proc/equal_value_spec.rb
@@ -1,6 +1,83 @@
require_relative '../../spec_helper'
-require_relative 'shared/equal'
+require_relative 'fixtures/common'
describe "Proc#==" do
- it_behaves_like :proc_equal, :==
+ it "is a public method" do
+ Proc.public_instance_methods(false).should.include?(:==)
+ end
+
+ it "returns true if self and other are the same object" do
+ p = proc { :foo }
+ (p == p).should == true
+
+ p = Proc.new { :foo }
+ (p == p).should == true
+
+ p = -> { :foo }
+ (p == p).should == true
+ end
+
+ it "returns true if other is a dup of the original" do
+ p = proc { :foo }
+ (p == p.dup).should == true
+
+ p = Proc.new { :foo }
+ (p == p.dup).should == true
+
+ p = -> { :foo }
+ (p == p.dup).should == true
+ end
+
+ # identical here means the same method invocation.
+ it "returns false when bodies are the same but capture env is not identical" do
+ a = ProcSpecs.proc_for_1
+ b = ProcSpecs.proc_for_1
+
+ (a == b).should == false
+ end
+
+ it "returns false if procs are distinct but have the same body and environment" do
+ p = proc { :foo }
+ p2 = proc { :foo }
+ (p == p2).should == false
+ end
+
+ it "returns false if lambdas are distinct but have same body and environment" do
+ x = -> { :foo }
+ x2 = -> { :foo }
+ (x == x2).should == false
+ end
+
+ it "returns false if using comparing lambda to proc, even with the same body and env" do
+ p = -> { :foo }
+ p2 = proc { :foo }
+ (p == p2).should == false
+
+ x = proc { :bar }
+ x2 = -> { :bar }
+ (x == x2).should == false
+ end
+
+ it "returns false if other is not a Proc" do
+ p = proc { :foo }
+ (p == []).should == false
+
+ p = Proc.new { :foo }
+ (p == Object.new).should == false
+
+ p = -> { :foo }
+ (p == :foo).should == false
+ end
+
+ it "returns false if self and other are both procs but have different bodies" do
+ p = proc { :bar }
+ p2 = proc { :foo }
+ (p == p2).should == false
+ end
+
+ it "returns false if self and other are both lambdas but have different bodies" do
+ p = -> { :foo }
+ p2 = -> { :bar }
+ (p == p2).should == false
+ end
end
diff --git a/spec/ruby/core/proc/fixtures/proc_aref.rb b/spec/ruby/core/proc/fixtures/proc_aref.rb
deleted file mode 100644
index 8ee355b14c..0000000000
--- a/spec/ruby/core/proc/fixtures/proc_aref.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-# frozen_string_literal: false
-module ProcArefSpecs
- def self.aref
- proc {|a| a }["sometext"]
- end
-
- def self.aref_freeze
- proc {|a| a }["sometext".freeze]
- end
-end
diff --git a/spec/ruby/core/proc/fixtures/proc_aref_frozen.rb b/spec/ruby/core/proc/fixtures/proc_aref_frozen.rb
deleted file mode 100644
index 50a330ba4f..0000000000
--- a/spec/ruby/core/proc/fixtures/proc_aref_frozen.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-# frozen_string_literal: true
-module ProcArefFrozenSpecs
- def self.aref
- proc {|a| a }["sometext"]
- end
-
- def self.aref_freeze
- proc {|a| a }["sometext".freeze]
- end
-end
diff --git a/spec/ruby/core/proc/fixtures/proc_call.rb b/spec/ruby/core/proc/fixtures/proc_call.rb
new file mode 100644
index 0000000000..32048f5319
--- /dev/null
+++ b/spec/ruby/core/proc/fixtures/proc_call.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: false
+module ProcCallSpecs
+ def self.call
+ proc {|a| a }.call("sometext")
+ end
+
+ def self.call_freeze
+ proc {|a| a }.call("sometext".freeze)
+ end
+end
diff --git a/spec/ruby/core/proc/fixtures/proc_call_frozen.rb b/spec/ruby/core/proc/fixtures/proc_call_frozen.rb
new file mode 100644
index 0000000000..29ffc3c4c9
--- /dev/null
+++ b/spec/ruby/core/proc/fixtures/proc_call_frozen.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+module ProcCallFrozenSpecs
+ def self.call
+ proc {|a| a }.call("sometext")
+ end
+
+ def self.call_freeze
+ proc {|a| a }.call("sometext".freeze)
+ end
+end
diff --git a/spec/ruby/core/proc/inspect_spec.rb b/spec/ruby/core/proc/inspect_spec.rb
index f53d34116f..96995ec410 100644
--- a/spec/ruby/core/proc/inspect_spec.rb
+++ b/spec/ruby/core/proc/inspect_spec.rb
@@ -1,6 +1,7 @@
require_relative '../../spec_helper'
-require_relative 'shared/to_s'
describe "Proc#inspect" do
- it_behaves_like :proc_to_s, :inspect
+ it "is an alias of Proc#to_s" do
+ Proc.instance_method(:inspect).should == Proc.instance_method(:to_s)
+ end
end
diff --git a/spec/ruby/core/proc/shared/call.rb b/spec/ruby/core/proc/shared/call.rb
deleted file mode 100644
index fae2331b68..0000000000
--- a/spec/ruby/core/proc/shared/call.rb
+++ /dev/null
@@ -1,99 +0,0 @@
-require_relative '../fixtures/common'
-
-describe :proc_call, shared: true do
- it "invokes self" do
- Proc.new { "test!" }.send(@method).should == "test!"
- -> { "test!" }.send(@method).should == "test!"
- proc { "test!" }.send(@method).should == "test!"
- end
-
- it "sets self's parameters to the given values" do
- Proc.new { |a, b| a + b }.send(@method, 1, 2).should == 3
- Proc.new { |*args| args }.send(@method, 1, 2, 3, 4).should == [1, 2, 3, 4]
- Proc.new { |_, *args| args }.send(@method, 1, 2, 3).should == [2, 3]
-
- -> a, b { a + b }.send(@method, 1, 2).should == 3
- -> *args { args }.send(@method, 1, 2, 3, 4).should == [1, 2, 3, 4]
- -> _, *args { args }.send(@method, 1, 2, 3).should == [2, 3]
-
- proc { |a, b| a + b }.send(@method, 1, 2).should == 3
- proc { |*args| args }.send(@method, 1, 2, 3, 4).should == [1, 2, 3, 4]
- proc { |_, *args| args }.send(@method, 1, 2, 3).should == [2, 3]
- end
-end
-
-
-describe :proc_call_on_proc_new, shared: true do
- it "replaces missing arguments with nil" do
- Proc.new { |a, b| [a, b] }.send(@method).should == [nil, nil]
- Proc.new { |a, b| [a, b] }.send(@method, 1).should == [1, nil]
- end
-
- it "silently ignores extra arguments" do
- Proc.new { |a, b| a + b }.send(@method, 1, 2, 5).should == 3
- end
-
- it "auto-explodes a single Array argument" do
- p = Proc.new { |a, b| [a, b] }
- p.send(@method, 1, 2).should == [1, 2]
- p.send(@method, [1, 2]).should == [1, 2]
- p.send(@method, [1, 2, 3]).should == [1, 2]
- p.send(@method, [1, 2, 3], 4).should == [[1, 2, 3], 4]
- end
-end
-
-describe :proc_call_on_proc_or_lambda, shared: true do
- it "ignores excess arguments when self is a proc" do
- a = proc {|x| x}.send(@method, 1, 2)
- a.should == 1
-
- a = proc {|x| x}.send(@method, 1, 2, 3)
- a.should == 1
-
- a = proc {|x:| x}.send(@method, 2, x: 1)
- a.should == 1
- end
-
- it "will call #to_ary on argument and return self if return is nil" do
- argument = ProcSpecs::ToAryAsNil.new
- result = proc { |x, _| x }.send(@method, argument)
- result.should == argument
- end
-
- it "substitutes nil for missing arguments when self is a proc" do
- proc {|x,y| [x,y]}.send(@method).should == [nil,nil]
-
- a = proc {|x,y| [x, y]}.send(@method, 1)
- a.should == [1,nil]
- end
-
- it "raises an ArgumentError on excess arguments when self is a lambda" do
- -> {
- -> x { x }.send(@method, 1, 2)
- }.should.raise(ArgumentError)
-
- -> {
- -> x { x }.send(@method, 1, 2, 3)
- }.should.raise(ArgumentError)
- end
-
- it "raises an ArgumentError on missing arguments when self is a lambda" do
- -> {
- -> x { x }.send(@method)
- }.should.raise(ArgumentError)
-
- -> {
- -> x, y { [x,y] }.send(@method, 1)
- }.should.raise(ArgumentError)
- end
-
- it "treats a single Array argument as a single argument when self is a lambda" do
- -> a { a }.send(@method, [1, 2]).should == [1, 2]
- -> a, b { [a, b] }.send(@method, [1, 2], 3).should == [[1,2], 3]
- end
-
- it "treats a single Array argument as a single argument when self is a proc" do
- proc { |a| a }.send(@method, [1, 2]).should == [1, 2]
- proc { |a, b| [a, b] }.send(@method, [1, 2], 3).should == [[1,2], 3]
- end
-end
diff --git a/spec/ruby/core/proc/shared/call_arguments.rb b/spec/ruby/core/proc/shared/call_arguments.rb
deleted file mode 100644
index 91ada3439e..0000000000
--- a/spec/ruby/core/proc/shared/call_arguments.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-describe :proc_call_block_args, shared: true do
- it "can receive block arguments" do
- Proc.new {|&b| b.send(@method)}.send(@method) {1 + 1}.should == 2
- -> &b { b.send(@method)}.send(@method) {1 + 1}.should == 2
- proc {|&b| b.send(@method)}.send(@method) {1 + 1}.should == 2
- end
-
- it "yields to the block given at declaration and not to the block argument" do
- proc_creator = Object.new
- def proc_creator.create
- Proc.new do |&b|
- yield
- end
- end
- a_proc = proc_creator.create { 7 }
- a_proc.send(@method) { 3 }.should == 7
- end
-
- it "can call its block argument declared with a block argument" do
- proc_creator = Object.new
- def proc_creator.create(method_name)
- Proc.new do |&b|
- yield + b.send(method_name)
- end
- end
- a_proc = proc_creator.create(@method) { 7 }
- a_proc.call { 3 }.should == 10
- end
-end
diff --git a/spec/ruby/core/proc/shared/equal.rb b/spec/ruby/core/proc/shared/equal.rb
deleted file mode 100644
index 4f6f6c41be..0000000000
--- a/spec/ruby/core/proc/shared/equal.rb
+++ /dev/null
@@ -1,83 +0,0 @@
-require_relative '../../../spec_helper'
-require_relative '../fixtures/common'
-
-describe :proc_equal, shared: true do
- it "is a public method" do
- Proc.public_instance_methods(false).should.include?(@method)
- end
-
- it "returns true if self and other are the same object" do
- p = proc { :foo }
- p.send(@method, p).should == true
-
- p = Proc.new { :foo }
- p.send(@method, p).should == true
-
- p = -> { :foo }
- p.send(@method, p).should == true
- end
-
- it "returns true if other is a dup of the original" do
- p = proc { :foo }
- p.send(@method, p.dup).should == true
-
- p = Proc.new { :foo }
- p.send(@method, p.dup).should == true
-
- p = -> { :foo }
- p.send(@method, p.dup).should == true
- end
-
- # identical here means the same method invocation.
- it "returns false when bodies are the same but capture env is not identical" do
- a = ProcSpecs.proc_for_1
- b = ProcSpecs.proc_for_1
-
- a.send(@method, b).should == false
- end
-
- it "returns false if procs are distinct but have the same body and environment" do
- p = proc { :foo }
- p2 = proc { :foo }
- p.send(@method, p2).should == false
- end
-
- it "returns false if lambdas are distinct but have same body and environment" do
- x = -> { :foo }
- x2 = -> { :foo }
- x.send(@method, x2).should == false
- end
-
- it "returns false if using comparing lambda to proc, even with the same body and env" do
- p = -> { :foo }
- p2 = proc { :foo }
- p.send(@method, p2).should == false
-
- x = proc { :bar }
- x2 = -> { :bar }
- x.send(@method, x2).should == false
- end
-
- it "returns false if other is not a Proc" do
- p = proc { :foo }
- p.send(@method, []).should == false
-
- p = Proc.new { :foo }
- p.send(@method, Object.new).should == false
-
- p = -> { :foo }
- p.send(@method, :foo).should == false
- end
-
- it "returns false if self and other are both procs but have different bodies" do
- p = proc { :bar }
- p2 = proc { :foo }
- p.send(@method, p2).should == false
- end
-
- it "returns false if self and other are both lambdas but have different bodies" do
- p = -> { :foo }
- p2 = -> { :bar }
- p.send(@method, p2).should == false
- end
-end
diff --git a/spec/ruby/core/proc/shared/to_s.rb b/spec/ruby/core/proc/shared/to_s.rb
deleted file mode 100644
index a52688a89f..0000000000
--- a/spec/ruby/core/proc/shared/to_s.rb
+++ /dev/null
@@ -1,60 +0,0 @@
-describe :proc_to_s, shared: true do
- describe "for a proc created with Proc.new" do
- it "returns a description including file and line number" do
- Proc.new { "hello" }.send(@method).should =~ /^#<Proc:([^ ]*?) #{Regexp.escape __FILE__}:#{__LINE__ }>$/
- end
-
- it "has a binary encoding" do
- Proc.new { "hello" }.send(@method).encoding.should == Encoding::BINARY
- end
- end
-
- describe "for a proc created with lambda" do
- it "returns a description including '(lambda)' and including file and line number" do
- -> { "hello" }.send(@method).should =~ /^#<Proc:([^ ]*?) #{Regexp.escape __FILE__}:#{__LINE__ } \(lambda\)>$/
- end
-
- it "has a binary encoding" do
- -> { "hello" }.send(@method).encoding.should == Encoding::BINARY
- end
- end
-
- describe "for a proc created with proc" do
- it "returns a description including file and line number" do
- proc { "hello" }.send(@method).should =~ /^#<Proc:([^ ]*?) #{Regexp.escape __FILE__}:#{__LINE__ }>$/
- end
-
- it "has a binary encoding" do
- proc { "hello" }.send(@method).encoding.should == Encoding::BINARY
- end
- end
-
- describe "for a proc created with UnboundMethod#to_proc" do
- it "returns a description including '(lambda)' and optionally including file and line number" do
- def hello; end
- s = method("hello").to_proc.send(@method)
- if s.include? __FILE__
- s.should =~ /^#<Proc:([^ ]*?) #{Regexp.escape __FILE__}:#{__LINE__ - 3} \(lambda\)>$/
- else
- s.should =~ /^#<Proc:([^ ]*?) \(lambda\)>$/
- end
- end
-
- it "has a binary encoding" do
- def hello; end
- method("hello").to_proc.send(@method).encoding.should == Encoding::BINARY
- end
- end
-
- describe "for a proc created with Symbol#to_proc" do
- it "returns a description including '(&:symbol)'" do
- proc = :foobar.to_proc
- proc.send(@method).should.include?('(&:foobar)')
- end
-
- it "has a binary encoding" do
- proc = :foobar.to_proc
- proc.send(@method).encoding.should == Encoding::BINARY
- end
- end
-end
diff --git a/spec/ruby/core/proc/to_s_spec.rb b/spec/ruby/core/proc/to_s_spec.rb
index 5e9c46b6b8..58a9aa76fb 100644
--- a/spec/ruby/core/proc/to_s_spec.rb
+++ b/spec/ruby/core/proc/to_s_spec.rb
@@ -1,6 +1,62 @@
require_relative '../../spec_helper'
-require_relative 'shared/to_s'
describe "Proc#to_s" do
- it_behaves_like :proc_to_s, :to_s
+ describe "for a proc created with Proc.new" do
+ it "returns a description including file and line number" do
+ Proc.new { "hello" }.to_s.should =~ /^#<Proc:([^ ]*?) #{Regexp.escape __FILE__}:#{__LINE__ }>$/
+ end
+
+ it "has a binary encoding" do
+ Proc.new { "hello" }.to_s.encoding.should == Encoding::BINARY
+ end
+ end
+
+ describe "for a proc created with lambda" do
+ it "returns a description including '(lambda)' and including file and line number" do
+ -> { "hello" }.to_s.should =~ /^#<Proc:([^ ]*?) #{Regexp.escape __FILE__}:#{__LINE__ } \(lambda\)>$/
+ end
+
+ it "has a binary encoding" do
+ -> { "hello" }.to_s.encoding.should == Encoding::BINARY
+ end
+ end
+
+ describe "for a proc created with proc" do
+ it "returns a description including file and line number" do
+ proc { "hello" }.to_s.should =~ /^#<Proc:([^ ]*?) #{Regexp.escape __FILE__}:#{__LINE__ }>$/
+ end
+
+ it "has a binary encoding" do
+ proc { "hello" }.to_s.encoding.should == Encoding::BINARY
+ end
+ end
+
+ describe "for a proc created with UnboundMethod#to_proc" do
+ it "returns a description including '(lambda)' and optionally including file and line number" do
+ def hello; end
+ s = method("hello").to_proc.to_s
+ if s.include? __FILE__
+ s.should =~ /^#<Proc:([^ ]*?) #{Regexp.escape __FILE__}:#{__LINE__ - 3} \(lambda\)>$/
+ else
+ s.should =~ /^#<Proc:([^ ]*?) \(lambda\)>$/
+ end
+ end
+
+ it "has a binary encoding" do
+ def hello; end
+ method("hello").to_proc.to_s.encoding.should == Encoding::BINARY
+ end
+ end
+
+ describe "for a proc created with Symbol#to_proc" do
+ it "returns a description including '(&:symbol)'" do
+ proc = :foobar.to_proc
+ proc.to_s.should.include?('(&:foobar)')
+ end
+
+ it "has a binary encoding" do
+ proc = :foobar.to_proc
+ proc.to_s.encoding.should == Encoding::BINARY
+ end
+ end
end
diff --git a/spec/ruby/core/proc/yield_spec.rb b/spec/ruby/core/proc/yield_spec.rb
index 365d5b04bd..e6ee2d5eff 100644
--- a/spec/ruby/core/proc/yield_spec.rb
+++ b/spec/ruby/core/proc/yield_spec.rb
@@ -1,16 +1,7 @@
require_relative '../../spec_helper'
-require_relative 'shared/call'
-require_relative 'shared/call_arguments'
describe "Proc#yield" do
- it_behaves_like :proc_call, :yield
- it_behaves_like :proc_call_block_args, :yield
-end
-
-describe "Proc#yield on a Proc created with Proc.new" do
- it_behaves_like :proc_call_on_proc_new, :yield
-end
-
-describe "Proc#yield on a Proc created with Kernel#lambda or Kernel#proc" do
- it_behaves_like :proc_call_on_proc_or_lambda, :yield
+ it "is an alias of Proc#call" do
+ Proc.instance_method(:yield).should == Proc.instance_method(:call)
+ end
end