diff --git a/spec/unit/facter/apt_dist_has_updates_spec.rb b/spec/unit/facter/apt_dist_has_updates_spec.rb index 7846632..6130f27 100644 --- a/spec/unit/facter/apt_dist_has_updates_spec.rb +++ b/spec/unit/facter/apt_dist_has_updates_spec.rb @@ -1,41 +1,39 @@ require 'spec_helper' describe 'apt_has_dist_updates fact' do subject { Facter.fact(:apt_has_dist_updates).value } - after(:each) { Facter.clear } + before(:each) { Facter.clear } describe 'on non-Debian distro' do before(:each) do - # Adding temporary workaround for this ticket https://tickets.puppetlabs.com/browse/IAC-1143 - Facter.clear allow(Facter.fact(:osfamily)).to receive(:value).once.and_return('Redhat') end it { is_expected.to be_nil } end describe 'on Debian based distro missing apt-get' do before(:each) do allow(Facter.fact(:osfamily)).to receive(:value).once.and_return('Debian') allow(File).to receive(:executable?) # Stub all other calls allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(false) end it { is_expected.to be_nil } end describe 'on Debian based distro' do before(:each) do allow(Facter.fact(:osfamily)).to receive(:value).once.and_return('Debian') allow(File).to receive(:executable?) # Stub all other calls allow(Facter::Util::Resolution).to receive(:exec) # Catch all other calls allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true) allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return('test') apt_output = "Inst extremetuxracer [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ "Conf extremetuxracer (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ "Inst planet.rb [13-1.1] (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" \ "Conf planet.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true dist-upgrade 2>&1').and_return(apt_output) end it { is_expected.to be true } end end diff --git a/spec/unit/facter/apt_dist_package_security_updates_spec.rb b/spec/unit/facter/apt_dist_package_security_updates_spec.rb index 6355b79..4033a28 100644 --- a/spec/unit/facter/apt_dist_package_security_updates_spec.rb +++ b/spec/unit/facter/apt_dist_package_security_updates_spec.rb @@ -1,52 +1,52 @@ require 'spec_helper' describe 'apt_package_security_dist_updates fact' do subject { Facter.fact(:apt_package_security_dist_updates).value } - after(:each) { Facter.clear } + before(:each) { Facter.clear } describe 'when apt has no updates' do before(:each) do allow(Facter.fact(:apt_has_dist_updates)).to receive(:value).and_return(false) end it { is_expected.to be nil } end describe 'when apt has updates' do before(:each) do allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian') allow(File).to receive(:executable?) # Stub all other calls allow(Facter::Util::Resolution).to receive(:exec) # Catch all other calls allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true) allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return('test') allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true) allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true dist-upgrade 2>&1').and_return(apt_get_upgrade_output) end describe 'on Debian' do let(:apt_get_upgrade_output) do "Inst extremetuxracer [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ "Conf extremetuxracer (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ "Inst planet.rb [13-1.1] (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" \ "Conf planet.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" \ "Inst vim [7.52.1-5] (7.52.1-5+deb9u2 Debian-Security:9/stable [amd64]) []\n" \ "Conf vim (7.52.1-5+deb9u2 Debian-Security:9/stable [amd64])\n" \ end it { is_expected.to eq(['vim']) } end describe 'on Ubuntu' do let(:apt_get_upgrade_output) do "Inst extremetuxracer [2016f-0ubuntu0.16.04] (2016j-0ubuntu0.16.04 Ubuntu:16.04/xenial-security, Ubuntu:16.04/xenial-updates [all])\n" \ "Conf extremetuxracer (2016j-0ubuntu0.16.04 Ubuntu:16.04/xenial-security, Ubuntu:16.04/xenial-updates [all])\n" \ "Inst vim [7.47.0-1ubuntu2] (7.47.0-1ubuntu2.2 Ubuntu:16.04/xenial-security [amd64]) []\n" \ "Conf vim (7.47.0-1ubuntu2.2 Ubuntu:16.04/xenial-security [amd64])\n" \ "Inst onioncircuits [2:3.3.10-4ubuntu2] (2:3.3.10-4ubuntu2.3 Ubuntu:16.04/xenial-updates [amd64])\n" \ "Conf onioncircuits (2:3.3.10-4ubuntu2.3 Ubuntu:16.04/xenial-updates [amd64])\n" end it { is_expected.to eq(['extremetuxracer', 'vim']) } end end end diff --git a/spec/unit/facter/apt_dist_package_updates_spec.rb b/spec/unit/facter/apt_dist_package_updates_spec.rb index bbe212e..59e02b8 100644 --- a/spec/unit/facter/apt_dist_package_updates_spec.rb +++ b/spec/unit/facter/apt_dist_package_updates_spec.rb @@ -1,31 +1,31 @@ require 'spec_helper' describe 'apt_package_dist_updates fact' do subject { Facter.fact(:apt_package_dist_updates).value } - after(:each) { Facter.clear } + before(:each) { Facter.clear } describe 'when apt has no updates' do before(:each) do allow(Facter.fact(:apt_has_dist_updates)).to receive(:value).and_return(false) end it { is_expected.to be nil } end describe 'when apt has updates' do before(:each) do allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian') allow(File).to receive(:executable?) # Stub all other calls allow(Facter::Util::Resolution).to receive(:exec) # Catch all other calls allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true) allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return('test') allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true) apt_output = "Inst extremetuxracer [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ "Conf extremetuxracer (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ "Inst planet.rb [13-1.1] (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" \ "Conf planet.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true dist-upgrade 2>&1').and_return(apt_output) end it { is_expected.to eq(['extremetuxracer', 'planet.rb']) } end end diff --git a/spec/unit/facter/apt_dist_security_updates_spec.rb b/spec/unit/facter/apt_dist_security_updates_spec.rb index 8035f16..895a36c 100644 --- a/spec/unit/facter/apt_dist_security_updates_spec.rb +++ b/spec/unit/facter/apt_dist_security_updates_spec.rb @@ -1,52 +1,52 @@ require 'spec_helper' describe 'apt_security_updates fact' do subject { Facter.fact(:apt_security_dist_updates).value } - after(:each) { Facter.clear } + before(:each) { Facter.clear } describe 'when apt has no updates' do before(:each) do allow(Facter.fact(:apt_has_dist_updates)).to receive(:value).and_return(false) end it { is_expected.to be nil } end describe 'when apt has security updates' do before(:each) do allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian') allow(File).to receive(:executable?) # Stub all other calls allow(Facter::Util::Resolution).to receive(:exec) # Catch all other calls allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true) allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return('test') allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true) allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true dist-upgrade 2>&1').and_return(apt_get_upgrade_output) end describe 'on Debian' do let(:apt_get_upgrade_output) do "Inst extremetuxracer [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ "Conf extremetuxracer (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ "Inst planet.rb [13-1.1] (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" \ "Conf planet.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" \ "Inst vim [7.52.1-5] (7.52.1-5+deb9u2 Debian-Security:9/stable [amd64]) []\n" \ "Conf vim (7.52.1-5+deb9u2 Debian-Security:9/stable [amd64])\n" \ end it { is_expected.to eq(1) } end describe 'on Ubuntu' do let(:apt_get_upgrade_output) do "Inst extremetuxracer [2016f-0ubuntu0.16.04] (2016j-0ubuntu0.16.04 Ubuntu:16.04/xenial-security, Ubuntu:16.04/xenial-updates [all])\n" \ "Conf extremetuxracer (2016j-0ubuntu0.16.04 Ubuntu:16.04/xenial-security, Ubuntu:16.04/xenial-updates [all])\n" \ "Inst vim [7.47.0-1ubuntu2] (7.47.0-1ubuntu2.2 Ubuntu:16.04/xenial-security [amd64]) []\n" \ "Conf vim (7.47.0-1ubuntu2.2 Ubuntu:16.04/xenial-security [amd64])\n" \ "Inst onioncircuits [2:3.3.10-4ubuntu2] (2:3.3.10-4ubuntu2.3 Ubuntu:16.04/xenial-updates [amd64])\n" \ "Conf onioncircuits (2:3.3.10-4ubuntu2.3 Ubuntu:16.04/xenial-updates [amd64])\n" end it { is_expected.to eq(2) } end end end diff --git a/spec/unit/facter/apt_dist_updates_spec.rb b/spec/unit/facter/apt_dist_updates_spec.rb index f9942af..112dca8 100644 --- a/spec/unit/facter/apt_dist_updates_spec.rb +++ b/spec/unit/facter/apt_dist_updates_spec.rb @@ -1,31 +1,31 @@ require 'spec_helper' describe 'apt_updates fact' do subject { Facter.fact(:apt_dist_updates).value } - after(:each) { Facter.clear } + before(:each) { Facter.clear } describe 'when apt has no updates' do before(:each) do allow(Facter.fact(:apt_has_dist_updates)).to receive(:value).and_return(false) end it { is_expected.to be nil } end describe 'when apt has updates' do before(:each) do allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian') allow(File).to receive(:executable?) # Stub all other calls allow(Facter::Util::Resolution).to receive(:exec) # Catch all other calls allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true) allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return('test') allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true) apt_output = "Inst extremetuxracer [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ "Conf extremetuxracer (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ "Inst planet.rb [13-1.1] (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" \ "Conf planet.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true dist-upgrade 2>&1').and_return(apt_output) end it { is_expected.to eq(2) } end end diff --git a/spec/unit/facter/apt_has_updates_spec.rb b/spec/unit/facter/apt_has_updates_spec.rb index f7a1ca9..ea3e085 100644 --- a/spec/unit/facter/apt_has_updates_spec.rb +++ b/spec/unit/facter/apt_has_updates_spec.rb @@ -1,38 +1,38 @@ require 'spec_helper' describe 'apt_has_updates fact' do subject { Facter.fact(:apt_has_updates).value } - after(:each) { Facter.clear } + before(:each) { Facter.clear } describe 'on non-Debian distro' do before(:each) do allow(Facter.fact(:osfamily)).to receive(:value).once.and_return('Redhat') end it { is_expected.to be_nil } end describe 'on Debian based distro missing apt-get' do before(:each) do allow(Facter.fact(:osfamily)).to receive(:value).once.and_return('Debian') allow(File).to receive(:executable?) # Stub all other calls allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(false) end it { is_expected.to be_nil } end describe 'on Debian based distro' do before(:each) do allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian') allow(File).to receive(:executable?) # Stub all other calls allow(Facter::Util::Resolution).to receive(:exec) # Catch all other calls allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true) apt_output = "Inst tzdata [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ "Conf tzdata (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ "Inst unhide.rb [13-1.1] (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" \ "Conf unhide.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return(apt_output) end it { is_expected.to be true } end end diff --git a/spec/unit/facter/apt_package_security_updates_spec.rb b/spec/unit/facter/apt_package_security_updates_spec.rb index 53b91bc..958fd00 100644 --- a/spec/unit/facter/apt_package_security_updates_spec.rb +++ b/spec/unit/facter/apt_package_security_updates_spec.rb @@ -1,50 +1,50 @@ require 'spec_helper' describe 'apt_package_security_updates fact' do subject { Facter.fact(:apt_package_security_updates).value } - after(:each) { Facter.clear } + before(:each) { Facter.clear } describe 'when apt has no updates' do before(:each) do allow(Facter.fact(:apt_has_updates)).to receive(:value).and_return(false) end it { is_expected.to be nil } end describe 'when apt has updates' do before(:each) do allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian') allow(File).to receive(:executable?) # Stub all other calls allow(Facter::Util::Resolution).to receive(:exec) # Catch all other calls allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true) allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return(apt_get_upgrade_output) end describe 'on Debian' do let(:apt_get_upgrade_output) do "Inst tzdata [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ "Conf tzdata (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ "Inst unhide.rb [13-1.1] (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" \ "Conf unhide.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" \ "Inst curl [7.52.1-5] (7.52.1-5+deb9u2 Debian-Security:9/stable [amd64]) []\n" \ "Conf curl (7.52.1-5+deb9u2 Debian-Security:9/stable [amd64])\n" \ end it { is_expected.to eq(['curl']) } end describe 'on Ubuntu' do let(:apt_get_upgrade_output) do "Inst tzdata [2016f-0ubuntu0.16.04] (2016j-0ubuntu0.16.04 Ubuntu:16.04/xenial-security, Ubuntu:16.04/xenial-updates [all])\n" \ "Conf tzdata (2016j-0ubuntu0.16.04 Ubuntu:16.04/xenial-security, Ubuntu:16.04/xenial-updates [all])\n" \ "Inst curl [7.47.0-1ubuntu2] (7.47.0-1ubuntu2.2 Ubuntu:16.04/xenial-security [amd64]) []\n" \ "Conf curl (7.47.0-1ubuntu2.2 Ubuntu:16.04/xenial-security [amd64])\n" \ "Inst procps [2:3.3.10-4ubuntu2] (2:3.3.10-4ubuntu2.3 Ubuntu:16.04/xenial-updates [amd64])\n" \ "Conf procps (2:3.3.10-4ubuntu2.3 Ubuntu:16.04/xenial-updates [amd64])\n" end it { is_expected.to eq(['tzdata', 'curl']) } end end end diff --git a/spec/unit/facter/apt_package_updates_spec.rb b/spec/unit/facter/apt_package_updates_spec.rb index 4b3e749..4c81d0c 100644 --- a/spec/unit/facter/apt_package_updates_spec.rb +++ b/spec/unit/facter/apt_package_updates_spec.rb @@ -1,29 +1,29 @@ require 'spec_helper' describe 'apt_package_updates fact' do subject { Facter.fact(:apt_package_updates).value } - after(:each) { Facter.clear } + before(:each) { Facter.clear } describe 'when apt has no updates' do before(:each) do allow(Facter.fact(:apt_has_updates)).to receive(:value).and_return(false) end it { is_expected.to be nil } end describe 'when apt has updates' do before(:each) do allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian') allow(File).to receive(:executable?) # Stub all other calls allow(Facter::Util::Resolution).to receive(:exec) # Catch all other calls allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true) apt_output = "Inst tzdata [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ "Conf tzdata (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ "Inst unhide.rb [13-1.1] (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" \ "Conf unhide.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return(apt_output) end it { is_expected.to eq(['tzdata', 'unhide.rb']) } end end diff --git a/spec/unit/facter/apt_reboot_required_spec.rb b/spec/unit/facter/apt_reboot_required_spec.rb index b15cb4c..22f5617 100644 --- a/spec/unit/facter/apt_reboot_required_spec.rb +++ b/spec/unit/facter/apt_reboot_required_spec.rb @@ -1,25 +1,25 @@ require 'spec_helper' describe 'apt_reboot_required fact' do subject { Facter.fact(:apt_reboot_required).value } - after(:each) { Facter.clear } + before(:each) { Facter.clear } describe 'if a reboot is required' do before(:each) do allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian') allow(File).to receive(:file?).and_return(true) allow(File).to receive(:file?).once.with('/var/run/reboot-required').and_return(true) end it { is_expected.to eq true } end describe 'if a reboot is not required' do before(:each) do allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian') allow(File).to receive(:file?).and_return(true) allow(File).to receive(:file?).once.with('/var/run/reboot-required').and_return(false) end it { is_expected.to eq false } end end diff --git a/spec/unit/facter/apt_security_updates_spec.rb b/spec/unit/facter/apt_security_updates_spec.rb index cde0158..4e4b54d 100644 --- a/spec/unit/facter/apt_security_updates_spec.rb +++ b/spec/unit/facter/apt_security_updates_spec.rb @@ -1,50 +1,50 @@ require 'spec_helper' describe 'apt_security_updates fact' do subject { Facter.fact(:apt_security_updates).value } - after(:each) { Facter.clear } + before(:each) { Facter.clear } describe 'when apt has no updates' do before(:each) do allow(Facter.fact(:apt_has_updates)).to receive(:value).and_return(false) end it { is_expected.to be nil } end describe 'when apt has security updates' do before(:each) do allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian') allow(File).to receive(:executable?) # Stub all other calls allow(Facter::Util::Resolution).to receive(:exec) # Catch all other calls allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true) allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return(apt_get_upgrade_output) end describe 'on Debian' do let(:apt_get_upgrade_output) do "Inst tzdata [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ "Conf tzdata (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ "Inst unhide.rb [13-1.1] (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" \ "Conf unhide.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" \ "Inst curl [7.52.1-5] (7.52.1-5+deb9u2 Debian-Security:9/stable [amd64]) []\n" \ "Conf curl (7.52.1-5+deb9u2 Debian-Security:9/stable [amd64])\n" \ end it { is_expected.to eq(1) } end describe 'on Ubuntu' do let(:apt_get_upgrade_output) do "Inst tzdata [2016f-0ubuntu0.16.04] (2016j-0ubuntu0.16.04 Ubuntu:16.04/xenial-security, Ubuntu:16.04/xenial-updates [all])\n" \ "Conf tzdata (2016j-0ubuntu0.16.04 Ubuntu:16.04/xenial-security, Ubuntu:16.04/xenial-updates [all])\n" \ "Inst curl [7.47.0-1ubuntu2] (7.47.0-1ubuntu2.2 Ubuntu:16.04/xenial-security [amd64]) []\n" \ "Conf curl (7.47.0-1ubuntu2.2 Ubuntu:16.04/xenial-security [amd64])\n" \ "Inst procps [2:3.3.10-4ubuntu2] (2:3.3.10-4ubuntu2.3 Ubuntu:16.04/xenial-updates [amd64])\n" \ "Conf procps (2:3.3.10-4ubuntu2.3 Ubuntu:16.04/xenial-updates [amd64])\n" end it { is_expected.to eq(2) } end end end diff --git a/spec/unit/facter/apt_update_last_success_spec.rb b/spec/unit/facter/apt_update_last_success_spec.rb index dc0fc54..f4858dd 100644 --- a/spec/unit/facter/apt_update_last_success_spec.rb +++ b/spec/unit/facter/apt_update_last_success_spec.rb @@ -1,25 +1,24 @@ require 'spec_helper' describe 'apt_update_last_success fact' do subject { Facter.fact(:apt_update_last_success).value } before(:each) { Facter.clear } - after(:each) { Facter.clear } describe 'on Debian based distro which has not yet created the update-success-stamp file' do it 'has a value of -1' do allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian') allow(File).to receive(:exist?).with('/var/lib/apt/periodic/update-success-stamp').and_return(false) is_expected.to eq(-1) end end describe 'on Debian based distro which has created the update-success-stamp' do it 'has the value of the mtime of the file' do allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian') allow(File).to receive(:exist?).and_return(true) allow(File).to receive(:mtime).and_return(1_407_660_561) is_expected.to eq(1_407_660_561) end end end diff --git a/spec/unit/facter/apt_updates_spec.rb b/spec/unit/facter/apt_updates_spec.rb index e9d4c0d..1f1c15b 100644 --- a/spec/unit/facter/apt_updates_spec.rb +++ b/spec/unit/facter/apt_updates_spec.rb @@ -1,29 +1,29 @@ require 'spec_helper' describe 'apt_updates fact' do subject { Facter.fact(:apt_updates).value } - after(:each) { Facter.clear } + before(:each) { Facter.clear } describe 'when apt has no updates' do before(:each) do allow(Facter.fact(:apt_has_updates)).to receive(:value).and_return(false) end it { is_expected.to be nil } end describe 'when apt has updates' do before(:each) do allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian') allow(File).to receive(:executable?) # Stub all other calls allow(Facter::Util::Resolution).to receive(:exec) # Catch all other calls allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true) apt_output = "Inst tzdata [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ "Conf tzdata (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ "Inst unhide.rb [13-1.1] (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" \ "Conf unhide.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return(apt_output) end it { is_expected.to eq(2) } end end