regexpescape_spec.rb 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. require 'spec_helper'
  2. describe 'regexpescape' do
  3. describe 'signature validation' 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. it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{Requires either array or string to work}) }
  11. it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, %r{Requires either array or string to work}) }
  12. it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, %r{Requires either array or string to work}) }
  13. end
  14. describe 'handling normal strings' do
  15. it 'calls ruby\'s Regexp.escape function' do
  16. Regexp.expects(:escape).with('regexp_string').returns('escaped_regexp_string').once
  17. is_expected.to run.with_params('regexp_string').and_return('escaped_regexp_string')
  18. end
  19. end
  20. describe 'handling classes derived from String' do
  21. it 'calls ruby\'s Regexp.escape function' do
  22. regexp_string = AlsoString.new('regexp_string')
  23. Regexp.expects(:escape).with(regexp_string).returns('escaped_regexp_string').once
  24. is_expected.to run.with_params(regexp_string).and_return('escaped_regexp_string')
  25. end
  26. end
  27. describe 'strings in arrays handling' do
  28. it { is_expected.to run.with_params([]).and_return([]) }
  29. it { is_expected.to run.with_params(['one*', 'two']).and_return(['one\*', 'two']) }
  30. it { is_expected.to run.with_params(['one*', 1, true, {}, 'two']).and_return(['one\*', 1, true, {}, 'two']) }
  31. context 'with UTF8 and double byte characters' do
  32. it { is_expected.to run.with_params(['ŏʼnε*']).and_return(['ŏʼnε\*']) }
  33. it { is_expected.to run.with_params(['インターネット*']).and_return(['インターネット\*']) }
  34. end
  35. end
  36. end