diff options
Diffstat (limited to 'spec/ruby/core/random/rand_spec.rb')
-rw-r--r-- | spec/ruby/core/random/rand_spec.rb | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/spec/ruby/core/random/rand_spec.rb b/spec/ruby/core/random/rand_spec.rb index 395e89dc75..b585aa9737 100644 --- a/spec/ruby/core/random/rand_spec.rb +++ b/spec/ruby/core/random/rand_spec.rb @@ -1,4 +1,5 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' describe "Random.rand" do it "returns a Float if no max argument is passed" do @@ -83,13 +84,13 @@ describe "Random#rand with Fixnum" do end it "raises an ArgumentError when the argument is 0" do - lambda do + -> do Random.new.rand(0) end.should raise_error(ArgumentError) end it "raises an ArgumentError when the argument is negative" do - lambda do + -> do Random.new.rand(-12) end.should raise_error(ArgumentError) end @@ -122,7 +123,7 @@ describe "Random#rand with Bignum" do end it "raises an ArgumentError when the argument is negative" do - lambda do + -> do Random.new.rand(-bignum_value) end.should raise_error(ArgumentError) end @@ -154,7 +155,7 @@ describe "Random#rand with Float" do end it "raises an ArgumentError when the argument is negative" do - lambda do + -> do Random.new.rand(-1.234567) end.should raise_error(ArgumentError) end @@ -165,6 +166,12 @@ describe "Random#rand with Range" do Random.new.rand(20..43).should be_an_instance_of(Fixnum) 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) + end + it "returns an object that is a member of the Range" do prng = Random.new r = 20..30 @@ -203,13 +210,13 @@ describe "Random#rand with Range" do end it "raises an ArgumentError when the startpoint lacks #+ and #- methods" do - lambda do + -> do Random.new.rand(Object.new..67) end.should raise_error(ArgumentError) end it "raises an ArgumentError when the endpoint lacks #+ and #- methods" do - lambda do + -> do Random.new.rand(68..Object.new) end.should raise_error(ArgumentError) end |