Updated RubySpec source to b897f30c.
[rbx.git] / spec / frozen / 1.8 / core / array / shared / indexes.rb
blob771f40ed00c53fe8e825b328b1f50acf646145f8
1 describe :array_indexes, :shared => true do
2   it "returns elements at integer argument indexes (DEPRECATED)" do
3     array = [1, 2, 3, 4, 5]
5     x = mock('4')
6     def x.to_int() 4 end
8     params = [1, 0, 5, -1, -8, 10, x]
9     array.send(@method, *params).should == array.values_at(*params)
10   end
11   
12   it "tries to convert the passed arguments to Integers using #to_int" do
13     obj = mock('to_int')
14     obj.should_receive(:to_int).and_return(1, 3)
15     [1, 2, 3, 4, 5].send(@method, obj, obj).should == [2, 4]
16   end
18   it "checks whether the passed arguments respond to #to_int" do
19     obj = mock('method_missing to_int')
20     obj.should_receive(:respond_to?).with(:to_int).any_number_of_times.and_return(true)
21     obj.should_receive(:method_missing).with(:to_int).twice.and_return(1, 3)
22     [1, 2, 3, 4, 5].send(@method, obj, obj).should == [2, 4]
23   end
25   it "returns elements in range arguments as nested arrays (DEPRECATED)" do
26     array = [1, 2, 3, 4, 5]
27     params = [0..2, 1...3, 4..6]
28     array.indexes(*params).should == [[1, 2, 3], [2, 3], [5]]
29     array.indices(*params).should == [[1, 2, 3], [2, 3], [5]]
30   end
31 end