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/call.rb8
-rw-r--r--spec/ruby/core/proc/shared/compose.rb4
-rw-r--r--spec/ruby/core/proc/shared/dup.rb31
-rw-r--r--spec/ruby/core/proc/shared/equal.rb34
-rw-r--r--spec/ruby/core/proc/shared/to_s.rb14
5 files changed, 56 insertions, 35 deletions
diff --git a/spec/ruby/core/proc/shared/call.rb b/spec/ruby/core/proc/shared/call.rb
index dbec34df4b..fae2331b68 100644
--- a/spec/ruby/core/proc/shared/call.rb
+++ b/spec/ruby/core/proc/shared/call.rb
@@ -70,21 +70,21 @@ describe :proc_call_on_proc_or_lambda, shared: true do
it "raises an ArgumentError on excess arguments when self is a lambda" do
-> {
-> x { x }.send(@method, 1, 2)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
-> {
-> x { x }.send(@method, 1, 2, 3)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
it "raises an ArgumentError on missing arguments when self is a lambda" do
-> {
-> x { x }.send(@method)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
-> {
-> x, y { [x,y] }.send(@method, 1)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
it "treats a single Array argument as a single argument when self is a lambda" do
diff --git a/spec/ruby/core/proc/shared/compose.rb b/spec/ruby/core/proc/shared/compose.rb
index 3d3f3b310d..c004cec7c9 100644
--- a/spec/ruby/core/proc/shared/compose.rb
+++ b/spec/ruby/core/proc/shared/compose.rb
@@ -5,7 +5,7 @@ describe :proc_compose, shared: true do
-> {
lhs.send(@method, not_callable)
- }.should raise_error(TypeError, "callable object is expected")
+ }.should.raise(TypeError, "callable object is expected")
end
@@ -17,6 +17,6 @@ describe :proc_compose, shared: true do
-> {
lhs.send(@method, succ)
- }.should raise_error(TypeError, "callable object is expected")
+ }.should.raise(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 4480f3d0c9..2821d2e00f 100644
--- a/spec/ruby/core/proc/shared/dup.rb
+++ b/spec/ruby/core/proc/shared/dup.rb
@@ -3,16 +3,37 @@ describe :proc_dup, shared: true do
a = -> { "hello" }
b = a.send(@method)
- a.should_not equal(b)
+ a.should_not.equal?(b)
a.call.should == b.call
end
- ruby_version_is "3.2" do
- it "returns an instance of subclass" do
- cl = Class.new(Proc)
+ it "returns an instance of subclass" do
+ cl = Class.new(Proc)
- cl.new{}.send(@method).class.should == cl
+ cl.new{}.send(@method).class.should == cl
+ 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 d0503fb064..4f6f6c41be 100644
--- a/spec/ruby/core/proc/shared/equal.rb
+++ b/spec/ruby/core/proc/shared/equal.rb
@@ -3,29 +3,29 @@ require_relative '../fixtures/common'
describe :proc_equal, shared: true do
it "is a public method" do
- Proc.should have_public_instance_method(@method, false)
+ 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 be_true
+ p.send(@method, p).should == true
p = Proc.new { :foo }
- p.send(@method, p).should be_true
+ p.send(@method, p).should == true
p = -> { :foo }
- p.send(@method, p).should be_true
+ 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 be_true
+ p.send(@method, p.dup).should == true
p = Proc.new { :foo }
- p.send(@method, p.dup).should be_true
+ p.send(@method, p.dup).should == true
p = -> { :foo }
- p.send(@method, p.dup).should be_true
+ p.send(@method, p.dup).should == true
end
# identical here means the same method invocation.
@@ -33,51 +33,51 @@ describe :proc_equal, shared: true do
a = ProcSpecs.proc_for_1
b = ProcSpecs.proc_for_1
- a.send(@method, b).should be_false
+ 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 be_false
+ 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 be_false
+ 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 be_false
+ p.send(@method, p2).should == false
x = proc { :bar }
x2 = -> { :bar }
- x.send(@method, x2).should be_false
+ x.send(@method, x2).should == false
end
it "returns false if other is not a Proc" do
p = proc { :foo }
- p.send(@method, []).should be_false
+ p.send(@method, []).should == false
p = Proc.new { :foo }
- p.send(@method, Object.new).should be_false
+ p.send(@method, Object.new).should == false
p = -> { :foo }
- p.send(@method, :foo).should be_false
+ 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 be_false
+ 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 be_false
+ 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
index f1e2f416fc..a52688a89f 100644
--- a/spec/ruby/core/proc/shared/to_s.rb
+++ b/spec/ruby/core/proc/shared/to_s.rb
@@ -31,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:([^ ]*?) #{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