validate_bool_spec.rb 1.7 KB

123456789101112131415161718192021222324252627282930313233343536
  1. require 'spec_helper'
  2. describe 'validate_bool' 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(true)
  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. end
  16. describe 'acceptable values' do
  17. it { is_expected.to run.with_params(true) }
  18. it { is_expected.to run.with_params(false) }
  19. it { is_expected.to run.with_params(true, false, false, true) }
  20. end
  21. describe 'validation failures' do
  22. it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, %r{is not a boolean}) }
  23. it { is_expected.to run.with_params(true, 'one').and_raise_error(Puppet::ParseError, %r{is not a boolean}) }
  24. it { is_expected.to run.with_params('one', false).and_raise_error(Puppet::ParseError, %r{is not a boolean}) }
  25. it { is_expected.to run.with_params('true').and_raise_error(Puppet::ParseError, %r{is not a boolean}) }
  26. it { is_expected.to run.with_params('false').and_raise_error(Puppet::ParseError, %r{is not a boolean}) }
  27. it { is_expected.to run.with_params(true, 'false').and_raise_error(Puppet::ParseError, %r{is not a boolean}) }
  28. it { is_expected.to run.with_params('true', false).and_raise_error(Puppet::ParseError, %r{is not a boolean}) }
  29. it { is_expected.to run.with_params('true', false, false, false, false, false).and_raise_error(Puppet::ParseError, %r{is not a boolean}) }
  30. end
  31. end