2011-06-29 22:21:55 +02:00
require 'spec_helper'
2015-06-01 13:21:59 +02:00
describe 'values_at' do
describe 'signature validation' do
it { is_expected . not_to eq ( nil ) }
it { is_expected . to run . with_params ( ) . and_raise_error ( Puppet :: ParseError , / wrong number of arguments /i ) }
it { is_expected . to run . with_params ( [ ] ) . and_raise_error ( Puppet :: ParseError , / wrong number of arguments /i ) }
it {
pending ( " Current implementation ignores parameters after the first two. " )
is_expected . to run . with_params ( [ ] , 0 , 1 ) . and_raise_error ( Puppet :: ParseError , / wrong number of arguments /i )
}
it { is_expected . to run . with_params ( '' , 1 ) . and_raise_error ( Puppet :: ParseError , / Requires array /i ) }
it { is_expected . to run . with_params ( { } , 1 ) . and_raise_error ( Puppet :: ParseError , / Requires array /i ) }
it { is_expected . to run . with_params ( true , 1 ) . and_raise_error ( Puppet :: ParseError , / Requires array /i ) }
it { is_expected . to run . with_params ( 1 , 1 ) . and_raise_error ( Puppet :: ParseError , / Requires array /i ) }
it { is_expected . to run . with_params ( [ 0 , 1 , 2 ] , 'two' ) . and_raise_error ( Puppet :: ParseError , / Unknown format of given index / ) }
it { is_expected . to run . with_params ( [ 0 , 1 , 2 ] , [ ] ) . and_raise_error ( Puppet :: ParseError , / provide at least one positive index / ) }
it { is_expected . to run . with_params ( [ 0 , 1 , 2 ] , '-1-1' ) . and_raise_error ( Puppet :: ParseError , / Unknown format of given index / ) }
it { is_expected . to run . with_params ( [ 0 , 1 , 2 ] , '2-1' ) . and_raise_error ( Puppet :: ParseError , / Stop index in given indices range is smaller than the start index / ) }
2011-07-29 22:17:19 +02:00
end
2015-06-01 13:21:59 +02:00
context 'when requesting a single item' do
it { is_expected . to run . with_params ( [ 0 , 1 , 2 ] , - 1 ) . and_raise_error ( Puppet :: ParseError , / Unknown format of given index / ) }
it { is_expected . to run . with_params ( [ 0 , 1 , 2 ] , 0 ) . and_return ( [ 0 ] ) }
it { is_expected . to run . with_params ( [ 0 , 1 , 2 ] , 1 ) . and_return ( [ 1 ] ) }
it { is_expected . to run . with_params ( [ 0 , 1 , 2 ] , [ 1 ] ) . and_return ( [ 1 ] ) }
it { is_expected . to run . with_params ( [ 0 , 1 , 2 ] , '1' ) . and_return ( [ 1 ] ) }
it { is_expected . to run . with_params ( [ 0 , 1 , 2 ] , '1-1' ) . and_return ( [ 1 ] ) }
it { is_expected . to run . with_params ( [ 0 , 1 , 2 ] , 2 ) . and_return ( [ 2 ] ) }
it { is_expected . to run . with_params ( [ 0 , 1 , 2 ] , 3 ) . and_raise_error ( Puppet :: ParseError , / index exceeds array size / ) }
2011-07-29 22:17:19 +02:00
end
2015-06-01 13:21:59 +02:00
context 'when requesting multiple items' do
it { is_expected . to run . with_params ( [ 0 , 1 , 2 ] , [ 1 , - 1 ] ) . and_raise_error ( Puppet :: ParseError , / Unknown format of given index / ) }
it { is_expected . to run . with_params ( [ 0 , 1 , 2 ] , [ 0 , 2 ] ) . and_return ( [ 0 , 2 ] ) }
it { is_expected . to run . with_params ( [ 0 , 1 , 2 ] , [ '0-2' , 1 , 2 ] ) . and_return ( [ 0 , 1 , 2 , 1 , 2 ] ) }
it { is_expected . to run . with_params ( [ 0 , 1 , 2 ] , [ 3 , 2 ] ) . and_raise_error ( Puppet :: ParseError , / index exceeds array size / ) }
describe 'different range syntaxes' do
it { is_expected . to run . with_params ( [ 0 , 1 , 2 ] , '0-2' ) . and_return ( [ 0 , 1 , 2 ] ) }
it { is_expected . to run . with_params ( [ 0 , 1 , 2 ] , '0..2' ) . and_return ( [ 0 , 1 , 2 ] ) }
it { is_expected . to run . with_params ( [ 0 , 1 , 2 ] , '0...2' ) . and_return ( [ 0 , 1 ] ) }
it {
pending ( 'fix this bounds check' )
is_expected . to run . with_params ( [ 0 , 1 , 2 ] , '0...3' ) . and_return ( [ 0 , 1 , 2 ] )
}
end
2011-07-29 22:17:19 +02:00
end
2011-06-29 22:21:55 +02:00
end