Update puppetlabs/stdlib module
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / is_string_spec.rb
1 require 'spec_helper'
2
3 describe 'is_string' do
4   it { is_expected.not_to eq(nil) }
5   it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
6   it {
7     pending('Current implementation ignores parameters after the first.')
8     is_expected.to run.with_params('', '').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i)
9   }
10
11   it { is_expected.to run.with_params(3).and_return(false) }
12   it { is_expected.to run.with_params('3').and_return(false) }
13   it { is_expected.to run.with_params(-3).and_return(false) }
14   it { is_expected.to run.with_params('-3').and_return(false) }
15
16   it { is_expected.to run.with_params(3.7).and_return(false) }
17   it { is_expected.to run.with_params('3.7').and_return(false) }
18   it { is_expected.to run.with_params(-3.7).and_return(false) }
19   it { is_expected.to run.with_params('-3.7').and_return(false) }
20
21   it { is_expected.to run.with_params([]).and_return(false) }
22   it { is_expected.to run.with_params([1]).and_return(false) }
23   it { is_expected.to run.with_params({}).and_return(false) }
24   it { is_expected.to run.with_params(true).and_return(false) }
25   it { is_expected.to run.with_params(false).and_return(false) }
26   it { is_expected.to run.with_params('one').and_return(true) }
27   it { is_expected.to run.with_params('0001234').and_return(true) }
28
29   context 'with  deprecation warning' do
30     after(:each) do
31       ENV.delete('STDLIB_LOG_DEPRECATIONS')
32     end
33     # Checking for deprecation warning, which should only be provoked when the env variable for it is set.
34     it 'displays a single deprecation' do
35       ENV['STDLIB_LOG_DEPRECATIONS'] = 'true'
36       expect(scope).to receive(:warning).with(include('This method is deprecated'))
37       is_expected.to run.with_params('sponge').and_return(true)
38     end
39     it 'displays no warning for deprecation' do
40       ENV['STDLIB_LOG_DEPRECATIONS'] = 'false'
41       expect(scope).to receive(:warning).with(include('This method is deprecated')).never
42       is_expected.to run.with_params('bob').and_return(true)
43     end
44   end
45 end