1 | require 'spec_helper'
|
---|
2 |
|
---|
3 | describe 'validate_slength' do
|
---|
4 | after(:all) do
|
---|
5 | ENV.delete('STDLIB_LOG_DEPRECATIONS')
|
---|
6 | end
|
---|
7 |
|
---|
8 | # Checking for deprecation warning
|
---|
9 | it 'should display a single deprecation' do
|
---|
10 | ENV['STDLIB_LOG_DEPRECATIONS'] = "true"
|
---|
11 | scope.expects(:warning).with(includes('This method is deprecated'))
|
---|
12 | is_expected.to run.with_params('1234567890', 10)
|
---|
13 | end
|
---|
14 |
|
---|
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, /wrong number of arguments/i) }
|
---|
18 | it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
|
---|
19 | it { is_expected.to run.with_params('', 2, 3, 'extra').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
|
---|
20 | it { is_expected.to run.with_params('', '').and_raise_error(Puppet::ParseError, /second argument to be a positive Numeric/) }
|
---|
21 | it { is_expected.to run.with_params('', -1).and_raise_error(Puppet::ParseError, /second argument to be a positive Numeric/) }
|
---|
22 | it { is_expected.to run.with_params('', 1, '').and_raise_error(Puppet::ParseError, /third argument to be unset or a positive Numeric/) }
|
---|
23 | it { is_expected.to run.with_params('', 1, -1).and_raise_error(Puppet::ParseError, /third argument to be unset or a positive Numeric/) }
|
---|
24 | it { is_expected.to run.with_params('', 1, 2).and_raise_error(Puppet::ParseError, /argument to be equal to or larger than third argument/) }
|
---|
25 | end
|
---|
26 |
|
---|
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, /Expected length/) }
|
---|
30 | it { is_expected.to run.with_params('1234567890abcdef', 10).and_raise_error(Puppet::ParseError, /Expected length/) }
|
---|
31 | it { is_expected.to run.with_params([ 'one', '1234567890abcdef' ], 10).and_raise_error(Puppet::ParseError, /Expected length/) }
|
---|
32 | end
|
---|
33 |
|
---|
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) }
|
---|
38 | end
|
---|
39 |
|
---|
40 | context "with a minimum length of 5" do
|
---|
41 | describe 'rejects strings longer than the upper limit' do
|
---|
42 | it { is_expected.to run.with_params('1234567890a', 10, 5).and_raise_error(Puppet::ParseError, /Expected length/) }
|
---|
43 | it { is_expected.to run.with_params('1234567890abcdef', 10, 5).and_raise_error(Puppet::ParseError, /Expected length/) }
|
---|
44 | end
|
---|
45 |
|
---|
46 | describe 'rejects numbers shorter than the lower limit' do
|
---|
47 | it { is_expected.to run.with_params('one', 10, 5).and_raise_error(Puppet::ParseError, /Expected length/) }
|
---|
48 | it { is_expected.to run.with_params(['12345678', 'two'], 10, 5).and_raise_error(Puppet::ParseError, /Expected length/) }
|
---|
49 | end
|
---|
50 |
|
---|
51 | describe 'accepts strings of length between and including the limits' do
|
---|
52 | it { is_expected.to run.with_params('12345', 10, 5) }
|
---|
53 | it { is_expected.to run.with_params('123456', 10, 5) }
|
---|
54 | it { is_expected.to run.with_params('1234567', 10, 5) }
|
---|
55 | it { is_expected.to run.with_params('12345678', 10, 5) }
|
---|
56 | it { is_expected.to run.with_params('123456789', 10, 5) }
|
---|
57 | it { is_expected.to run.with_params('1234567890', 10, 5) }
|
---|
58 | it { is_expected.to run.with_params(['1233456', '12345678'], 10, 5) }
|
---|
59 | end
|
---|
60 | end
|
---|
61 | end
|
---|
62 |
|
---|
63 | describe 'corner cases' do
|
---|
64 | it { pending('this should work'); is_expected.to run.with_params('', 0, 0) }
|
---|
65 | it { is_expected.to run.with_params('1234567890', 10, 10) }
|
---|
66 | end
|
---|
67 |
|
---|
68 | describe 'empty upper limit is interpreted as infinity' do
|
---|
69 | it { pending('not implemented'); is_expected.to run.with_params('1234567890ab', '', 10) }
|
---|
70 | it { pending('not implemented'); is_expected.to run.with_params('12345678', '', 10).and_raise_error(Puppet::ParseError, /Expected length/) }
|
---|
71 | end
|
---|
72 | end
|
---|