3 describe 'regexpescape' do
4 describe 'signature validation' do
5 it { is_expected.not_to eq(nil) }
6 it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
8 pending("Current implementation ignores parameters after the first.")
9 is_expected.to run.with_params('', '').and_raise_error(Puppet::ParseError, /wrong number of arguments/i)
11 it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /Requires either array or string to work/) }
12 it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /Requires either array or string to work/) }
13 it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, /Requires either array or string to work/) }
16 describe 'handling normal strings' do
17 it 'should call ruby\'s Regexp.escape function' do
18 Regexp.expects(:escape).with('regexp_string').returns('escaped_regexp_string').once
19 is_expected.to run.with_params('regexp_string').and_return('escaped_regexp_string')
23 describe 'handling classes derived from String' do
24 it 'should call ruby\'s Regexp.escape function' do
25 regexp_string = AlsoString.new('regexp_string')
26 Regexp.expects(:escape).with(regexp_string).returns('escaped_regexp_string').once
27 is_expected.to run.with_params(regexp_string).and_return("escaped_regexp_string")
31 describe 'strings in arrays handling' do
32 it { is_expected.to run.with_params([]).and_return([]) }
33 it { is_expected.to run.with_params(['one*', "two"]).and_return(['one\*', "two"]) }
34 it { is_expected.to run.with_params(['one*', 1, true, {}, "two"]).and_return(['one\*', 1, true, {}, "two"]) }
36 context 'should run with UTF8 and double byte characters' do
37 it { is_expected.to run.with_params(['ŏʼnε*']).and_return(['ŏʼnε\*']) }
38 it { is_expected.to run.with_params(['インターネット*']).and_return(['インターネット\*']) }