(CONT-773) Rubocop Auto Fixes 6-10
[puppet-modules/puppetlabs-apt.git] / spec / unit / facter / apt_dist_has_updates_spec.rb
1 # frozen_string_literal: true
2
3 require 'spec_helper'
4
5 describe 'apt_has_dist_updates fact' do
6   subject { Facter.fact(:apt_has_dist_updates).value }
7
8   before(:each) { Facter.clear }
9
10   describe 'on non-Debian distro' do
11     before(:each) do
12       allow(Facter.fact(:osfamily)).to receive(:value).once.and_return('Redhat')
13     end
14
15     it { is_expected.to be_nil }
16   end
17
18   describe 'on Debian based distro missing apt-get' do
19     before(:each) do
20       allow(Facter.fact(:osfamily)).to receive(:value).once.and_return('Debian')
21       allow(File).to receive(:executable?) # Stub all other calls
22       allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(false)
23     end
24
25     it { is_expected.to be_nil }
26   end
27
28   describe 'on Debian based distro' do
29     before(:each) do
30       allow(Facter.fact(:osfamily)).to receive(:value).once.and_return('Debian')
31       allow(File).to receive(:executable?) # Stub all other calls
32       allow(Facter::Core::Execution).to receive(:execute) # Catch all other calls
33       allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true)
34       allow(Facter::Core::Execution).to receive(:execute).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return('test')
35       apt_output = "Inst extremetuxracer [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n" \
36                    "Conf extremetuxracer (2015g-0+deb8u1 Debian:stable-updates [all])\n" \
37                    "Inst planet.rb [13-1.1] (22-2~bpo8+1 Debian Backports:stretch-backports [all])\n" \
38                    "Conf planet.rb (22-2~bpo8+1 Debian Backports:stretch-backports [all])\n"
39       allow(Facter::Core::Execution).to receive(:execute).with('/usr/bin/apt-get -s -o Debug::NoLocking=true dist-upgrade 2>&1').and_return(apt_output)
40     end
41
42     it { is_expected.to be true }
43   end
44 end