2011-06-29 22:21:55 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-06-01 13:21:59 +02:00
|
|
|
describe 'squeeze' 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 { is_expected.to run.with_params(1).and_raise_error(NoMethodError) }
|
|
|
|
it { is_expected.to run.with_params({}).and_raise_error(NoMethodError) }
|
|
|
|
it { is_expected.to run.with_params(true).and_raise_error(NoMethodError) }
|
2011-06-29 22:21:55 +02:00
|
|
|
|
2015-06-01 13:21:59 +02:00
|
|
|
context 'when squeezing a single string' do
|
|
|
|
it { is_expected.to run.with_params('').and_return('') }
|
|
|
|
it { is_expected.to run.with_params('a').and_return('a') }
|
|
|
|
it { is_expected.to run.with_params('aaaaaaaaa').and_return('a') }
|
|
|
|
it { is_expected.to run.with_params('aaaaaaaaa', 'a').and_return('a') }
|
|
|
|
it { is_expected.to run.with_params('aaaaaaaaabbbbbbbbbbcccccccccc', 'b-c').and_return('aaaaaaaaabc') }
|
2011-06-29 22:21:55 +02:00
|
|
|
end
|
|
|
|
|
2015-06-01 13:21:59 +02:00
|
|
|
context 'when squeezing values in an array' do
|
|
|
|
it {
|
|
|
|
is_expected.to run \
|
|
|
|
.with_params(['', 'a', 'aaaaaaaaa', 'aaaaaaaaabbbbbbbbbbcccccccccc']) \
|
|
|
|
.and_return( ['', 'a', 'a', 'abc'])
|
|
|
|
}
|
|
|
|
it {
|
|
|
|
is_expected.to run \
|
|
|
|
.with_params(['', 'a', 'aaaaaaaaa', 'aaaaaaaaabbbbbbbbbbcccccccccc'], 'a') \
|
|
|
|
.and_return( ['', 'a', 'a', 'abbbbbbbbbbcccccccccc'])
|
|
|
|
}
|
|
|
|
it {
|
|
|
|
is_expected.to run \
|
|
|
|
.with_params(['', 'a', 'aaaaaaaaa', 'aaaaaaaaabbbbbbbbbbcccccccccc'], 'b-c') \
|
|
|
|
.and_return( ['', 'a', 'aaaaaaaaa', 'aaaaaaaaabc'])
|
|
|
|
}
|
2011-06-29 22:21:55 +02:00
|
|
|
end
|
|
|
|
|
2015-06-01 13:21:59 +02:00
|
|
|
context 'when using a class extending String' do
|
|
|
|
it 'should call its squeeze method' do
|
|
|
|
value = AlsoString.new('aaaaaaaaa')
|
|
|
|
value.expects(:squeeze).returns('foo')
|
|
|
|
expect(subject).to run.with_params(value).and_return('foo')
|
|
|
|
end
|
2011-07-24 01:39:17 +02:00
|
|
|
end
|
2011-06-29 22:21:55 +02:00
|
|
|
end
|