3 describe 'validate_slength' do
5 ENV.delete('STDLIB_LOG_DEPRECATIONS')
8 # Checking for deprecation warning
9 it 'displays a single deprecation' do
10 ENV['STDLIB_LOG_DEPRECATIONS'] = 'true'
11 expect(scope).to receive(:warning).with(include('This method is deprecated'))
12 is_expected.to run.with_params('1234567890', 10)
15 describe 'signature validation' do
16 it { is_expected.not_to eq(nil) }
17 it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
18 it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
19 it { is_expected.to run.with_params('', 2, 3, 'extra').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
20 it { is_expected.to run.with_params('', '').and_raise_error(Puppet::ParseError, %r{second argument to be a positive Numeric}) }
21 it { is_expected.to run.with_params('', -1).and_raise_error(Puppet::ParseError, %r{second argument to be a positive Numeric}) }
22 it { is_expected.to run.with_params('', 1, '').and_raise_error(Puppet::ParseError, %r{third argument to be unset or a positive Numeric}) }
23 it { is_expected.to run.with_params('', 1, -1).and_raise_error(Puppet::ParseError, %r{third argument to be unset or a positive Numeric}) }
24 it { is_expected.to run.with_params('', 1, 2).and_raise_error(Puppet::ParseError, %r{argument to be equal to or larger than third argument}) }
27 context 'with a maximum length of 10' do
28 describe 'rejects strings longer than the limit' do
29 it { is_expected.to run.with_params('1234567890a', 10).and_raise_error(Puppet::ParseError, %r{Expected length}) }
30 it { is_expected.to run.with_params('1234567890abcdef', 10).and_raise_error(Puppet::ParseError, %r{Expected length}) }
31 it { is_expected.to run.with_params(['one', '1234567890abcdef'], 10).and_raise_error(Puppet::ParseError, %r{Expected length}) }
34 describe 'accepts strings shorter or equal to the limit' do
35 it { is_expected.to run.with_params('1234567890', 10) }
36 it { is_expected.to run.with_params('12345', 10) }
37 it { is_expected.to run.with_params(['one', 'two'], 10) }
41 context 'with a minimum length of 5' do
42 describe 'rejects strings longer than the upper limit' do
43 it { is_expected.to run.with_params('1234567890a', 10, 5).and_raise_error(Puppet::ParseError, %r{Expected length}) }
44 it { is_expected.to run.with_params('1234567890abcdef', 10, 5).and_raise_error(Puppet::ParseError, %r{Expected length}) }
47 describe 'rejects numbers shorter than the lower limit' do
48 it { is_expected.to run.with_params('one', 10, 5).and_raise_error(Puppet::ParseError, %r{Expected length}) }
49 it { is_expected.to run.with_params(['12345678', 'two'], 10, 5).and_raise_error(Puppet::ParseError, %r{Expected length}) }
52 describe 'accepts strings of length between and including the limits' do
53 it { is_expected.to run.with_params('12345', 10, 5) }
54 it { is_expected.to run.with_params('123456', 10, 5) }
55 it { is_expected.to run.with_params('1234567', 10, 5) }
56 it { is_expected.to run.with_params('12345678', 10, 5) }
57 it { is_expected.to run.with_params('123456789', 10, 5) }
58 it { is_expected.to run.with_params('1234567890', 10, 5) }
59 it { is_expected.to run.with_params(['1233456', '12345678'], 10, 5) }
63 describe 'corner cases' do
65 pending('this should work')
66 is_expected.to run.with_params('', 0, 0)
68 it { is_expected.to run.with_params('1234567890', 10, 10) }
71 describe 'empty upper limit is interpreted as infinity' do
73 pending('not implemented')
74 is_expected.to run.with_params('1234567890ab', '', 10)
77 pending('not implemented')
78 is_expected.to run.with_params('12345678', '', 10).and_raise_error(Puppet::ParseError, %r{Expected length})