validate_re_spec.rb 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. require 'spec_helper'
  2. describe 'validate_re' do
  3. after(:each) do
  4. ENV.delete('STDLIB_LOG_DEPRECATIONS')
  5. end
  6. # Checking for deprecation warning
  7. it 'displays a single deprecation' do
  8. ENV['STDLIB_LOG_DEPRECATIONS'] = 'true'
  9. scope.expects(:warning).with(includes('This method is deprecated'))
  10. is_expected.to run.with_params('', '')
  11. end
  12. describe 'signature validation' do
  13. it { is_expected.not_to eq(nil) }
  14. it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
  15. it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
  16. it { is_expected.to run.with_params('', '', '', 'extra').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
  17. describe 'valid inputs' do
  18. it { is_expected.to run.with_params('', '') }
  19. it { is_expected.to run.with_params('', ['']) }
  20. it { is_expected.to run.with_params('', [''], 'custom error') }
  21. it { is_expected.to run.with_params('one', '^one') }
  22. it { is_expected.to run.with_params('one', ['^one', '^two']) }
  23. it { is_expected.to run.with_params('one', ['^one', '^two'], 'custom error') }
  24. end
  25. describe 'invalid inputs' do
  26. it { is_expected.to run.with_params('', []).and_raise_error(Puppet::ParseError, %r{does not match}) }
  27. it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, %r{does not match}) }
  28. it { is_expected.to run.with_params('', 'two').and_raise_error(Puppet::ParseError, %r{does not match}) }
  29. it { is_expected.to run.with_params('', ['two']).and_raise_error(Puppet::ParseError, %r{does not match}) }
  30. it { is_expected.to run.with_params('', ['two'], 'custom error').and_raise_error(Puppet::ParseError, %r{custom error}) }
  31. it { is_expected.to run.with_params('notone', '^one').and_raise_error(Puppet::ParseError, %r{does not match}) }
  32. it { is_expected.to run.with_params('notone', ['^one', '^two']).and_raise_error(Puppet::ParseError, %r{does not match}) }
  33. it { is_expected.to run.with_params('notone', ['^one', '^two'], 'custom error').and_raise_error(Puppet::ParseError, %r{custom error}) }
  34. end
  35. describe 'non-string inputs' do
  36. [
  37. 1, # Fixnum
  38. 3.14, # Float
  39. nil, # NilClass
  40. true, # TrueClass
  41. false, # FalseClass
  42. ['10'], # Array
  43. :key, # Symbol
  44. { :key => 'val' }, # Hash
  45. ].each do |input|
  46. it { is_expected.to run.with_params(input, '.*').and_raise_error(Puppet::ParseError, %r{needs to be a String}) }
  47. end
  48. end
  49. end
  50. end