summaryrefslogtreecommitdiff
path: root/spec/ruby/core/kernel
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
parent64d8c0815e6ab042e8a67a670bda9f34404fa662 (diff)
Update to ruby/spec@b6b7752
Diffstat (limited to 'spec/ruby/core/kernel')
-rw-r--r--spec/ruby/core/kernel/initialize_copy_spec.rb29
-rw-r--r--spec/ruby/core/kernel/proc_spec.rb22
-rw-r--r--spec/ruby/core/kernel/srand_spec.rb4
3 files changed, 46 insertions, 9 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
diff --git a/spec/ruby/core/kernel/proc_spec.rb b/spec/ruby/core/kernel/proc_spec.rb
index 3930715ebd..7b4493dcc4 100644
--- a/spec/ruby/core/kernel/proc_spec.rb
+++ b/spec/ruby/core/kernel/proc_spec.rb
@@ -36,27 +36,31 @@ describe "Kernel.proc" do
end
describe "Kernel#proc" do
+ def some_method
+ proc
+ end
+
ruby_version_is ""..."2.7" do
it "uses the implicit block from an enclosing method" do
- def some_method
- proc
- end
-
prc = some_method { "hello" }
prc.call.should == "hello"
end
end
- ruby_version_is "2.7" ... "2.8" do
+ ruby_version_is "2.7"..."2.8" do
it "can be created when called with no block" do
- def some_method
- proc
- end
-
-> {
some_method { "hello" }
}.should complain(/Capturing the given block using Kernel#proc is deprecated/)
end
end
+
+ ruby_version_is "2.8" do
+ it "raises an ArgumentError when passed no block" do
+ -> {
+ some_method { "hello" }
+ }.should raise_error(ArgumentError, 'tried to create Proc object without a block')
+ end
+ end
end
diff --git a/spec/ruby/core/kernel/srand_spec.rb b/spec/ruby/core/kernel/srand_spec.rb
index 5454aae8cf..0985c76cb0 100644
--- a/spec/ruby/core/kernel/srand_spec.rb
+++ b/spec/ruby/core/kernel/srand_spec.rb
@@ -11,6 +11,10 @@ describe "Kernel.srand" do
srand(20).should == 10
end
+ it "returns the previous seed value on the first call" do
+ ruby_exe('p srand(10)', options: '--disable-gems').chomp.should =~ /\A\d+\z/
+ end
+
it "seeds the RNG correctly and repeatably" do
srand(10)
x = rand