Permalink
Browse files

Refactor to @populated

Most of the tests use an @array with data already in it.
  • Loading branch information...
1 parent 4a7d06e commit 066725c471e021671098c08a2f089c71909ddfe1 @rking rking committed with rking@sharpsaw.org Sep 17, 2012
Showing with 11 additions and 19 deletions.
  1. +11 −19 test/test_history_array.rb
View
@@ -3,56 +3,48 @@
describe Pry::HistoryArray do
before do
@array = Pry::HistoryArray.new 10
+ @populated = @array.dup << 1 << 2 << 3 << 4
end
it 'should have a maximum size specifed at creation time' do
@array.max_size.should == 10
end
it 'should be able to be added objects to' do
- @array << 1 << 2 << 3
- @array.size.should == 3
- @array.to_a.should == [1, 2, 3]
+ @populated.size.should == 4
+ @populated.to_a.should == [1, 2, 3, 4]
end
it 'should be able to access single elements' do
- @array << 1 << 2 << 3
- @array[2].should == 3
+ @populated[2].should == 3
end
it 'should be able to access negative indices' do
- @array << 1 << 2 << 3
- @array[-1].should == 3
+ @populated[-1].should == 4
end
it 'should be able to access ranges' do
- @array << 1 << 2 << 3 << 4
- @array[1..2].should == [2, 3]
+ @populated[1..2].should == [2, 3]
end
it 'should be able to access ranges starting from a negative index' do
- @array << 1 << 2 << 3 << 4
- @array[-2..3].should == [3, 4]
+ @populated[-2..3].should == [3, 4]
end
it 'should be able to access ranges ending at a negative index' do
- @array << 1 << 2 << 3 << 4
- @array[2..-1].should == [3, 4]
+ @populated[2..-1].should == [3, 4]
end
it 'should be able to access ranges using only negative indices' do
- @array << 1 << 2 << 3 << 4
- @array[-2..-1].should == [3, 4]
+ @populated[-2..-1].should == [3, 4]
end
it 'should be able to use range where end is excluded' do
- @array << 1 << 2 << 3 << 4
- @array[-2...-1].should == [3]
+ @populated[-2...-1].should == [3]
end
it 'should be able to access slices using a size' do
- @array << 1 << 2 << 3 << 4
- @array[-3, 2].should == [2, 3]
+ @populated[-3, 2].should == [2, 3]
end
it 'should remove older entries' do

0 comments on commit 066725c

Please sign in to comment.