deprecation_spec.rb 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. require 'spec_helper'
  2. if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0
  3. describe 'deprecation' do
  4. before(:each) do
  5. # this is to reset the strict variable to default
  6. Puppet.settings[:strict] = :warning
  7. end
  8. it { is_expected.not_to eq(nil) }
  9. it { is_expected.to run.with_params.and_raise_error(ArgumentError) }
  10. it 'displays a single warning' do
  11. Puppet.expects(:warning).with(includes('heelo'))
  12. is_expected.to run.with_params('key', 'heelo')
  13. end
  14. it 'displays a single warning, despite multiple calls' do
  15. Puppet.expects(:warning).with(includes('heelo')).once
  16. (0..1).each do |_i|
  17. is_expected.to run.with_params('key', 'heelo')
  18. end
  19. end
  20. it 'fails twice with message, with multiple calls. when strict= :error' do
  21. Puppet.settings[:strict] = :error
  22. Puppet.expects(:warning).with(includes('heelo')).never
  23. (0..1).each do |_i|
  24. is_expected.to run.with_params('key', 'heelo').and_raise_error(RuntimeError, %r{deprecation. key. heelo})
  25. end
  26. end
  27. it 'displays nothing, despite multiple calls. strict= :off' do
  28. Puppet.settings[:strict] = :off
  29. Puppet.expects(:warning).with(includes('heelo')).never
  30. (0..1).each do |_i|
  31. is_expected.to run.with_params('key', 'heelo')
  32. end
  33. end
  34. after(:each) do
  35. # this is to reset the strict variable to default
  36. Puppet.settings[:strict] = :warning
  37. end
  38. end
  39. elsif Puppet.version.to_f < 4.0
  40. # Puppet version < 4 will use these tests.
  41. describe 'deprecation' do
  42. after(:each) do
  43. ENV.delete('STDLIB_LOG_DEPRECATIONS')
  44. end
  45. before(:each) do
  46. ENV['STDLIB_LOG_DEPRECATIONS'] = 'true'
  47. end
  48. it { is_expected.not_to eq(nil) }
  49. it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
  50. it 'displays a single warning' do
  51. scope.expects(:warning).with(includes('heelo'))
  52. is_expected.to run.with_params('key', 'heelo')
  53. end
  54. end
  55. end