uriescape_spec.rb 1.7 KB

123456789101112131415161718192021222324252627282930313233343536
  1. require 'spec_helper'
  2. describe 'uriescape' 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 URI.escape function' do
  16. URI.expects(:escape).with('uri_string').returns('escaped_uri_string').once
  17. is_expected.to run.with_params('uri_string').and_return('escaped_uri_string')
  18. end
  19. end
  20. describe 'handling classes derived from String' do
  21. it 'calls ruby\'s URI.escape function' do
  22. uri_string = AlsoString.new('uri_string')
  23. URI.expects(:escape).with(uri_string).returns('escaped_uri_string').once
  24. is_expected.to run.with_params(uri_string).and_return('escaped_uri_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%7D', 'two']) }
  30. it { is_expected.to run.with_params(['one}', 1, true, {}, 'two']).and_return(['one%7D', 1, true, {}, 'two']) }
  31. end
  32. end