From ae739e9baf18de742453702ee5fc420b1211ce44 Mon Sep 17 00:00:00 2001 From: tphoney Date: Tue, 12 Feb 2019 16:22:24 +0000 Subject: [PATCH] (maint) use rspec-mock for unit tests --- .puppet-lint.rc | 2 +- .sync.yml | 28 +++++++++++-------- metadata.json | 2 +- spec/spec_helper.rb | 5 ++++ spec/unit/facter/apt_dist_has_updates_spec.rb | 21 +++++++------- .../apt_dist_package_security_updates_spec.rb | 28 +++++++------------ .../facter/apt_dist_package_updates_spec.rb | 16 +++++------ .../facter/apt_dist_security_updates_spec.rb | 16 +++++------ spec/unit/facter/apt_dist_updates_spec.rb | 16 +++++------ spec/unit/facter/apt_has_updates_spec.rb | 18 ++++++------ .../apt_package_security_updates_spec.rb | 12 ++++---- spec/unit/facter/apt_package_updates_spec.rb | 12 ++++---- spec/unit/facter/apt_reboot_required_spec.rb | 12 ++++---- spec/unit/facter/apt_security_updates_spec.rb | 12 ++++---- .../facter/apt_update_last_success_spec.rb | 10 +++---- spec/unit/facter/apt_updates_spec.rb | 13 ++++----- 16 files changed, 111 insertions(+), 112 deletions(-) diff --git a/.puppet-lint.rc b/.puppet-lint.rc index cc96ece..8b13789 100644 --- a/.puppet-lint.rc +++ b/.puppet-lint.rc @@ -1 +1 @@ ---relative + diff --git a/.sync.yml b/.sync.yml index ad63bcd..efaa467 100644 --- a/.sync.yml +++ b/.sync.yml @@ -1,4 +1,14 @@ --- +.gitlab-ci.yml: + unmanaged: true + +.rubocop.yml: + default_configs: + inherit_from: .rubocop_todo.yml + require: + - rubocop-i18n + - rubocop-rspec + .travis.yml: docker_sets: - set: docker/debian-8 @@ -9,6 +19,9 @@ branches: - release +appveyor.yml: + delete: true + Gemfile: required: ':system_tests': @@ -27,19 +40,10 @@ Gemfile: condition: "Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2')" - gem: puppet-lint-i18n -.rubocop.yml: - default_configs: - inherit_from: .rubocop_todo.yml - require: - - rubocop-i18n - - rubocop-rspec - Rakefile: requires: - puppet_pot_generator/rake_tasks -appveyor.yml: - delete: true - -.gitlab-ci.yml: - unmanaged: true +spec/spec_helper.rb: + mock_with: ':rspec' + coverage_report: true diff --git a/metadata.json b/metadata.json index a32d7d6..d529a87 100644 --- a/metadata.json +++ b/metadata.json @@ -43,4 +43,4 @@ "template-url": "https://github.com/puppetlabs/pdk-templates/", "template-ref": "1.9.0-0-g7281db5", "pdk-version": "1.9.0" -} \ No newline at end of file +} diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0d5efc0..149ff03 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,7 @@ +RSpec.configure do |c| + c.mock_with :rspec +end + require 'puppetlabs_spec_helper/module_spec_helper' require 'rspec-puppet-facts' @@ -34,6 +38,7 @@ RSpec.configure do |c| end c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT'] c.after(:suite) do + RSpec::Puppet::Coverage.report!(0) end end diff --git a/spec/unit/facter/apt_dist_has_updates_spec.rb b/spec/unit/facter/apt_dist_has_updates_spec.rb index ae67bcf..216050d 100644 --- a/spec/unit/facter/apt_dist_has_updates_spec.rb +++ b/spec/unit/facter/apt_dist_has_updates_spec.rb @@ -7,33 +7,32 @@ describe 'apt_has_dist_updates fact' do describe 'on non-Debian distro' do before(:each) do - Facter.fact(:osfamily).expects(:value).at_least(1).returns 'RedHat' + 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 - Facter.fact(:osfamily).expects(:value).at_least(1).returns 'Debian' - File.stubs(:executable?) # Stub all other calls - File.expects(:executable?).with('/usr/bin/apt-get').returns false + 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 - Facter.fact(:osfamily).expects(:value).at_least(1).returns 'Debian' - File.stubs(:executable?) # Stub all other calls - Facter::Util::Resolution.stubs(:exec) # Catch all other calls - File.expects(:executable?).with('/usr/bin/apt-get').returns true - Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns 'test' - File.expects(:executable?).with('/usr/bin/apt-get').returns true + 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" - Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true dist-upgrade 2>&1').returns apt_output + 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 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 d6f0a9f..6355b79 100644 --- a/spec/unit/facter/apt_dist_package_security_updates_spec.rb +++ b/spec/unit/facter/apt_dist_package_security_updates_spec.rb @@ -7,20 +7,20 @@ describe 'apt_package_security_dist_updates fact' do describe 'when apt has no updates' do before(:each) do - Facter.fact(:apt_has_dist_updates).stubs(:value).returns false + 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 - Facter.fact(:osfamily).stubs(:value).returns 'Debian' - File.stubs(:executable?) # Stub all other calls - Facter::Util::Resolution.stubs(:exec) # Catch all other calls - File.expects(:executable?).with('/usr/bin/apt-get').returns true - Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns 'test' - File.expects(:executable?).with('/usr/bin/apt-get').returns true - Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true dist-upgrade 2>&1').returns apt_get_upgrade_output + 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 @@ -33,11 +33,7 @@ describe 'apt_package_security_dist_updates fact' do "Conf vim (7.52.1-5+deb9u2 Debian-Security:9/stable [amd64])\n" \ end - if Facter.version < '2.0.0' - it { is_expected.to eq('vim') } - else - it { is_expected.to eq(['vim']) } - end + it { is_expected.to eq(['vim']) } end describe 'on Ubuntu' do @@ -50,11 +46,7 @@ describe 'apt_package_security_dist_updates fact' do "Conf onioncircuits (2:3.3.10-4ubuntu2.3 Ubuntu:16.04/xenial-updates [amd64])\n" end - if Facter.version < '2.0.0' - it { is_expected.to eq('extremetuxracer,vim') } - else - it { is_expected.to eq(['extremetuxracer', 'vim']) } - 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 1a7d8e9..bbe212e 100644 --- a/spec/unit/facter/apt_dist_package_updates_spec.rb +++ b/spec/unit/facter/apt_dist_package_updates_spec.rb @@ -7,24 +7,24 @@ describe 'apt_package_dist_updates fact' do describe 'when apt has no updates' do before(:each) do - Facter.fact(:apt_has_dist_updates).stubs(:value).returns false + 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 - Facter.fact(:osfamily).stubs(:value).returns 'Debian' - File.stubs(:executable?) # Stub all other calls - Facter::Util::Resolution.stubs(:exec) # Catch all other calls - File.expects(:executable?).with('/usr/bin/apt-get').returns true - Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns 'test' - File.expects(:executable?).with('/usr/bin/apt-get').returns true + 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" - Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true dist-upgrade 2>&1').returns apt_output + 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 diff --git a/spec/unit/facter/apt_dist_security_updates_spec.rb b/spec/unit/facter/apt_dist_security_updates_spec.rb index 9b58b6e..8035f16 100644 --- a/spec/unit/facter/apt_dist_security_updates_spec.rb +++ b/spec/unit/facter/apt_dist_security_updates_spec.rb @@ -7,20 +7,20 @@ describe 'apt_security_updates fact' do describe 'when apt has no updates' do before(:each) do - Facter.fact(:apt_has_dist_updates).stubs(:value).returns false + 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 - Facter.fact(:osfamily).stubs(:value).returns 'Debian' - File.stubs(:executable?) # Stub all other calls - Facter::Util::Resolution.stubs(:exec) # Catch all other calls - File.expects(:executable?).with('/usr/bin/apt-get').returns true - Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns 'test' - File.expects(:executable?).with('/usr/bin/apt-get').returns true - Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true dist-upgrade 2>&1').returns apt_get_upgrade_output + 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 diff --git a/spec/unit/facter/apt_dist_updates_spec.rb b/spec/unit/facter/apt_dist_updates_spec.rb index 737d1b6..f9942af 100644 --- a/spec/unit/facter/apt_dist_updates_spec.rb +++ b/spec/unit/facter/apt_dist_updates_spec.rb @@ -7,24 +7,24 @@ describe 'apt_updates fact' do describe 'when apt has no updates' do before(:each) do - Facter.fact(:apt_has_dist_updates).stubs(:value).returns false + 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 - Facter.fact(:osfamily).stubs(:value).returns 'Debian' - File.stubs(:executable?) # Stub all other calls - Facter::Util::Resolution.stubs(:exec) # Catch all other calls - File.expects(:executable?).with('/usr/bin/apt-get').returns true - Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns 'test' - File.expects(:executable?).with('/usr/bin/apt-get').returns true + 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" - Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true dist-upgrade 2>&1').returns apt_output + 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 diff --git a/spec/unit/facter/apt_has_updates_spec.rb b/spec/unit/facter/apt_has_updates_spec.rb index 5c06c2f..f7a1ca9 100644 --- a/spec/unit/facter/apt_has_updates_spec.rb +++ b/spec/unit/facter/apt_has_updates_spec.rb @@ -7,31 +7,31 @@ describe 'apt_has_updates fact' do describe 'on non-Debian distro' do before(:each) do - Facter.fact(:osfamily).expects(:value).at_least(1).returns 'RedHat' + 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 - Facter.fact(:osfamily).expects(:value).at_least(1).returns 'Debian' - File.stubs(:executable?) # Stub all other calls - File.expects(:executable?).with('/usr/bin/apt-get').returns false + 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 - Facter.fact(:osfamily).expects(:value).at_least(1).returns 'Debian' - File.stubs(:executable?) # Stub all other calls - Facter::Util::Resolution.stubs(:exec) # Catch all other calls - File.expects(:executable?).with('/usr/bin/apt-get').returns true + 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" - Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns apt_output + 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 diff --git a/spec/unit/facter/apt_package_security_updates_spec.rb b/spec/unit/facter/apt_package_security_updates_spec.rb index 913add0..53b91bc 100644 --- a/spec/unit/facter/apt_package_security_updates_spec.rb +++ b/spec/unit/facter/apt_package_security_updates_spec.rb @@ -7,18 +7,18 @@ describe 'apt_package_security_updates fact' do describe 'when apt has no updates' do before(:each) do - Facter.fact(:apt_has_updates).stubs(:value).returns false + 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 - Facter.fact(:osfamily).stubs(:value).returns 'Debian' - File.stubs(:executable?) # Stub all other calls - Facter::Util::Resolution.stubs(:exec) # Catch all other calls - File.expects(:executable?).with('/usr/bin/apt-get').returns true - Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns apt_get_upgrade_output + 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 diff --git a/spec/unit/facter/apt_package_updates_spec.rb b/spec/unit/facter/apt_package_updates_spec.rb index 3468691..4b3e749 100644 --- a/spec/unit/facter/apt_package_updates_spec.rb +++ b/spec/unit/facter/apt_package_updates_spec.rb @@ -7,22 +7,22 @@ describe 'apt_package_updates fact' do describe 'when apt has no updates' do before(:each) do - Facter.fact(:apt_has_updates).stubs(:value).returns false + 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 - Facter.fact(:osfamily).stubs(:value).returns 'Debian' - File.stubs(:executable?) # Stub all other calls - Facter::Util::Resolution.stubs(:exec) # Catch all other calls - File.expects(:executable?).with('/usr/bin/apt-get').returns true + 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" - Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns apt_output + 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 diff --git a/spec/unit/facter/apt_reboot_required_spec.rb b/spec/unit/facter/apt_reboot_required_spec.rb index 356f36b..b15cb4c 100644 --- a/spec/unit/facter/apt_reboot_required_spec.rb +++ b/spec/unit/facter/apt_reboot_required_spec.rb @@ -7,18 +7,18 @@ describe 'apt_reboot_required fact' do describe 'if a reboot is required' do before(:each) do - Facter.fact(:osfamily).expects(:value).at_least(1).returns 'Debian' - File.stubs(:file?).returns true - File.expects(:file?).at_least(1).with('/var/run/reboot-required').returns true + 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 - Facter.fact(:osfamily).expects(:value).at_least(1).returns 'Debian' - File.stubs(:file?).returns true - File.expects(:file?).at_least(1).with('/var/run/reboot-required').returns false + 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 diff --git a/spec/unit/facter/apt_security_updates_spec.rb b/spec/unit/facter/apt_security_updates_spec.rb index fc93552..cde0158 100644 --- a/spec/unit/facter/apt_security_updates_spec.rb +++ b/spec/unit/facter/apt_security_updates_spec.rb @@ -7,18 +7,18 @@ describe 'apt_security_updates fact' do describe 'when apt has no updates' do before(:each) do - Facter.fact(:apt_has_updates).stubs(:value).returns false + 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 - Facter.fact(:osfamily).stubs(:value).returns 'Debian' - File.stubs(:executable?) # Stub all other calls - Facter::Util::Resolution.stubs(:exec) # Catch all other calls - File.expects(:executable?).with('/usr/bin/apt-get').returns true - Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns apt_get_upgrade_output + 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 diff --git a/spec/unit/facter/apt_update_last_success_spec.rb b/spec/unit/facter/apt_update_last_success_spec.rb index 60d7273..dc0fc54 100644 --- a/spec/unit/facter/apt_update_last_success_spec.rb +++ b/spec/unit/facter/apt_update_last_success_spec.rb @@ -8,17 +8,17 @@ describe 'apt_update_last_success fact' do describe 'on Debian based distro which has not yet created the update-success-stamp file' do it 'has a value of -1' do - Facter.fact(:osfamily).stubs(:value).returns 'Debian' - File.expects(:exist?).with('/var/lib/apt/periodic/update-success-stamp').returns false + 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 - Facter.fact(:osfamily).stubs(:value).returns 'Debian' - File.stubs(:exist?).returns true - File.stubs(:mtime).returns 1_407_660_561 + 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 diff --git a/spec/unit/facter/apt_updates_spec.rb b/spec/unit/facter/apt_updates_spec.rb index d0a5dbb..e9d4c0d 100644 --- a/spec/unit/facter/apt_updates_spec.rb +++ b/spec/unit/facter/apt_updates_spec.rb @@ -7,23 +7,22 @@ describe 'apt_updates fact' do describe 'when apt has no updates' do before(:each) do - Facter.fact(:apt_has_updates).stubs(:value).returns false + 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 - Facter.fact(:osfamily).stubs(:value).returns 'Debian' - File.stubs(:executable?) # Stub all other calls - Facter::Util::Resolution.stubs(:exec) # Catch all other calls - File.expects(:executable?).with('/usr/bin/apt-get').returns true + 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" - puts apt_output - Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns apt_output + 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 -- 2.32.3