is_integer_spec.rb 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. require 'spec_helper'
  2. describe 'is_integer' 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("123\nfoo").and_return(true) }
  11. it { is_expected.to run.with_params("foo\n123").and_return(true) }
  12. it { is_expected.to run.with_params(3.7).and_return(false) }
  13. it { is_expected.to run.with_params('3.7').and_return(false) }
  14. it { is_expected.to run.with_params(-3.7).and_return(false) }
  15. it { is_expected.to run.with_params('-3.7').and_return(false) }
  16. it { is_expected.to run.with_params('one').and_return(false) }
  17. it { is_expected.to run.with_params([]).and_return(false) }
  18. it { is_expected.to run.with_params([1]).and_return(false) }
  19. it { is_expected.to run.with_params({}).and_return(false) }
  20. it { is_expected.to run.with_params(true).and_return(false) }
  21. it { is_expected.to run.with_params(false).and_return(false) }
  22. it { is_expected.to run.with_params('0001234').and_return(false) }
  23. it { is_expected.to run.with_params("foo\nbar").and_return(false) }
  24. context 'with deprecation warning' do
  25. after(:each) do
  26. ENV.delete('STDLIB_LOG_DEPRECATIONS')
  27. end
  28. # Checking for deprecation warning, which should only be provoked when the env variable for it is set.
  29. it 'displays a single deprecation' do
  30. ENV['STDLIB_LOG_DEPRECATIONS'] = 'true'
  31. scope.expects(:warning).with(includes('This method is deprecated'))
  32. is_expected.to run.with_params(50).and_return(true)
  33. end
  34. it 'displays no warning for deprecation' do
  35. ENV['STDLIB_LOG_DEPRECATIONS'] = 'false'
  36. scope.expects(:warning).with(includes('This method is deprecated')).never
  37. is_expected.to run.with_params(50).and_return(true)
  38. end
  39. end
  40. end