summaryrefslogtreecommitdiff
path: root/spec/ruby/core/random
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2019-09-29 16:03:58 +0200
committerBenoit Daloze <eregontp@gmail.com>2019-09-29 16:03:58 +0200
commit1c938a72aa9378f982dbc55327e86150c47b8707 (patch)
tree34a0bb0a45396c26eed111877a810c3aa793bff5 /spec/ruby/core/random
parent31bb66a19df26409c9d47afcf37919c9a065516a (diff)
Update to ruby/spec@519df35
Diffstat (limited to 'spec/ruby/core/random')
-rw-r--r--spec/ruby/core/random/rand_spec.rb17
-rw-r--r--spec/ruby/core/random/shared/bytes.rb8
-rw-r--r--spec/ruby/core/random/shared/rand.rb9
3 files changed, 23 insertions, 11 deletions
diff --git a/spec/ruby/core/random/rand_spec.rb b/spec/ruby/core/random/rand_spec.rb
index b585aa9737..d1a76e5dac 100644
--- a/spec/ruby/core/random/rand_spec.rb
+++ b/spec/ruby/core/random/rand_spec.rb
@@ -1,10 +1,11 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
+require_relative 'shared/rand'
describe "Random.rand" do
- it "returns a Float if no max argument is passed" do
- Random.rand.should be_kind_of(Float)
- end
+ it_behaves_like :random_number, :rand, Random.new
+ it_behaves_like :random_number, :random_number, Random.new
+ it_behaves_like :random_number, :rand, Random
it "returns a Float >= 0 if no max argument is passed" do
floats = 200.times.map { Random.rand }
@@ -24,10 +25,6 @@ describe "Random.rand" do
floats_a.should == floats_b
end
- it "returns an Integer if an Integer argument is passed" do
- Random.rand(20).should be_kind_of(Integer)
- end
-
it "returns an Integer >= 0 if an Integer argument is passed" do
ints = 200.times.map { Random.rand(34) }
ints.min.should >= 0
@@ -221,3 +218,9 @@ describe "Random#rand with Range" do
end.should raise_error(ArgumentError)
end
end
+
+ruby_version_is "2.6" do
+ describe "Random.random_number" do
+ it_behaves_like :random_number, :random_number, Random
+ end
+end
diff --git a/spec/ruby/core/random/shared/bytes.rb b/spec/ruby/core/random/shared/bytes.rb
index fe8cd8d683..9afad3b7f8 100644
--- a/spec/ruby/core/random/shared/bytes.rb
+++ b/spec/ruby/core/random/shared/bytes.rb
@@ -1,17 +1,17 @@
describe :random_bytes, shared: true do
it "returns a String" do
- @object.bytes(1).should be_an_instance_of(String)
+ @object.send(@method, 1).should be_an_instance_of(String)
end
it "returns a String of the length given as argument" do
- @object.bytes(15).length.should == 15
+ @object.send(@method, 15).length.should == 15
end
it "returns a binary String" do
- @object.bytes(15).encoding.should == Encoding::BINARY
+ @object.send(@method, 15).encoding.should == Encoding::BINARY
end
it "returns a random binary String" do
- @object.bytes(12).should_not == @object.bytes(12)
+ @object.send(@method, 12).should_not == @object.send(@method, 12)
end
end
diff --git a/spec/ruby/core/random/shared/rand.rb b/spec/ruby/core/random/shared/rand.rb
new file mode 100644
index 0000000000..d3b24b8851
--- /dev/null
+++ b/spec/ruby/core/random/shared/rand.rb
@@ -0,0 +1,9 @@
+describe :random_number, shared: true do
+ it "returns a Float if no max argument is passed" do
+ @object.send(@method).should be_kind_of(Float)
+ end
+
+ it "returns an Integer if an Integer argument is passed" do
+ @object.send(@method, 20).should be_kind_of(Integer)
+ end
+end