Sha256: b575ca9688e906324026a9ebdbbad368a27b9eec56b5816f5aa7dc3af7ffd769
Contents?: true
Size: 1.32 KB
Versions: 83
Compression:
Stored size: 1.32 KB
Contents
require File.dirname(File.join(__rhoGetCurrentDir(), __FILE__)) + '/../../spec_helper' require File.dirname(File.join(__rhoGetCurrentDir(), __FILE__)) + '/fixtures/classes' describe "Array#rassoc" do it "returns the first contained array whose second element is == object" do ary = [[1, "a", 0.5], [2, "b"], [3, "b"], [4, "c"], [], [5], [6, "d"]] ary.rassoc("a").should == [1, "a", 0.5] ary.rassoc("b").should == [2, "b"] ary.rassoc("d").should == [6, "d"] ary.rassoc("z").should == nil end it "properly handles recursive arrays" do empty = ArraySpecs.empty_recursive_array empty.rassoc([]).should be_nil [[empty, empty]].rassoc(empty).should == [empty, empty] array = ArraySpecs.recursive_array array.rassoc(array).should be_nil [[empty, array]].rassoc(array).should == [empty, array] end it "calls elem == obj on the second element of each contained array" do key = 'foobar' o = mock('foobar') def o.==(other); other == 'foobar'; end [[1, :foobar], [2, o], [3, mock('foo')]].rassoc(key).should == [2, o] end it "does not check the last element in each contained but speficically the second" do key = 'foobar' o = mock('foobar') def o.==(other); other == 'foobar'; end [[1, :foobar, o], [2, o, 1], [3, mock('foo')]].rassoc(key).should == [2, o, 1] end end
Version data entries
83 entries across 83 versions & 1 rubygems