diff options
Diffstat (limited to 'spec/ruby/core/kernel/srand_spec.rb')
| -rw-r--r-- | spec/ruby/core/kernel/srand_spec.rb | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/spec/ruby/core/kernel/srand_spec.rb b/spec/ruby/core/kernel/srand_spec.rb index 5454aae8cf..cbc3a7f4b8 100644 --- a/spec/ruby/core/kernel/srand_spec.rb +++ b/spec/ruby/core/kernel/srand_spec.rb @@ -1,9 +1,17 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' -describe "Kernel.srand" do +describe "Kernel#srand" do + before :each do + @seed = srand + end + + after :each do + srand(@seed) + end + it "is a private method" do - Kernel.should have_private_instance_method(:srand) + Kernel.private_instance_methods(false).should.include?(:srand) end it "returns the previous seed value" do @@ -11,6 +19,10 @@ describe "Kernel.srand" do srand(20).should == 10 end + it "returns the system-initialized seed value on the first call" do + ruby_exe('print srand(10)', options: '--disable-gems').should =~ /\A\d+\z/ + end + it "seeds the RNG correctly and repeatably" do srand(10) x = rand @@ -19,7 +31,7 @@ describe "Kernel.srand" do end it "defaults number to a random value" do - -> { srand }.should_not raise_error + -> { srand }.should_not.raise srand.should_not == 0 end @@ -33,7 +45,7 @@ describe "Kernel.srand" do srand.should == -17 end - it "accepts a Bignum as a seed" do + it "accepts an Integer as a seed" do srand(0x12345678901234567890) srand.should == 0x12345678901234567890 end @@ -48,14 +60,14 @@ describe "Kernel.srand" do end it "raises a TypeError when passed nil" do - -> { srand(nil) }.should raise_error(TypeError) + -> { srand(nil) }.should.raise(TypeError) end it "raises a TypeError when passed a String" do - -> { srand("7") }.should raise_error(TypeError) + -> { srand("7") }.should.raise(TypeError) end end -describe "Kernel#srand" do +describe "Kernel.srand" do it "needs to be reviewed for spec completeness" end |
