1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Refactor to @populated

Most of the tests use an @array with data already in it.
This commit is contained in:
☈king 2012-09-17 00:52:53 -06:00 committed by rking@sharpsaw.org
parent 4a7d06ea7e
commit 066725c471

View file

@ -3,6 +3,7 @@ require 'helper'
describe Pry::HistoryArray do describe Pry::HistoryArray do
before do before do
@array = Pry::HistoryArray.new 10 @array = Pry::HistoryArray.new 10
@populated = @array.dup << 1 << 2 << 3 << 4
end end
it 'should have a maximum size specifed at creation time' do it 'should have a maximum size specifed at creation time' do
@ -10,49 +11,40 @@ describe Pry::HistoryArray do
end end
it 'should be able to be added objects to' do it 'should be able to be added objects to' do
@array << 1 << 2 << 3 @populated.size.should == 4
@array.size.should == 3 @populated.to_a.should == [1, 2, 3, 4]
@array.to_a.should == [1, 2, 3]
end end
it 'should be able to access single elements' do it 'should be able to access single elements' do
@array << 1 << 2 << 3 @populated[2].should == 3
@array[2].should == 3
end end
it 'should be able to access negative indices' do it 'should be able to access negative indices' do
@array << 1 << 2 << 3 @populated[-1].should == 4
@array[-1].should == 3
end end
it 'should be able to access ranges' do it 'should be able to access ranges' do
@array << 1 << 2 << 3 << 4 @populated[1..2].should == [2, 3]
@array[1..2].should == [2, 3]
end end
it 'should be able to access ranges starting from a negative index' do it 'should be able to access ranges starting from a negative index' do
@array << 1 << 2 << 3 << 4 @populated[-2..3].should == [3, 4]
@array[-2..3].should == [3, 4]
end end
it 'should be able to access ranges ending at a negative index' do it 'should be able to access ranges ending at a negative index' do
@array << 1 << 2 << 3 << 4 @populated[2..-1].should == [3, 4]
@array[2..-1].should == [3, 4]
end end
it 'should be able to access ranges using only negative indices' do it 'should be able to access ranges using only negative indices' do
@array << 1 << 2 << 3 << 4 @populated[-2..-1].should == [3, 4]
@array[-2..-1].should == [3, 4]
end end
it 'should be able to use range where end is excluded' do it 'should be able to use range where end is excluded' do
@array << 1 << 2 << 3 << 4 @populated[-2...-1].should == [3]
@array[-2...-1].should == [3]
end end
it 'should be able to access slices using a size' do it 'should be able to access slices using a size' do
@array << 1 << 2 << 3 << 4 @populated[-3, 2].should == [2, 3]
@array[-3, 2].should == [2, 3]
end end
it 'should remove older entries' do it 'should remove older entries' do