summaryrefslogtreecommitdiff
path: root/spec/ruby/core/kernel/initialize_copy_spec.rb
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2020-06-27 15:51:37 +0200
committerBenoit Daloze <eregontp@gmail.com>2020-06-27 15:51:37 +0200
commitb3fa158d1c4d8e03b8dc04f1e4f9940a8a4ef44c (patch)
treefa8a62d6192c24a21e70aa02589507adfe4e4e6a /spec/ruby/core/kernel/initialize_copy_spec.rb
parent64d8c0815e6ab042e8a67a670bda9f34404fa662 (diff)
Update to ruby/spec@b6b7752
Diffstat (limited to 'spec/ruby/core/kernel/initialize_copy_spec.rb')
-rw-r--r--spec/ruby/core/kernel/initialize_copy_spec.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/spec/ruby/core/kernel/initialize_copy_spec.rb b/spec/ruby/core/kernel/initialize_copy_spec.rb
new file mode 100644
index 0000000000..fe08d184ad
--- /dev/null
+++ b/spec/ruby/core/kernel/initialize_copy_spec.rb
@@ -0,0 +1,29 @@
+require_relative '../../spec_helper'
+
+describe "Kernel#initialize_copy" do
+ it "does nothing if the argument is the same as the receiver" do
+ obj = Object.new
+ obj.send(:initialize_copy, obj).should.equal?(obj)
+ obj.freeze
+ obj.send(:initialize_copy, obj).should.equal?(obj)
+ 1.send(:initialize_copy, 1).should.equal?(1)
+ end
+
+ it "raises FrozenError if the receiver is frozen" do
+ -> { Object.new.freeze.send(:initialize_copy, Object.new) }.should raise_error(FrozenError)
+ -> { 1.send(:initialize_copy, Object.new) }.should raise_error(FrozenError)
+ end
+
+ it "raises TypeError if the objects are of different class" do
+ klass = Class.new
+ sub = Class.new(klass)
+ a = klass.new
+ b = sub.new
+ message = 'initialize_copy should take same class object'
+ -> { a.send(:initialize_copy, b) }.should raise_error(TypeError, message)
+ -> { b.send(:initialize_copy, a) }.should raise_error(TypeError, message)
+
+ -> { a.send(:initialize_copy, 1) }.should raise_error(TypeError, message)
+ -> { a.send(:initialize_copy, 1.0) }.should raise_error(TypeError, message)
+ end
+end