3 describe 'validate_integer' 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(3)
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(1, 2, 3, 4).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
20 [true, 'true', false, 'false', 'iAmAString', '1test', '1 test', 'test 1', 'test 1 test', 7.0, -7.0, {}, { 'key' => 'value' }, { 1 => 2 }, '', :undef, 'x'].each do |invalid|
21 it { is_expected.to run.with_params(invalid).and_raise_error(Puppet::ParseError, %r{to be an Integer}) }
22 it { is_expected.to run.with_params(invalid, 10).and_raise_error(Puppet::ParseError, %r{to be an Integer}) }
23 it { is_expected.to run.with_params(invalid, 10, -10).and_raise_error(Puppet::ParseError, %r{to be an Integer}) }
24 it { is_expected.to run.with_params([0, 1, 2, invalid, 3, 4], 10, -10).and_raise_error(Puppet::ParseError, %r{to be an Integer}) }
27 context 'when running on modern rubies', :unless => RUBY_VERSION == '1.8.7' do
28 it { is_expected.to run.with_params([0, 1, 2, { 1 => 2 }, 3, 4], 10, -10).and_raise_error(Puppet::ParseError, %r{to be an Integer}) }
31 context 'when running on ruby, which munges hashes weirdly', :if => RUBY_VERSION == '1.8.7' do
32 it { is_expected.to run.with_params([0, 1, 2, { 1 => 2 }, 3, 4], 10, -10).and_raise_error(Puppet::ParseError) }
33 it { is_expected.to run.with_params([0, 1, 2, { 0 => 2 }, 3, 4], 10, -10).and_raise_error(Puppet::ParseError) }
36 it { is_expected.to run.with_params(1, '').and_raise_error(Puppet::ParseError, %r{to be unset or an Integer}) }
37 it { is_expected.to run.with_params(1, 2, '').and_raise_error(Puppet::ParseError, %r{to be unset or an Integer}) }
38 it { is_expected.to run.with_params(1, 2, 3).and_raise_error(Puppet::ParseError, %r{second argument to be larger than third argument}) }
41 context 'with no range constraints' do
42 it { is_expected.to run.with_params(1) }
43 it { is_expected.to run.with_params(-1) }
44 it { is_expected.to run.with_params('1') }
45 it { is_expected.to run.with_params('-1') }
46 it { is_expected.to run.with_params([1, 2, 3, 4]) }
47 it { is_expected.to run.with_params([1, '2', '3', 4]) }
50 context 'with a maximum limit of 10' do
51 describe 'rejects numbers greater than the limit' do
52 it { is_expected.to run.with_params(11, 10).and_raise_error(Puppet::ParseError, %r{to be smaller or equal}) }
53 it { is_expected.to run.with_params(100, 10).and_raise_error(Puppet::ParseError, %r{to be smaller or equal}) }
54 it { is_expected.to run.with_params(2**65, 10).and_raise_error(Puppet::ParseError, %r{to be smaller or equal}) }
55 it { is_expected.to run.with_params([1, 2, 10, 100], 10).and_raise_error(Puppet::ParseError, %r{to be smaller or equal}) }
58 describe 'accepts numbers less or equal to the limit' do
59 it { is_expected.to run.with_params(10, 10) }
60 it { is_expected.to run.with_params(1, 10) }
61 it { is_expected.to run.with_params(-1, 10) }
62 it { is_expected.to run.with_params('1', 10) }
63 it { is_expected.to run.with_params('-1', 10) }
64 it { is_expected.to run.with_params([1, 2, 3, 4], 10) }
65 it { is_expected.to run.with_params([1, '2', '3', 4], 10) }
69 context 'with a minimum limit of -10' do
70 describe 'rejects numbers greater than the upper limit' do
71 it { is_expected.to run.with_params(11, 10, -10).and_raise_error(Puppet::ParseError, %r{to be smaller or equal}) }
72 it { is_expected.to run.with_params(100, 10, -10).and_raise_error(Puppet::ParseError, %r{to be smaller or equal}) }
73 it { is_expected.to run.with_params(2**65, 10, -10).and_raise_error(Puppet::ParseError, %r{to be smaller or equal}) }
74 it { is_expected.to run.with_params([1, 2, 10, 100], 10, -10).and_raise_error(Puppet::ParseError, %r{to be smaller or equal}) }
77 describe 'rejects numbers smaller than the lower limit' do
78 it { is_expected.to run.with_params(-11, 10, -10).and_raise_error(Puppet::ParseError, %r{to be greater or equal}) }
79 it { is_expected.to run.with_params(-100, 10, -10).and_raise_error(Puppet::ParseError, %r{to be greater or equal}) }
80 it { is_expected.to run.with_params(-2**65, 10, -10).and_raise_error(Puppet::ParseError, %r{to be greater or equal}) }
81 it { is_expected.to run.with_params([-10, 1, 2, 10, -100], 10, -10).and_raise_error(Puppet::ParseError, %r{to be greater or equal}) }
84 describe 'accepts numbers between and including the limits' do
85 it { is_expected.to run.with_params(10, 10, -10) }
86 it { is_expected.to run.with_params(-10, 10, -10) }
87 it { is_expected.to run.with_params(1, 10, -10) }
88 it { is_expected.to run.with_params(-1, 10, -10) }
89 it { is_expected.to run.with_params('1', 10, -10) }
90 it { is_expected.to run.with_params('-1', 10, -10) }
91 it { is_expected.to run.with_params([1, 2, 3, 4], 10, -10) }
92 it { is_expected.to run.with_params([1, '2', '3', 4], 10, -10) }
96 it { is_expected.to run.with_params(10, 10, 10) }
98 describe 'empty upper limit is interpreted as infinity' do
99 it { is_expected.to run.with_params(11, '', 10) }