swapcase_spec.rb 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. require 'spec_helper'
  2. describe 'swapcase' do
  3. it { is_expected.not_to eq(nil) }
  4. it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
  5. it {
  6. pending('Current implementation ignores parameters after the first.')
  7. is_expected.to run.with_params('a', '').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i)
  8. }
  9. it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{Requires either array or string to work}) }
  10. it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, %r{Requires either array or string to work}) }
  11. it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, %r{Requires either array or string to work}) }
  12. describe 'with strings as inputs' do
  13. it { is_expected.to run.with_params('').and_return('') }
  14. it { is_expected.to run.with_params('one').and_return('ONE') }
  15. it { is_expected.to run.with_params('ONE').and_return('one') }
  16. it { is_expected.to run.with_params('oNe').and_return('OnE') }
  17. end
  18. describe 'with arrays as inputs' do
  19. it { is_expected.to run.with_params([]).and_return([]) }
  20. describe 'only containing strings' do
  21. it { is_expected.to run.with_params(['']).and_return(['']) }
  22. it { is_expected.to run.with_params(['one']).and_return(['ONE']) }
  23. it { is_expected.to run.with_params(['ONE']).and_return(['one']) }
  24. it { is_expected.to run.with_params(['oNe']).and_return(['OnE']) }
  25. it { is_expected.to run.with_params(%w[one ONE]).and_return(%w[ONE one]) }
  26. it { is_expected.to run.with_params(%w[ONE OnE]).and_return(%w[one oNe]) }
  27. it { is_expected.to run.with_params(%w[oNe one]).and_return(%w[OnE ONE]) }
  28. end
  29. describe 'containing mixed types' do
  30. it { is_expected.to run.with_params(['OnE', {}]).and_return(['oNe', {}]) }
  31. it { is_expected.to run.with_params(['OnE', 1]).and_return(['oNe', 1]) }
  32. it { is_expected.to run.with_params(['OnE', []]).and_return(['oNe', []]) }
  33. it { is_expected.to run.with_params(['OnE', ['two']]).and_return(['oNe', ['two']]) }
  34. end
  35. end
  36. it 'accepts objects which extend String' do
  37. is_expected.to run.with_params(AlsoString.new('OnE')).and_return('oNe')
  38. end
  39. end