summaryrefslogtreecommitdiff
path: root/spec/ruby/core/proc/shared
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/proc/shared')
-rw-r--r--spec/ruby/core/proc/shared/compose.rb51
-rw-r--r--spec/ruby/core/proc/shared/dup.rb31
-rw-r--r--spec/ruby/core/proc/shared/equal.rb17
-rw-r--r--spec/ruby/core/proc/shared/to_s.rb22
4 files changed, 54 insertions, 67 deletions
diff --git a/spec/ruby/core/proc/shared/compose.rb b/spec/ruby/core/proc/shared/compose.rb
index e3ae7f76b8..3d3f3b310d 100644
--- a/spec/ruby/core/proc/shared/compose.rb
+++ b/spec/ruby/core/proc/shared/compose.rb
@@ -1,47 +1,22 @@
describe :proc_compose, shared: true do
- ruby_version_is ""..."2.7" do
- it "raises NoMethodError when called if passed not callable object" do
- not_callable = Object.new
- composed = @object.call.send(@method, not_callable)
+ it "raises TypeError if passed not callable object" do
+ lhs = @object.call
+ not_callable = Object.new
- -> {
- composed.call('a')
- }.should raise_error(NoMethodError, /undefined method `call' for/)
+ -> {
+ lhs.send(@method, not_callable)
+ }.should raise_error(TypeError, "callable object is expected")
- end
-
- it "when called does not try to coerce argument with #to_proc" do
- succ = Object.new
- def succ.to_proc(s); s.succ; end
-
- composed = @object.call.send(@method, succ)
-
- -> {
- composed.call('a')
- }.should raise_error(NoMethodError, /undefined method `call' for/)
- end
end
- ruby_version_is "2.7" do # https://bugs.ruby-lang.org/issues/15428
- it "raises TypeError if passed not callable object" do
- lhs = @object.call
- not_callable = Object.new
-
- -> {
- lhs.send(@method, not_callable)
- }.should raise_error(TypeError, "callable object is expected")
-
- end
-
- it "does not try to coerce argument with #to_proc" do
- lhs = @object.call
+ it "does not try to coerce argument with #to_proc" do
+ lhs = @object.call
- succ = Object.new
- def succ.to_proc(s); s.succ; end
+ succ = Object.new
+ def succ.to_proc(s); s.succ; end
- -> {
- lhs.send(@method, succ)
- }.should raise_error(TypeError, "callable object is expected")
- end
+ -> {
+ lhs.send(@method, succ)
+ }.should raise_error(TypeError, "callable object is expected")
end
end
diff --git a/spec/ruby/core/proc/shared/dup.rb b/spec/ruby/core/proc/shared/dup.rb
index eda1d6929d..c419a4078a 100644
--- a/spec/ruby/core/proc/shared/dup.rb
+++ b/spec/ruby/core/proc/shared/dup.rb
@@ -7,4 +7,35 @@ describe :proc_dup, shared: true do
a.call.should == b.call
end
+
+ ruby_version_is "3.2" do
+ it "returns an instance of subclass" do
+ cl = Class.new(Proc)
+
+ cl.new{}.send(@method).class.should == cl
+ end
+ end
+
+ ruby_version_is "3.4" do
+ it "copies instance variables" do
+ proc = -> { "hello" }
+ proc.instance_variable_set(:@ivar, 1)
+ cl = proc.send(@method)
+ cl.instance_variables.should == [:@ivar]
+ end
+
+ it "copies the finalizer" do
+ code = <<-RUBY
+ obj = Proc.new { }
+
+ ObjectSpace.define_finalizer(obj, Proc.new { STDOUT.write "finalized\n" })
+
+ obj.clone
+
+ exit 0
+ RUBY
+
+ ruby_exe(code).lines.sort.should == ["finalized\n", "finalized\n"]
+ end
+ end
end
diff --git a/spec/ruby/core/proc/shared/equal.rb b/spec/ruby/core/proc/shared/equal.rb
index 0c0020ca7f..d0503fb064 100644
--- a/spec/ruby/core/proc/shared/equal.rb
+++ b/spec/ruby/core/proc/shared/equal.rb
@@ -81,20 +81,3 @@ describe :proc_equal, shared: true do
p.send(@method, p2).should be_false
end
end
-
-describe :proc_equal_undefined, shared: true do
- it "is not defined" do
- Proc.should_not have_instance_method(@method, false)
- end
-
- it "returns false if other is a dup of the original" do
- p = proc { :foo }
- p.send(@method, p.dup).should be_false
-
- p = Proc.new { :foo }
- p.send(@method, p.dup).should be_false
-
- p = -> { :foo }
- p.send(@method, p.dup).should be_false
- end
-end
diff --git a/spec/ruby/core/proc/shared/to_s.rb b/spec/ruby/core/proc/shared/to_s.rb
index 7f167a3d9d..a52688a89f 100644
--- a/spec/ruby/core/proc/shared/to_s.rb
+++ b/spec/ruby/core/proc/shared/to_s.rb
@@ -1,9 +1,7 @@
describe :proc_to_s, shared: true do
- sep = ruby_version_is("2.7") ? " " : "@"
-
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:([^ ]*?)#{sep}#{Regexp.escape __FILE__}:#{__LINE__ }>$/
+ Proc.new { "hello" }.send(@method).should =~ /^#<Proc:([^ ]*?) #{Regexp.escape __FILE__}:#{__LINE__ }>$/
end
it "has a binary encoding" do
@@ -13,7 +11,7 @@ describe :proc_to_s, shared: true do
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:([^ ]*?)#{sep}#{Regexp.escape __FILE__}:#{__LINE__ } \(lambda\)>$/
+ -> { "hello" }.send(@method).should =~ /^#<Proc:([^ ]*?) #{Regexp.escape __FILE__}:#{__LINE__ } \(lambda\)>$/
end
it "has a binary encoding" do
@@ -23,7 +21,7 @@ describe :proc_to_s, shared: true do
describe "for a proc created with proc" do
it "returns a description including file and line number" do
- proc { "hello" }.send(@method).should =~ /^#<Proc:([^ ]*?)#{sep}#{Regexp.escape __FILE__}:#{__LINE__ }>$/
+ proc { "hello" }.send(@method).should =~ /^#<Proc:([^ ]*?) #{Regexp.escape __FILE__}:#{__LINE__ }>$/
end
it "has a binary encoding" do
@@ -33,13 +31,13 @@ describe :proc_to_s, shared: true do
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:([^ ]*?)#{sep}#{Regexp.escape __FILE__}:#{__LINE__ - 3} \(lambda\)>$/
- else
- s.should =~ /^#<Proc:([^ ]*?) \(lambda\)>$/
- end
+ 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