| 1 | require 'spec_helper'
|
|---|
| 2 |
|
|---|
| 3 | describe 'squeeze' do
|
|---|
| 4 | it { is_expected.not_to eq(nil) }
|
|---|
| 5 | it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
|
|---|
| 6 | it { is_expected.to run.with_params('', '', '').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
|
|---|
| 7 | it { is_expected.to run.with_params(1).and_raise_error(NoMethodError) }
|
|---|
| 8 | it { is_expected.to run.with_params({}).and_raise_error(NoMethodError) }
|
|---|
| 9 | it { is_expected.to run.with_params(true).and_raise_error(NoMethodError) }
|
|---|
| 10 |
|
|---|
| 11 | context 'when squeezing a single string' do
|
|---|
| 12 | it { is_expected.to run.with_params('').and_return('') }
|
|---|
| 13 | it { is_expected.to run.with_params('a').and_return('a') }
|
|---|
| 14 | it { is_expected.to run.with_params('aaaaaaaaa').and_return('a') }
|
|---|
| 15 | it { is_expected.to run.with_params('aaaaaaaaa', 'a').and_return('a') }
|
|---|
| 16 | it { is_expected.to run.with_params('aaaaaaaaabbbbbbbbbbcccccccccc', 'b-c').and_return('aaaaaaaaabc') }
|
|---|
| 17 | end
|
|---|
| 18 |
|
|---|
| 19 | context 'when squeezing values in an array' do
|
|---|
| 20 | it {
|
|---|
| 21 | is_expected.to run \
|
|---|
| 22 | .with_params(['', 'a', 'aaaaaaaaa', 'aaaaaaaaabbbbbbbbbbcccccccccc']) \
|
|---|
| 23 | .and_return( ['', 'a', 'a', 'abc'])
|
|---|
| 24 | }
|
|---|
| 25 | it {
|
|---|
| 26 | is_expected.to run \
|
|---|
| 27 | .with_params(['', 'a', 'aaaaaaaaa', 'aaaaaaaaabbbbbbbbbbcccccccccc'], 'a') \
|
|---|
| 28 | .and_return( ['', 'a', 'a', 'abbbbbbbbbbcccccccccc'])
|
|---|
| 29 | }
|
|---|
| 30 | it {
|
|---|
| 31 | is_expected.to run \
|
|---|
| 32 | .with_params(['', 'a', 'aaaaaaaaa', 'aaaaaaaaabbbbbbbbbbcccccccccc'], 'b-c') \
|
|---|
| 33 | .and_return( ['', 'a', 'aaaaaaaaa', 'aaaaaaaaabc'])
|
|---|
| 34 | }
|
|---|
| 35 | end
|
|---|
| 36 |
|
|---|
| 37 | context 'when using a class extending String' do
|
|---|
| 38 | it 'should call its squeeze method' do
|
|---|
| 39 | value = AlsoString.new('aaaaaaaaa')
|
|---|
| 40 | value.expects(:squeeze).returns('foo')
|
|---|
| 41 | expect(subject).to run.with_params(value).and_return('foo')
|
|---|
| 42 | end
|
|---|
| 43 | end
|
|---|
| 44 | end
|
|---|