any2bool_spec.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. require 'spec_helper'
  2. describe 'any2bool' 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(true).and_return(true) }
  6. it { is_expected.to run.with_params(false).and_return(false) }
  7. it { is_expected.to run.with_params('1.5').and_return(true) }
  8. describe 'when testing stringy values that mean "true"' do
  9. %w[TRUE 1 t y true yes].each do |value|
  10. it { is_expected.to run.with_params(value).and_return(true) }
  11. end
  12. end
  13. describe 'when testing stringy values that mean "false"' do
  14. ['FALSE', '', '0', 'f', 'n', 'false', 'no', 'undef', 'undefined', nil, :undef].each do |value|
  15. it { is_expected.to run.with_params(value).and_return(false) }
  16. end
  17. end
  18. describe 'when testing numeric values that mean "true"' do
  19. [1, '1', 1.5, '1.5'].each do |value|
  20. it { is_expected.to run.with_params(value).and_return(true) }
  21. end
  22. end
  23. describe 'when testing numeric that mean "false"' do
  24. [-1, '-1', -1.5, '-1.5', '0', 0].each do |value|
  25. it { is_expected.to run.with_params(value).and_return(false) }
  26. end
  27. end
  28. describe 'everything else returns true' do
  29. [[], {}, ['1'], [1], { :one => 1 }].each do |value|
  30. it { is_expected.to run.with_params(value).and_return(true) }
  31. end
  32. end
  33. end