Skip to content

Commit

Permalink
Random.raw_seed was renamed to Random.urandom
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Feb 26, 2017
1 parent e3770c3 commit 0fe99d2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 23 deletions.
27 changes: 4 additions & 23 deletions core/random/raw_seed_spec.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,9 @@
# -*- encoding: binary -*-
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/urandom', __FILE__)

ruby_version_is "2.3" do
describe "Random.raw_seed" do
it "returns a String" do
Random.raw_seed(1).should be_an_instance_of(String)
end

it "returns a String of the length given as argument" do
Random.raw_seed(15).length.should == 15
end

it "raises an ArgumentError on a negative size" do
lambda {
Random.raw_seed(-1)
}.should raise_error(ArgumentError)
end

it "returns an ASCII-8BIT String" do
Random.raw_seed(15).encoding.should == Encoding::ASCII_8BIT
end

it "returns a random binary String" do
Random.raw_seed(12).should_not == Random.raw_seed(12)
end
ruby_version_is "2.5" do
describe "Random.urandom" do
it_behaves_like :random_urandom, :urandom
end
end
23 changes: 23 additions & 0 deletions core/random/shared/urandom.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
describe :random_urandom, shared: true do
it "returns a String" do
Random.send(@method, 1).should be_an_instance_of(String)
end

it "returns a String of the length given as argument" do
Random.send(@method, 15).length.should == 15
end

it "raises an ArgumentError on a negative size" do
lambda {
Random.send(@method, -1)
}.should raise_error(ArgumentError)
end

it "returns an ASCII-8BIT String" do
Random.send(@method, 15).encoding.should == Encoding::ASCII_8BIT
end

it "returns a random binary String" do
Random.send(@method, 12).should_not == Random.send(@method, 12)
end
end
9 changes: 9 additions & 0 deletions core/random/urandom_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# -*- encoding: binary -*-
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/urandom', __FILE__)

ruby_version_is "2.3"..."2.5" do
describe "Random.raw_seed" do
it_behaves_like :random_urandom, :raw_seed
end
end

0 comments on commit 0fe99d2

Please sign in to comment.