From 1c938a72aa9378f982dbc55327e86150c47b8707 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Sun, 29 Sep 2019 16:03:58 +0200 Subject: Update to ruby/spec@519df35 --- spec/ruby/core/random/rand_spec.rb | 17 ++++++++++------- spec/ruby/core/random/shared/bytes.rb | 8 ++++---- spec/ruby/core/random/shared/rand.rb | 9 +++++++++ 3 files changed, 23 insertions(+), 11 deletions(-) create mode 100644 spec/ruby/core/random/shared/rand.rb (limited to 'spec/ruby/core/random') 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 -- cgit v1.2.3