From: Ashley Penney <ashley.penney@puppetlabs.com>
Date: Fri, 20 Dec 2013 18:57:48 +0000 (-0500)
Subject: Update to use modern rspec 2.14 syntax.
X-Git-Tag: 0.5.0~23^2~1
X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=d9d8aab561727bc39a83963e3767a8e4d13fa051;p=puppet-modules%2Fpuppetlabs-firewall.git

Update to use modern rspec 2.14 syntax.

This updates from mocha .stubs to allow(x).to receive(x) syntax,
and tweaks the Gemfile/Rakefile too.
---

diff --git a/Gemfile b/Gemfile
index 4ed08e8..2909ace 100644
--- a/Gemfile
+++ b/Gemfile
@@ -2,8 +2,10 @@ source 'https://rubygems.org'
 
 group :development, :test do
   gem 'puppetlabs_spec_helper', :require => false
-  gem 'rspec-system-puppet', '~>2.0'
-  gem 'puppet-lint'
+  gem 'rspec-puppet',           :require => false
+  gem 'serverspec',             :require => false
+  gem 'beaker-rspec',           :require => false
+  gem 'puppet-lint',            :require => false
 end
 
 if puppetversion = ENV['PUPPET_GEM_VERSION']
diff --git a/Rakefile b/Rakefile
index 261e9d0..8b12070 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,11 +1,4 @@
-require 'rubygems'
-require 'bundler/setup'
-
-Bundler.require :default
-
-require 'rspec/core/rake_task'
 require 'puppetlabs_spec_helper/rake_tasks'
-require 'rspec-system/rake_task'
 
 require 'puppet-lint/tasks/puppet-lint'
 PuppetLint.configuration.ignore_paths = ['vendor/**/*.pp']
diff --git a/spec/unit/facter/iptables_persistent_version_spec.rb b/spec/unit/facter/iptables_persistent_version_spec.rb
index 605e0da..13a23a5 100644
--- a/spec/unit/facter/iptables_persistent_version_spec.rb
+++ b/spec/unit/facter/iptables_persistent_version_spec.rb
@@ -10,8 +10,9 @@ describe "Facter::Util::Fact iptables_persistent_version" do
   }.each do |os, ver|
     describe "#{os} package installed" do
       before {
-        Facter.fact(:operatingsystem).stubs(:value).returns(os)
-        Facter::Util::Resolution.stubs(:exec).with(dpkg_cmd).returns(ver)
+        allow(Facter.fact(:operatingsystem)).to receive(:value).and_return(os)
+        allow(Facter::Util::Resolution).to receive(:exec).with(dpkg_cmd).
+          and_return(ver)
       }
       it { Facter.fact(:iptables_persistent_version).value.should == ver }
     end
@@ -19,14 +20,16 @@ describe "Facter::Util::Fact iptables_persistent_version" do
 
   describe 'Ubuntu package not installed' do
     before {
-      Facter.fact(:operatingsystem).stubs(:value).returns("Ubuntu")
-      Facter::Util::Resolution.stubs(:exec).with(dpkg_cmd).returns(nil)
+      allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('Ubuntu')
+      allow(Facter::Util::Resolution).to receive(:exec).with(dpkg_cmd).
+        and_return(nil)
     }
     it { Facter.fact(:iptables_persistent_version).value.should be_nil }
   end
 
   describe 'CentOS not supported' do
-    before { Facter.fact(:operatingsystem).stubs(:value).returns("CentOS") }
+    before { allow(Facter.fact(:operatingsystem)).to receive(:value).
+               and_return("CentOS") }
     it { Facter.fact(:iptables_persistent_version).value.should be_nil }
   end
 end
diff --git a/spec/unit/facter/iptables_spec.rb b/spec/unit/facter/iptables_spec.rb
index 1733f13..5773fdc 100644
--- a/spec/unit/facter/iptables_spec.rb
+++ b/spec/unit/facter/iptables_spec.rb
@@ -3,19 +3,21 @@ require 'spec_helper'
 describe "Facter::Util::Fact" do
   before {
     Facter.clear
-    Facter.fact(:kernel).stubs(:value).returns("Linux")
-    Facter.fact(:kernelrelease).stubs(:value).returns("2.6")
+    allow(Facter.fact(:kernel)).to receive(:value).and_return('Linux')
+    allow(Facter.fact(:kernelrelease)).to receive(:value).and_return('2.6')
   }
 
   describe 'iptables_version' do
     it {
-      Facter::Util::Resolution.stubs(:exec).with('iptables --version').returns('iptables v1.4.7')
+      allow(Facter::Util::Resolution).to receive(:exec).with('iptables --version').
+      and_return('iptables v1.4.7')
       Facter.fact(:iptables_version).value.should == '1.4.7'
     }
   end
 
   describe 'ip6tables_version' do
-    before { Facter::Util::Resolution.stubs(:exec).with('ip6tables --version').returns('ip6tables v1.4.7') }
+    before { allow(Facter::Util::Resolution).to receive(:exec).
+             with('ip6tables --version').and_return('ip6tables v1.4.7') }
     it { Facter.fact(:ip6tables_version).value.should == '1.4.7' }
   end
 end
diff --git a/spec/unit/puppet/provider/iptables_spec.rb b/spec/unit/puppet/provider/iptables_spec.rb
index 20aa7a6..4248cdb 100644
--- a/spec/unit/puppet/provider/iptables_spec.rb
+++ b/spec/unit/puppet/provider/iptables_spec.rb
@@ -1,7 +1,7 @@
 #!/usr/bin/env rspec
 
 require 'spec_helper'
-require 'puppet/provider/confine/exists'
+#require 'puppet/provider/confine/exists'
 
 describe 'iptables provider detection' do
   let(:exists) {
@@ -44,7 +44,7 @@ describe 'iptables provider' do
   }
 
   before :each do
-    Puppet::Type::Firewall.stubs(:defaultprovider).returns provider
+    allow(Puppet::Type::Firewall).to receive(:defaultprovider).and_return provider
     allow(provider).to receive(:command).with(:iptables_save).and_return "/sbin/iptables-save"
 
     # Stub iptables version
@@ -205,15 +205,15 @@ describe 'ip6tables provider' do
   }
 
   before :each do
-    Puppet::Type::Firewall.stubs(:ip6tables).returns provider6
-    provider6.stubs(:command).with(:ip6tables_save).returns "/sbin/ip6tables-save"
+    allow(Puppet::Type::Firewall).to receive(:ip6tables).and_return provider6
+    allow(provider6).to receive(:command).with(:ip6tables_save).and_return "/sbin/ip6tables-save"
 
     # Stub iptables version
-    Facter.fact(:ip6tables_version).stubs(:value).returns("1.4.7")
+    allow(Facter.fact(:ip6tables_version)).to receive(:value).and_return '1.4.7'
 
-    Puppet::Util::Execution.stubs(:execute).returns ""
-    Puppet::Util.stubs(:which).with("ip6tables-save").
-      returns "/sbin/ip6tables-save"
+    allow(Puppet::Util::Execution).to receive(:execute).and_return ''
+    allow(Puppet::Util).to receive(:which).with("ip6tables-save").
+      and_return "/sbin/ip6tables-save"
   end
 
   it 'should be able to get a list of existing rules' do
@@ -224,9 +224,8 @@ describe 'ip6tables provider' do
   end
 
   it 'should ignore lines with fatal errors' do
-    Puppet::Util::Execution.stubs(:execute).with(['/sbin/ip6tables-save']).
-      returns("FATAL: Could not load /lib/modules/2.6.18-028stab095.1/modules.dep: No such file or directory")
-
+    allow(Puppet::Util::Execution).to receive(:execute).with(['/sbin/ip6tables-save']).
+      and_return("FATAL: Could not load /lib/modules/2.6.18-028stab095.1/modules.dep: No such file or directory")
     provider6.instances.length.should == 0
   end
 
diff --git a/spec/unit/puppet/type/firewall_spec.rb b/spec/unit/puppet/type/firewall_spec.rb
index ed1cbbc..1d6b7d8 100755
--- a/spec/unit/puppet/type/firewall_spec.rb
+++ b/spec/unit/puppet/type/firewall_spec.rb
@@ -8,18 +8,18 @@ describe firewall do
   before :each do
     @class = firewall
     @provider = double 'provider'
-    @provider.stubs(:name).returns(:iptables)
-    Puppet::Type::Firewall.stubs(:defaultprovider).returns @provider
+    allow(@provider).to receive(:name).and_return(:iptables)
+    allow(Puppet::Type::Firewall).to receive(:defaultprovider).and_return @provider
 
     @resource = @class.new({:name  => '000 test foo'})
 
     # Stub iptables version
-    Facter.fact(:iptables_version).stubs(:value).returns("1.4.2")
-    Facter.fact(:ip6tables_version).stubs(:value).returns("1.4.2")
+    allow(Facter.fact(:iptables_version)).to receive(:value).and_return('1.4.2')
+    allow(Facter.fact(:ip6tables_version)).to receive(:value).and_return('1.4.2')
 
     # Stub confine facts
-    Facter.fact(:kernel).stubs(:value).returns("Linux")
-    Facter.fact(:operatingsystem).stubs(:value).returns("Debian")
+    allow(Facter.fact(:kernel)).to receive(:value).and_return('Linux')
+    allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('Debian')
   end
 
   it 'should have :name be its namevar' do
@@ -379,8 +379,8 @@ describe firewall do
       describe "with iptables #{iptables_version}" do
         before {
           Facter.clear
-          Facter.fact(:iptables_version).stubs(:value).returns(iptables_version)
-          Facter.fact(:ip6tables_version).stubs(:value).returns(iptables_version)
+          allow(Facter.fact(:iptables_version)).to receive(:value).and_return iptables_version
+          allow(Facter.fact(:ip6tables_version)).to receive(:value).and_return iptables_version
         }
 
         if iptables_version == '1.3.2'
diff --git a/spec/unit/puppet/type/firewallchain_spec.rb b/spec/unit/puppet/type/firewallchain_spec.rb
index dcae102..6632d4f 100755
--- a/spec/unit/puppet/type/firewallchain_spec.rb
+++ b/spec/unit/puppet/type/firewallchain_spec.rb
@@ -5,19 +5,19 @@ require 'spec_helper'
 firewallchain = Puppet::Type.type(:firewallchain)
 
 describe firewallchain do
-  before do
+  before(:each) do
     # Stub confine facts
-    Facter.fact(:kernel).stubs(:value).returns("Linux")
-    Facter.fact(:operatingsystem).stubs(:value).returns("Debian")
+    allow(Facter.fact(:kernel)).to receive(:value).and_return('Linux')
+    allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('Debian')
   end
   let(:klass) { firewallchain }
   let(:provider) {
     prov = double 'provider'
-    prov.stubs(:name).returns(:iptables_chain)
+    allow(prov).to receive(:name).and_return(:iptables_chain)
     prov
   }
   let(:resource) {
-    Puppet::Type::Firewallchain.stubs(:defaultprovider).returns provider
+    allow(Puppet::Type::Firewallchain).to receive(:defaultprovider).and_return provider
     klass.new({:name => 'INPUT:filter:IPv4', :policy => :accept })
   }