diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-09-20 20:18:52 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-09-20 20:18:52 +0000 |
commit | 1d15d5f08032acf1b7bceacbb450d617ff6e0931 (patch) | |
tree | a3785a79899302bc149e4a6e72f624ac27dc1f10 /spec/ruby/core/array/rassoc_spec.rb | |
parent | 75bfc6440d595bf339007f4fb280fd4d743e89c1 (diff) | |
download | ruby-1d15d5f08032acf1b7bceacbb450d617ff6e0931.tar.gz |
Move spec/rubyspec to spec/ruby for consistency
* Other ruby implementations use the spec/ruby directory.
[Misc #13792] [ruby-core:82287]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/core/array/rassoc_spec.rb')
-rw-r--r-- | spec/ruby/core/array/rassoc_spec.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/spec/ruby/core/array/rassoc_spec.rb b/spec/ruby/core/array/rassoc_spec.rb new file mode 100644 index 0000000000..cf3daccfc9 --- /dev/null +++ b/spec/ruby/core/array/rassoc_spec.rb @@ -0,0 +1,38 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../fixtures/classes', __FILE__) + +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 |