reverse_spec.rb 1.8 KB

123456789101112131415161718192021222324252627282930313233
  1. require 'spec_helper'
  2. describe 'reverse' 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([], 'extra').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. it { is_expected.to run.with_params([]).and_return([]) }
  13. it { is_expected.to run.with_params(['a']).and_return(['a']) }
  14. it { is_expected.to run.with_params(['one']).and_return(['one']) }
  15. it { is_expected.to run.with_params(%w[one two three]).and_return(%w[three two one]) }
  16. it { is_expected.to run.with_params(%w[one two three four]).and_return(%w[four three two one]) }
  17. it { is_expected.to run.with_params(%w[ổňë ťŵọ ŧңяəė ƒŏůŗ]).and_return(%w[ƒŏůŗ ŧңяəė ťŵọ ổňë]) }
  18. it { is_expected.to run.with_params('').and_return('') }
  19. it { is_expected.to run.with_params('a').and_return('a') }
  20. it { is_expected.to run.with_params('abc').and_return('cba') }
  21. it { is_expected.to run.with_params('abcd').and_return('dcba') }
  22. it { is_expected.to run.with_params('āβćđ').and_return('đćβā') }
  23. context 'when using a class extending String' do
  24. it 'calls its reverse method' do
  25. value = AlsoString.new('asdfghjkl')
  26. value.expects(:reverse).returns('foo')
  27. expect(subject).to run.with_params(value).and_return('foo')
  28. end
  29. end
  30. end