diff options
Diffstat (limited to 'spec/ruby/core/array/unshift_spec.rb')
| -rw-r--r-- | spec/ruby/core/array/unshift_spec.rb | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/spec/ruby/core/array/unshift_spec.rb b/spec/ruby/core/array/unshift_spec.rb index 9467a1a6df..c190db4d02 100644 --- a/spec/ruby/core/array/unshift_spec.rb +++ b/spec/ruby/core/array/unshift_spec.rb @@ -1,12 +1,12 @@ -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../fixtures/classes', __FILE__) +require_relative '../../spec_helper' +require_relative 'fixtures/classes' describe "Array#unshift" do it "prepends object to the original array" do a = [1, 2, 3] - a.unshift("a").should equal(a) + a.unshift("a").should.equal?(a) a.should == ['a', 1, 2, 3] - a.unshift().should equal(a) + a.unshift.should.equal?(a) a.should == ['a', 1, 2, 3] a.unshift(5, 4, 3) a.should == [5, 4, 3, 'a', 1, 2, 3] @@ -25,9 +25,13 @@ describe "Array#unshift" do a.should == [3, 4] end + it "returns self" do + a = [1, 2, 3] + a.unshift("a").should.equal?(a) + end + it "quietly ignores unshifting nothing" do - [].unshift().should == [] - [].unshift(*[]).should == [] + [].unshift.should == [] end it "properly handles recursive arrays" do @@ -39,12 +43,25 @@ describe "Array#unshift" do array[0..5].should == [:new, 1, 'two', 3.0, array, array] end - it "raises a RuntimeError on a frozen array when the array is modified" do - lambda { ArraySpecs.frozen_array.unshift(1) }.should raise_error(RuntimeError) + it "raises a FrozenError on a frozen array when the array is modified" do + -> { ArraySpecs.frozen_array.unshift(1) }.should.raise(FrozenError) end # see [ruby-core:23666] - it "raises a RuntimeError on a frozen array when the array would not be modified" do - lambda { ArraySpecs.frozen_array.unshift }.should raise_error(RuntimeError) + it "raises a FrozenError on a frozen array when the array would not be modified" do + -> { ArraySpecs.frozen_array.unshift }.should.raise(FrozenError) + end + + # https://github.com/truffleruby/truffleruby/issues/2772 + it "doesn't rely on Array#[]= so it can be overridden" do + subclass = Class.new(Array) do + def []=(*) + raise "[]= is called" + end + end + + array = subclass.new + array.unshift(1) + array.should == [1] end end |
