]> review.fuel-infra Code Review - puppet-modules/puppetlabs-apt.git/commitdiff
Merge pull request #843 from tphoney/rspec_mock
authordavid22swan <david.swan@puppet.com>
Thu, 14 Feb 2019 10:08:45 +0000 (10:08 +0000)
committerGitHub <noreply@github.com>
Thu, 14 Feb 2019 10:08:45 +0000 (10:08 +0000)
(maint) use rspec-mock for unit tests

16 files changed:
.puppet-lint.rc
.sync.yml
metadata.json
spec/spec_helper.rb
spec/unit/facter/apt_dist_has_updates_spec.rb
spec/unit/facter/apt_dist_package_security_updates_spec.rb
spec/unit/facter/apt_dist_package_updates_spec.rb
spec/unit/facter/apt_dist_security_updates_spec.rb
spec/unit/facter/apt_dist_updates_spec.rb
spec/unit/facter/apt_has_updates_spec.rb
spec/unit/facter/apt_package_security_updates_spec.rb
spec/unit/facter/apt_package_updates_spec.rb
spec/unit/facter/apt_reboot_required_spec.rb
spec/unit/facter/apt_security_updates_spec.rb
spec/unit/facter/apt_update_last_success_spec.rb
spec/unit/facter/apt_updates_spec.rb

index cc96ece0513d69709b87af611173e2a6e4532f62..8b137891791fe96927ad78e64b0aad7bded08bdc 100644 (file)
@@ -1 +1 @@
---relative
+
index ad63bcd99bddf7dc5b0bafd1166b3ab26a1014dd..efaa46761fb723202bde3a38a19f7c2ee272adcc 100644 (file)
--- 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
index a32d7d6fc3d6fa5a915cffc1e76199a15011dfca..d529a87370ce89ab819d299da4b45f2196dc1155 100644 (file)
@@ -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
+}
index 0d5efc0be24af0796472c8f21fe7b1246c3c5a3f..149ff0337aeffe7198ab371816a123f3d7e0875f 100644 (file)
@@ -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
 
index ae67bcf11077de3b0b7e7de7d5f3fbe01b7a5c3a..216050d035a93574f9a2fab27a4f12eacc745005 100644 (file)
@@ -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
index d6f0a9f11b6ca9a8826d9b0301a55277221f699f..6355b793076ee5e522f0517e47c035900e92616d 100644 (file)
@@ -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
index 1a7d8e9eaa32842ed5f7f9e7e62883dc11504d5b..bbe212e6ee2f7f25f2065ea0960977a2ab4a7de0 100644 (file)
@@ -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
index 9b58b6e6964bab4601262f436d20aab15c49b41b..8035f1663d063170fe5b397de37d11d0dbaf7b85 100644 (file)
@@ -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
index 737d1b6578565f1208ec28f1bc340d0a5384ba32..f9942afe9e29f3f304f6720003dad5a96b97693a 100644 (file)
@@ -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
index 5c06c2fb9cf2ad15f755ea5d21bb3c469c231624..f7a1ca9dbd1209885a1fc5825139223e2e7dc433 100644 (file)
@@ -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
index 913add03d34db519f3588d49c25cd31d457b1172..53b91bcaa06943ca7433019c06c1690527602142 100644 (file)
@@ -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
index 3468691f00f083f362865bc3ec15429c91c9e1d5..4b3e749324927646ec9d76dfa3965c95e4d70dd2 100644 (file)
@@ -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
index 356f36b14de41d65a97f665a2ac0163ae97e30ad..b15cb4c6076499b68fceb116776de086eb5af6bb 100644 (file)
@@ -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
index fc93552b2b8f4f2b00f6f84d05ac5b965a53afc5..cde0158ef0fa89c209ca248b14680ba99f51d295 100644 (file)
@@ -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
index 60d727302c6ddade0a78ca89999d0aa54efbeb4d..dc0fc540b91c6c1ec98503ad3150e043e1d619e9 100644 (file)
@@ -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
index d0a5dbb0febe2a567ebb5fd764c64ee5d7e3d85a..e9d4c0df176155b9b9c816d453fa8309cc1825f3 100644 (file)
@@ -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