apt_has_updates_spec.rb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. require 'spec_helper'
  2. describe 'apt_has_updates fact' do
  3. subject { Facter.fact(:apt_has_updates).value }
  4. after(:each) { Facter.clear }
  5. describe 'on non-Debian distro' do
  6. before {
  7. Facter.fact(:osfamily).expects(:value).at_least(1).returns 'RedHat'
  8. }
  9. it { is_expected.to be_nil }
  10. end
  11. describe 'on Debian based distro missing apt-get' do
  12. before {
  13. Facter.fact(:osfamily).expects(:value).at_least(1).returns 'Debian'
  14. File.stubs(:executable?) # Stub all other calls
  15. File.expects(:executable?).with('/usr/bin/apt-get').returns false
  16. }
  17. it { is_expected.to be_nil }
  18. end
  19. describe 'on Debian based distro' do
  20. before {
  21. Facter.fact(:osfamily).expects(:value).at_least(1).returns 'Debian'
  22. File.stubs(:executable?) # Stub all other calls
  23. Facter::Util::Resolution.stubs(:exec) # Catch all other calls
  24. File.expects(:executable?).with('/usr/bin/apt-get').returns true
  25. Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s upgrade 2>&1').returns ""+
  26. "Inst tzdata [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n"+
  27. "Conf tzdata (2015g-0+deb8u1 Debian:stable-updates [all])\n"+
  28. "Inst unhide.rb [13-1.1] (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n"+
  29. "Conf unhide.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n"
  30. }
  31. it { is_expected.to be true }
  32. end
  33. end