Sha256: d1fcd9149815a7aab06aa6e5253cb954e45b3870fc966b3a587e1d79653394ff

Contents?: true

Size: 1.57 KB

Versions: 79

Compression:

Stored size: 1.57 KB

Contents

require 'helper'

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
    @populated.size.should == 4
    @populated.to_a.should == [1, 2, 3, 4]
  end

  it 'should be able to access single elements' do
    @populated[2].should == 3
  end

  it 'should be able to access negative indices' do
    @populated[-1].should == 4
  end

  it 'should be able to access ranges' do
    @populated[1..2].should == [2, 3]
  end

  it 'should be able to access ranges starting from a negative index' do
    @populated[-2..3].should == [3, 4]
  end

  it 'should be able to access ranges ending at a negative index' do
    @populated[2..-1].should == [3, 4]
  end

  it 'should be able to access ranges using only negative indices' do
    @populated[-2..-1].should == [3, 4]
  end

  it 'should be able to use range where end is excluded' do
    @populated[-2...-1].should == [3]
  end

  it 'should be able to access slices using a size' do
    @populated[-3, 2].should == [2, 3]
  end

  it 'should remove older entries' do
    11.times { |n| @array << n }

    @array[0].should  == nil
    @array[1].should  == 1
    @array[10].should == 10
  end

  it 'should not be larger than specified maximum size' do
    12.times { |n| @array << n }
    @array.entries.compact.size.should == 10
  end

  it 'should pop!' do
    @populated.pop!
    @populated.to_a.should == [1, 2, 3]
  end
end

Version data entries

79 entries across 79 versions & 5 rubygems

Version Path
asana2flowdock-1.0.0 vendor/bundle/ruby/1.9.1/gems/pry-0.9.12.6/spec/history_array_spec.rb
pry-0.9.12.6 spec/history_array_spec.rb
pry-0.9.12.6-i386-mswin32 spec/history_array_spec.rb
pry-0.9.12.6-i386-mingw32 spec/history_array_spec.rb
pry-0.9.12.6-java spec/history_array_spec.rb
pry-0.9.12.5 spec/history_array_spec.rb
pry-0.9.12.5-i386-mswin32 spec/history_array_spec.rb
pry-0.9.12.5-i386-mingw32 spec/history_array_spec.rb
pry-0.9.12.5-java spec/history_array_spec.rb
pry-0.9.12.4 spec/history_array_spec.rb
pry-0.9.12.4-i386-mswin32 spec/history_array_spec.rb
pry-0.9.12.4-i386-mingw32 spec/history_array_spec.rb
pry-0.9.12.4-java spec/history_array_spec.rb
pry-0.9.12.3 spec/history_array_spec.rb
pry-0.9.12.3-i386-mswin32 spec/history_array_spec.rb
pry-0.9.12.3-i386-mingw32 spec/history_array_spec.rb
pry-0.9.12.3-java spec/history_array_spec.rb
torquebox-console-0.3.0 vendor/bundle/jruby/1.9/gems/pry-0.9.12-java/spec/history_array_spec.rb
sshp-0.0.2 vendor/ruby/1.9.1/gems/pry-0.9.12.2/spec/history_array_spec.rb
sshp-0.0.1 vendor/ruby/1.9.1/gems/pry-0.9.12.2/spec/history_array_spec.rb