diff options
Diffstat (limited to 'spec/ruby/core/random')
| -rw-r--r-- | spec/ruby/core/random/bytes_spec.rb | 2 | ||||
| -rw-r--r-- | spec/ruby/core/random/default_spec.rb | 32 | ||||
| -rw-r--r-- | spec/ruby/core/random/new_seed_spec.rb | 2 | ||||
| -rw-r--r-- | spec/ruby/core/random/new_spec.rb | 8 | ||||
| -rw-r--r-- | spec/ruby/core/random/rand_spec.rb | 34 | ||||
| -rw-r--r-- | spec/ruby/core/random/seed_spec.rb | 2 | ||||
| -rw-r--r-- | spec/ruby/core/random/shared/bytes.rb | 2 | ||||
| -rw-r--r-- | spec/ruby/core/random/shared/rand.rb | 4 | ||||
| -rw-r--r-- | spec/ruby/core/random/urandom_spec.rb | 4 |
9 files changed, 31 insertions, 59 deletions
diff --git a/spec/ruby/core/random/bytes_spec.rb b/spec/ruby/core/random/bytes_spec.rb index b42dc61234..c9be07cd3f 100644 --- a/spec/ruby/core/random/bytes_spec.rb +++ b/spec/ruby/core/random/bytes_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: binary -*- +# encoding: binary require_relative '../../spec_helper' require_relative 'shared/bytes' diff --git a/spec/ruby/core/random/default_spec.rb b/spec/ruby/core/random/default_spec.rb index 01d7430df8..9e4845986d 100644 --- a/spec/ruby/core/random/default_spec.rb +++ b/spec/ruby/core/random/default_spec.rb @@ -1,35 +1,7 @@ require_relative '../../spec_helper' describe "Random::DEFAULT" do - ruby_version_is ''...'3.2' do - it "returns a random number generator" do - suppress_warning do - Random::DEFAULT.should respond_to(:rand) - end - end - - it "changes seed on reboot" do - seed1 = ruby_exe('p Random::DEFAULT.seed', options: '--disable-gems') - seed2 = ruby_exe('p Random::DEFAULT.seed', options: '--disable-gems') - seed1.should != seed2 - end - - it "refers to the Random class" do - suppress_warning do - Random::DEFAULT.should.equal?(Random) - end - end - - it "is deprecated" do - -> { - Random::DEFAULT.should.equal?(Random) - }.should complain(/constant Random::DEFAULT is deprecated/) - end - end - - ruby_version_is '3.2' do - it "is no longer defined" do - Random.should_not.const_defined?(:DEFAULT) - end + it "is no longer defined" do + Random.should_not.const_defined?(:DEFAULT) end end diff --git a/spec/ruby/core/random/new_seed_spec.rb b/spec/ruby/core/random/new_seed_spec.rb index 7a93da99aa..b2741aaa31 100644 --- a/spec/ruby/core/random/new_seed_spec.rb +++ b/spec/ruby/core/random/new_seed_spec.rb @@ -2,7 +2,7 @@ require_relative '../../spec_helper' describe "Random.new_seed" do it "returns an Integer" do - Random.new_seed.should be_an_instance_of(Integer) + Random.new_seed.should.instance_of?(Integer) end it "returns an arbitrary seed value each time" do diff --git a/spec/ruby/core/random/new_spec.rb b/spec/ruby/core/random/new_spec.rb index 90e2a9d6f2..e20d487137 100644 --- a/spec/ruby/core/random/new_spec.rb +++ b/spec/ruby/core/random/new_spec.rb @@ -1,17 +1,17 @@ require_relative "../../spec_helper" describe "Random.new" do it "returns a new instance of Random" do - Random.new.should be_an_instance_of(Random) + Random.new.should.instance_of?(Random) end it "uses a random seed value if none is supplied" do - Random.new.seed.should be_an_instance_of(Integer) + Random.new.seed.should.instance_of?(Integer) end it "returns Random instances initialized with different seeds" do first = Random.new second = Random.new - (0..20).map { first.rand } .should_not == (0..20).map { second.rand } + (0..20).map { first.rand }.should_not == (0..20).map { second.rand } end it "accepts an Integer seed value as an argument" do @@ -33,6 +33,6 @@ describe "Random.new" do it "raises a RangeError if passed a Complex (with imaginary part) seed value as an argument" do -> do Random.new(Complex(20,2)) - end.should raise_error(RangeError) + end.should.raise(RangeError) end end diff --git a/spec/ruby/core/random/rand_spec.rb b/spec/ruby/core/random/rand_spec.rb index 9244177ab5..c882db6381 100644 --- a/spec/ruby/core/random/rand_spec.rb +++ b/spec/ruby/core/random/rand_spec.rb @@ -45,13 +45,13 @@ describe "Random.rand" do it "coerces arguments to Integers with #to_int" do obj = mock_numeric('int') obj.should_receive(:to_int).and_return(99) - Random.rand(obj).should be_kind_of(Integer) + Random.rand(obj).should.is_a?(Integer) end end describe "Random#rand with Fixnum" do it "returns an Integer" do - Random.new.rand(20).should be_an_instance_of(Integer) + Random.new.rand(20).should.instance_of?(Integer) end it "returns a Fixnum greater than or equal to 0" do @@ -82,20 +82,20 @@ describe "Random#rand with Fixnum" do it "raises an ArgumentError when the argument is 0" do -> do Random.new.rand(0) - end.should raise_error(ArgumentError) + end.should.raise(ArgumentError) end it "raises an ArgumentError when the argument is negative" do -> do Random.new.rand(-12) - end.should raise_error(ArgumentError) + end.should.raise(ArgumentError) end end describe "Random#rand with Bignum" do it "typically returns a Bignum" do rnd = Random.new(1) - 10.times.map{ rnd.rand(bignum_value*2) }.max.should be_an_instance_of(Integer) + 10.times.map{ rnd.rand(bignum_value*2) }.max.should.instance_of?(Integer) end it "returns a Bignum greater than or equal to 0" do @@ -121,13 +121,13 @@ describe "Random#rand with Bignum" do it "raises an ArgumentError when the argument is negative" do -> do Random.new.rand(-bignum_value) - end.should raise_error(ArgumentError) + end.should.raise(ArgumentError) end end describe "Random#rand with Float" do it "returns a Float" do - Random.new.rand(20.43).should be_an_instance_of(Float) + Random.new.rand(20.43).should.instance_of?(Float) end it "returns a Float greater than or equal to 0.0" do @@ -153,25 +153,25 @@ describe "Random#rand with Float" do it "raises an ArgumentError when the argument is negative" do -> do Random.new.rand(-1.234567) - end.should raise_error(ArgumentError) + end.should.raise(ArgumentError) end end describe "Random#rand with Range" do it "returns an element from the Range" do - Random.new.rand(20..43).should be_an_instance_of(Integer) + Random.new.rand(20..43).should.instance_of?(Integer) end it "supports custom object types" do - rand(RandomSpecs::CustomRangeInteger.new(1)..RandomSpecs::CustomRangeInteger.new(42)).should be_an_instance_of(RandomSpecs::CustomRangeInteger) - rand(RandomSpecs::CustomRangeFloat.new(1.0)..RandomSpecs::CustomRangeFloat.new(42.0)).should be_an_instance_of(RandomSpecs::CustomRangeFloat) - rand(Time.now..Time.now).should be_an_instance_of(Time) + rand(RandomSpecs::CustomRangeInteger.new(1)..RandomSpecs::CustomRangeInteger.new(42)).should.instance_of?(RandomSpecs::CustomRangeInteger) + rand(RandomSpecs::CustomRangeFloat.new(1.0)..RandomSpecs::CustomRangeFloat.new(42.0)).should.instance_of?(RandomSpecs::CustomRangeFloat) + rand(Time.now..Time.now).should.instance_of?(Time) end it "returns an object that is a member of the Range" do prng = Random.new r = 20..30 - 20.times { r.member?(prng.rand(r)).should be_true } + 20.times { r.member?(prng.rand(r)).should == true } end it "works with inclusive ranges" do @@ -201,8 +201,8 @@ describe "Random#rand with Range" do end it "considers Integers as Floats if one end point is a float" do - Random.new(42).rand(0.0..1).should be_kind_of(Float) - Random.new(42).rand(0..1.0).should be_kind_of(Float) + Random.new(42).rand(0.0..1).should.is_a?(Float) + Random.new(42).rand(0..1.0).should.is_a?(Float) end it "returns a float within a given float range" do @@ -213,12 +213,12 @@ describe "Random#rand with Range" do it "raises an ArgumentError when the startpoint lacks #+ and #- methods" do -> do Random.new.rand(Object.new..67) - end.should raise_error(ArgumentError) + end.should.raise(ArgumentError) end it "raises an ArgumentError when the endpoint lacks #+ and #- methods" do -> do Random.new.rand(68..Object.new) - end.should raise_error(ArgumentError) + end.should.raise(ArgumentError) end end diff --git a/spec/ruby/core/random/seed_spec.rb b/spec/ruby/core/random/seed_spec.rb index bf4524fdd9..6529b2c873 100644 --- a/spec/ruby/core/random/seed_spec.rb +++ b/spec/ruby/core/random/seed_spec.rb @@ -2,7 +2,7 @@ require_relative '../../spec_helper' describe "Random#seed" do it "returns an Integer" do - Random.new.seed.should be_kind_of(Integer) + Random.new.seed.should.is_a?(Integer) end it "returns an arbitrary seed if the constructor was called without arguments" do diff --git a/spec/ruby/core/random/shared/bytes.rb b/spec/ruby/core/random/shared/bytes.rb index 9afad3b7f8..86c64d5696 100644 --- a/spec/ruby/core/random/shared/bytes.rb +++ b/spec/ruby/core/random/shared/bytes.rb @@ -1,6 +1,6 @@ describe :random_bytes, shared: true do it "returns a String" do - @object.send(@method, 1).should be_an_instance_of(String) + @object.send(@method, 1).should.instance_of?(String) end it "returns a String of the length given as argument" do diff --git a/spec/ruby/core/random/shared/rand.rb b/spec/ruby/core/random/shared/rand.rb index d3b24b8851..655c75c9f1 100644 --- a/spec/ruby/core/random/shared/rand.rb +++ b/spec/ruby/core/random/shared/rand.rb @@ -1,9 +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) + @object.send(@method).should.is_a?(Float) end it "returns an Integer if an Integer argument is passed" do - @object.send(@method, 20).should be_kind_of(Integer) + @object.send(@method, 20).should.is_a?(Integer) end end diff --git a/spec/ruby/core/random/urandom_spec.rb b/spec/ruby/core/random/urandom_spec.rb index 6f180e54ac..94e9423a06 100644 --- a/spec/ruby/core/random/urandom_spec.rb +++ b/spec/ruby/core/random/urandom_spec.rb @@ -2,7 +2,7 @@ require_relative '../../spec_helper' describe "Random.urandom" do it "returns a String" do - Random.urandom(1).should be_an_instance_of(String) + Random.urandom(1).should.instance_of?(String) end it "returns a String of the length given as argument" do @@ -12,7 +12,7 @@ describe "Random.urandom" do it "raises an ArgumentError on a negative size" do -> { Random.urandom(-1) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end it "returns a binary String" do |
