Update stdlib and concat to 6.1.0 both
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / validate_re_spec.rb
1 require 'spec_helper'
2
3 describe 'validate_re' do
4   after(:each) do
5     ENV.delete('STDLIB_LOG_DEPRECATIONS')
6   end
7
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('', '')
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, %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('', '', '', 'extra').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
20
21     describe 'valid inputs' do
22       it { is_expected.to run.with_params('', '') }
23       it { is_expected.to run.with_params('', ['']) }
24       it { is_expected.to run.with_params('', [''], 'custom error') }
25       it { is_expected.to run.with_params('one', '^one') }
26       it { is_expected.to run.with_params('one', ['^one', '^two']) }
27       it { is_expected.to run.with_params('one', ['^one', '^two'], 'custom error') }
28     end
29
30     describe 'invalid inputs' do
31       it { is_expected.to run.with_params('', []).and_raise_error(Puppet::ParseError, %r{does not match}) }
32       it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, %r{does not match}) }
33       it { is_expected.to run.with_params('', 'two').and_raise_error(Puppet::ParseError, %r{does not match}) }
34       it { is_expected.to run.with_params('', ['two']).and_raise_error(Puppet::ParseError, %r{does not match}) }
35       it { is_expected.to run.with_params('', ['two'], 'custom error').and_raise_error(Puppet::ParseError, %r{custom error}) }
36       it { is_expected.to run.with_params('notone', '^one').and_raise_error(Puppet::ParseError, %r{does not match}) }
37       it { is_expected.to run.with_params('notone', ['^one', '^two']).and_raise_error(Puppet::ParseError, %r{does not match}) }
38       it { is_expected.to run.with_params('notone', ['^one', '^two'], 'custom error').and_raise_error(Puppet::ParseError, %r{custom error}) }
39     end
40
41     describe 'non-string inputs' do
42       [
43         1,                  # Fixnum
44         3.14,               # Float
45         nil,                # NilClass
46         true,               # TrueClass
47         false,              # FalseClass
48         ['10'],             # Array
49         :key,               # Symbol
50         { :key => 'val' },  # Hash
51       ].each do |input|
52         it { is_expected.to run.with_params(input, '.*').and_raise_error(Puppet::ParseError, %r{needs to be a String}) }
53       end
54     end
55   end
56 end