diff options
Diffstat (limited to 'spec/ruby/core/array/shuffle_spec.rb')
| -rw-r--r-- | spec/ruby/core/array/shuffle_spec.rb | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/spec/ruby/core/array/shuffle_spec.rb b/spec/ruby/core/array/shuffle_spec.rb index 1d528c124f..9bc9df73ac 100644 --- a/spec/ruby/core/array/shuffle_spec.rb +++ b/spec/ruby/core/array/shuffle_spec.rb @@ -10,7 +10,7 @@ describe "Array#shuffle" do s.sort.should == a different ||= (a != s) end - different.should be_true # Will fail once in a blue moon (4!^10) + different.should == true # Will fail once in a blue moon (4!^10) end it "is not destructive" do @@ -22,7 +22,7 @@ describe "Array#shuffle" do end it "does not return subclass instances with Array subclass" do - ArraySpecs::MyArray[1, 2, 3].shuffle.should be_an_instance_of(Array) + ArraySpecs::MyArray[1, 2, 3].shuffle.should.instance_of?(Array) end it "calls #rand on the Object passed by the :random key in the arguments Hash" do @@ -31,24 +31,24 @@ describe "Array#shuffle" do result = [1, 2].shuffle(random: obj) result.size.should == 2 - result.should include(1, 2) + result.sort.should == [1, 2] end it "raises a NoMethodError if an object passed for the RNG does not define #rand" do obj = BasicObject.new - -> { [1, 2].shuffle(random: obj) }.should raise_error(NoMethodError) + -> { [1, 2].shuffle(random: obj) }.should.raise(NoMethodError) end it "accepts a Float for the value returned by #rand" do random = mock("array_shuffle_random") random.should_receive(:rand).at_least(1).times.and_return(0.3) - [1, 2].shuffle(random: random).should be_an_instance_of(Array) + [1, 2].shuffle(random: random).should.instance_of?(Array) end it "accepts a Random class for the value for random: argument" do - [1, 2].shuffle(random: Random).should be_an_instance_of(Array) + [1, 2].shuffle(random: Random).should.instance_of?(Array) end it "calls #to_int on the Object returned by #rand" do @@ -57,7 +57,7 @@ describe "Array#shuffle" do random = mock("array_shuffle_random") random.should_receive(:rand).at_least(1).times.and_return(value) - [1, 2].shuffle(random: random).should be_an_instance_of(Array) + [1, 2].shuffle(random: random).should.instance_of?(Array) end it "raises a RangeError if the value is less than zero" do @@ -66,16 +66,25 @@ describe "Array#shuffle" do random = mock("array_shuffle_random") random.should_receive(:rand).and_return(value) - -> { [1, 2].shuffle(random: random) }.should raise_error(RangeError) + -> { [1, 2].shuffle(random: random) }.should.raise(RangeError) end - it "raises a RangeError if the value is equal to one" do + it "raises a RangeError if the value is equal to the Array size" do value = mock("array_shuffle_random_value") - value.should_receive(:to_int).at_least(1).times.and_return(1) + value.should_receive(:to_int).at_least(1).times.and_return(2) random = mock("array_shuffle_random") random.should_receive(:rand).at_least(1).times.and_return(value) - -> { [1, 2].shuffle(random: random) }.should raise_error(RangeError) + -> { [1, 2].shuffle(random: random) }.should.raise(RangeError) + end + + it "raises a RangeError if the value is greater than the Array size" do + value = mock("array_shuffle_random_value") + value.should_receive(:to_int).at_least(1).times.and_return(3) + random = mock("array_shuffle_random") + random.should_receive(:rand).at_least(1).times.and_return(value) + + -> { [1, 2].shuffle(random: random) }.should.raise(RangeError) end end @@ -89,13 +98,13 @@ describe "Array#shuffle!" do a.sort.should == [1, 2, 3, 4] different ||= (a != [1, 2, 3, 4]) end - different.should be_true # Will fail once in a blue moon (4!^10) - a.should equal(original) + different.should == true # Will fail once in a blue moon (4!^10) + a.should.equal?(original) end it "raises a FrozenError on a frozen array" do - -> { ArraySpecs.frozen_array.shuffle! }.should raise_error(FrozenError) - -> { ArraySpecs.empty_frozen_array.shuffle! }.should raise_error(FrozenError) + -> { ArraySpecs.frozen_array.shuffle! }.should.raise(FrozenError) + -> { ArraySpecs.empty_frozen_array.shuffle! }.should.raise(FrozenError) end it "matches CRuby with random:" do |
