is_numeric_spec.rb 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. require 'spec_helper'
  2. describe 'is_numeric' 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 { is_expected.to run.with_params(1, 2).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
  6. it { is_expected.to run.with_params(3).and_return(true) }
  7. it { is_expected.to run.with_params('3').and_return(true) }
  8. it { is_expected.to run.with_params(-3).and_return(true) }
  9. it { is_expected.to run.with_params('-3').and_return(true) }
  10. it { is_expected.to run.with_params(3.7).and_return(true) }
  11. it { is_expected.to run.with_params('3.7').and_return(true) }
  12. it { is_expected.to run.with_params(-3.7).and_return(true) }
  13. it { is_expected.to run.with_params('-3.7').and_return(true) }
  14. it { is_expected.to run.with_params('-342.2315e-12').and_return(true) }
  15. it { is_expected.to run.with_params('one').and_return(false) }
  16. it { is_expected.to run.with_params([]).and_return(false) }
  17. it { is_expected.to run.with_params([1]).and_return(false) }
  18. it { is_expected.to run.with_params({}).and_return(false) }
  19. it { is_expected.to run.with_params(true).and_return(false) }
  20. it { is_expected.to run.with_params(false).and_return(false) }
  21. it { is_expected.to run.with_params('0001234').and_return(false) }
  22. it { is_expected.to run.with_params(' - 1234').and_return(false) }
  23. context 'with deprecation warning' do
  24. after(:each) do
  25. ENV.delete('STDLIB_LOG_DEPRECATIONS')
  26. end
  27. # Checking for deprecation warning, which should only be provoked when the env variable for it is set.
  28. it 'displays a single deprecation' do
  29. ENV['STDLIB_LOG_DEPRECATIONS'] = 'true'
  30. scope.expects(:warning).with(includes('This method is deprecated'))
  31. is_expected.to run.with_params(7).and_return(true)
  32. end
  33. it 'displays no warning for deprecation' do
  34. ENV['STDLIB_LOG_DEPRECATIONS'] = 'false'
  35. scope.expects(:warning).with(includes('This method is deprecated')).never
  36. is_expected.to run.with_params(7).and_return(true)
  37. end
  38. end
  39. end