diff options
Diffstat (limited to 'spec/ruby/optional/capi/array_spec.rb')
| -rw-r--r-- | spec/ruby/optional/capi/array_spec.rb | 74 |
1 files changed, 55 insertions, 19 deletions
diff --git a/spec/ruby/optional/capi/array_spec.rb b/spec/ruby/optional/capi/array_spec.rb index 8e90980c6a..0b997f774c 100644 --- a/spec/ruby/optional/capi/array_spec.rb +++ b/spec/ruby/optional/capi/array_spec.rb @@ -8,7 +8,7 @@ describe :rb_ary_new2, shared: true do end it "raises an ArgumentError when the given argument is negative" do - -> { @s.send(@method, -1) }.should raise_error(ArgumentError) + -> { @s.send(@method, -1) }.should.raise(ArgumentError) end end @@ -84,7 +84,7 @@ describe "C-API Array function" do end it "raises a FrozenError if the array is frozen" do - -> { @s.rb_ary_cat([].freeze, 1) }.should raise_error(FrozenError) + -> { @s.rb_ary_cat([].freeze, 1) }.should.raise(FrozenError) end end @@ -120,7 +120,7 @@ describe "C-API Array function" do it "returns the original array" do a = [1,2,3] - @s.rb_ary_reverse(a).should equal(a) + @s.rb_ary_reverse(a).should.equal?(a) end end @@ -131,7 +131,7 @@ describe "C-API Array function" do end it "raises a FrozenError if the array is frozen" do - -> { @s.rb_ary_rotate([].freeze, 1) }.should raise_error(FrozenError) + -> { @s.rb_ary_rotate([].freeze, 1) }.should.raise(FrozenError) end end @@ -166,7 +166,7 @@ describe "C-API Array function" do b = @s.rb_ary_dup(a) b.should == a - b.should_not equal(a) + b.should_not.equal?(a) end end @@ -221,7 +221,7 @@ describe "C-API Array function" do it "raises an IndexError if the negative index is greater than the length" do a = [1, 2, 3] - -> { @s.rb_ary_store(a, -10, 5) }.should raise_error(IndexError) + -> { @s.rb_ary_store(a, -10, 5) }.should.raise(IndexError) end it "enlarges the array as needed" do @@ -232,7 +232,7 @@ describe "C-API Array function" do it "raises a FrozenError if the array is frozen" do a = [1, 2, 3].freeze - -> { @s.rb_ary_store(a, 1, 5) }.should raise_error(FrozenError) + -> { @s.rb_ary_store(a, 1, 5) }.should.raise(FrozenError) end end @@ -307,11 +307,11 @@ describe "C-API Array function" do describe "rb_ary_includes" do it "returns true if the array includes the element" do - @s.rb_ary_includes([1, 2, 3], 2).should be_true + @s.rb_ary_includes([1, 2, 3], 2).should == true end it "returns false if the array does not include the element" do - @s.rb_ary_includes([1, 2, 3], 4).should be_false + @s.rb_ary_includes([1, 2, 3], 4).should == false end end @@ -322,7 +322,7 @@ describe "C-API Array function" do end it "returns nil for an out of range index" do - @s.rb_ary_aref([1, 2, 3], 6).should be_nil + @s.rb_ary_aref([1, 2, 3], 6).should == nil end it "returns a new array where the first argument is the index and the second is the length" do @@ -335,7 +335,7 @@ describe "C-API Array function" do end it "returns nil when the start of a range is out of bounds" do - @s.rb_ary_aref([1, 2, 3, 4], 6..10).should be_nil + @s.rb_ary_aref([1, 2, 3, 4], 6..10).should == nil end it "returns an empty array when the start of a range equals the last element" do @@ -343,6 +343,42 @@ describe "C-API Array function" do end end + ruby_version_is ""..."4.0" do + describe "rb_iterate" do + it "calls an callback function as a block passed to an method" do + s = [1,2,3,4] + s2 = @s.rb_iterate(s) + + s2.should == s + + # Make sure they're different objects + s2.equal?(s).should == false + end + + it "calls a function with the other function available as a block" do + h = {a: 1, b: 2} + + @s.rb_iterate_each_pair(h).sort.should == [1,2] + end + + it "calls a function which can yield into the original block" do + s2 = [] + + o = Object.new + def o.each + yield 1 + yield 2 + yield 3 + yield 4 + end + + @s.rb_iterate_then_yield(o) { |x| s2 << x } + + s2.should == [1,2,3,4] + end + end + end + describe "rb_block_call" do it "calls an callback function as a block passed to an method" do s = [1,2,3,4] @@ -351,7 +387,7 @@ describe "C-API Array function" do s2.should == s # Make sure they're different objects - s2.equal?(s).should be_false + s2.equal?(s).should == false end it "calls a function with the other function available as a block" do @@ -386,7 +422,7 @@ describe "C-API Array function" do it "returns nil if the element is not in the array" do ary = [1, 2, 3, 4] - @s.rb_ary_delete(ary, 5).should be_nil + @s.rb_ary_delete(ary, 5).should == nil ary.should == [1, 2, 3, 4] end end @@ -401,7 +437,7 @@ describe "C-API Array function" do it "freezes the object exactly like Kernel#freeze" do ary = [1,2] @s.rb_ary_freeze(ary) - ary.frozen?.should be_true + ary.frozen?.should == true end end @@ -421,12 +457,12 @@ describe "C-API Array function" do end it "returns nil if the index is out of bounds" do - @s.rb_ary_delete_at(@array, 4).should be_nil + @s.rb_ary_delete_at(@array, 4).should == nil @array.should == [1, 2, 3, 4] end it "returns nil if the negative index is out of bounds" do - @s.rb_ary_delete_at(@array, -5).should be_nil + @s.rb_ary_delete_at(@array, -5).should == nil @array.should == [1, 2, 3, 4] end end @@ -437,7 +473,7 @@ describe "C-API Array function" do it "returns the given array" do array = [1, 2, 3] - @s.rb_ary_to_ary(array).should equal(array) + @s.rb_ary_to_ary(array).should.equal?(array) end end @@ -483,7 +519,7 @@ describe "C-API Array function" do end it "returns nil if the begin index is out of bound" do - @s.rb_ary_subseq([1, 2, 3, 4, 5], 6, 3).should be_nil + @s.rb_ary_subseq([1, 2, 3, 4, 5], 6, 3).should == nil end it "returns the existing subsequence of the length is out of bounds" do @@ -491,7 +527,7 @@ describe "C-API Array function" do end it "returns nil if the size is negative" do - @s.rb_ary_subseq([1, 2, 3, 4, 5], 1, -1).should be_nil + @s.rb_ary_subseq([1, 2, 3, 4, 5], 1, -1).should == nil end end end |
