ensure_packages_spec.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #! /usr/bin/env ruby
  2. require 'spec_helper'
  3. require 'rspec-puppet'
  4. describe 'ensure_packages' do
  5. let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
  6. describe 'argument handling' do
  7. it 'fails with no arguments' do
  8. should run.with_params().and_raise_error(Puppet::ParseError)
  9. end
  10. it 'requires an array' do
  11. lambda { scope.function_ensure_packages([['foo']]) }.should_not raise_error
  12. end
  13. it 'fails when given a string' do
  14. should run.with_params('foo').and_raise_error(Puppet::ParseError)
  15. end
  16. end
  17. context 'given a catalog containing Package[puppet]{ensure => absent}' do
  18. let :pre_condition do
  19. 'package { puppet: ensure => absent }'
  20. end
  21. # NOTE: should run.with_params has the side effect of making the compiler
  22. # available to the test harness.
  23. it 'has no effect on Package[puppet]' do
  24. should run.with_params(['puppet'])
  25. rsrc = compiler.catalog.resource('Package[puppet]')
  26. rsrc.to_hash.should == {:ensure => "absent"}
  27. end
  28. end
  29. context 'given a clean catalog' do
  30. it 'declares package resources with ensure => present' do
  31. should run.with_params(['facter'])
  32. rsrc = compiler.catalog.resource('Package[facter]')
  33. rsrc.to_hash.should == {:name => "facter", :ensure => "present"}
  34. end
  35. end
  36. end