Module sync 1d81b6a
[puppet-modules/puppetlabs-apt.git] / spec / defines / pin_spec.rb
index a11c3b5c253156dcae5b2866286932918f7c99ef..52ecb97132beddc48116fca47227a889c5b61142 100644 (file)
@@ -1,14 +1,21 @@
 require 'spec_helper'
-describe 'apt::pin', :type => :define do
+describe 'apt::pin', type: :define do
   let :pre_condition do
     'class { "apt": }'
   end
-  let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy' } }
+  let(:facts) do
+    {
+      os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
+      lsbdistid: 'Debian',
+      osfamily: 'Debian',
+      lsbdistcodename: 'wheezy',
+      puppetversion: Puppet.version,
+    }
+  end
   let(:title) { 'my_pin' }
 
   context 'defaults' do
-    it { is_expected.to contain_apt__setting("pref-my_pin").with_content(/Explanation: : my_pin\nPackage: \*\nPin: release a=my_pin\nPin-Priority: 0\n/)}
-    it { is_expected.to contain_apt__setting("pref-my_pin") }
+    it { is_expected.to contain_apt__setting('pref-my_pin').with_content(%r{Explanation: : my_pin\nPackage: \*\nPin: release a=my_pin\nPin-Priority: 0\n}) }
   end
 
   context 'set version' do
@@ -18,8 +25,8 @@ describe 'apt::pin', :type => :define do
         'version'  => '1',
       }
     end
-    it { is_expected.to contain_apt__setting("pref-my_pin").with_content(/Explanation: : my_pin\nPackage: vim\nPin: version 1\nPin-Priority: 0\n/)}
-    it { is_expected.to contain_apt__setting("pref-my_pin") }
+
+    it { is_expected.to contain_apt__setting('pref-my_pin').with_content(%r{Explanation: : my_pin\nPackage: vim\nPin: version 1\nPin-Priority: 0\n}) }
   end
 
   context 'set origin' do
@@ -29,8 +36,8 @@ describe 'apt::pin', :type => :define do
         'origin'   => 'test',
       }
     end
-    it { is_expected.to contain_apt__setting("pref-my_pin").with_content(/Explanation: : my_pin\nPackage: vim\nPin: origin test\nPin-Priority: 0\n/)}
-    it { is_expected.to contain_apt__setting("pref-my_pin") }
+
+    it { is_expected.to contain_apt__setting('pref-my_pin').with_content(%r{Explanation: : my_pin\nPackage: vim\nPin: origin test\nPin-Priority: 0\n}) }
   end
 
   context 'not defaults' do
@@ -47,28 +54,29 @@ describe 'apt::pin', :type => :define do
         'priority'        => 10,
       }
     end
-    it { is_expected.to contain_apt__setting("pref-my_pin").with_content(/Explanation: foo\nPackage: \*\nPin: release a=1, n=bar, v=2, c=baz, o=foobar, l=foobaz\nPin-Priority: 10\n/) }
-    it { is_expected.to contain_apt__setting("pref-my_pin").with({
-      'priority'     => 99,
-    })
+
+    it { is_expected.to contain_apt__setting('pref-my_pin').with_content(%r{Explanation: foo\nPackage: \*\nPin: release a=1, n=bar, v=2, c=baz, o=foobar, l=foobaz\nPin-Priority: 10\n}) }
+    it {
+      is_expected.to contain_apt__setting('pref-my_pin').with('priority' => 99)
     }
   end
 
   context 'ensure absent' do
     let :params do
       {
-        'ensure' => 'absent'
+        'ensure' => 'absent',
       }
     end
-    it { is_expected.to contain_apt__setting("pref-my_pin").with({
-      'ensure' => 'absent',
-    })
+
+    it {
+      is_expected.to contain_apt__setting('pref-my_pin').with('ensure' => 'absent')
     }
   end
 
   context 'bad characters' do
     let(:title) { 'such  bad && wow!' }
-    it { is_expected.to contain_apt__setting("pref-such__bad____wow_") }
+
+    it { is_expected.to contain_apt__setting('pref-such__bad____wow_') }
   end
 
   describe 'validation' do
@@ -78,10 +86,9 @@ describe 'apt::pin', :type => :define do
           'order' => 'foo',
         }
       end
+
       it do
-        expect {
-          is_expected.to compile
-        }.to raise_error(Puppet::Error, /Only integers are allowed/)
+        is_expected.to raise_error(Puppet::Error, %r{expects an Integer value, got String})
       end
     end
 
@@ -91,10 +98,9 @@ describe 'apt::pin', :type => :define do
           'version' => '1',
         }
       end
+
       it do
-        expect {
-          is_expected.to compile
-        }.to raise_error(Puppet::Error, /parameter version cannot be used in general form/)
+        is_expected.to raise_error(Puppet::Error, %r{parameter version cannot be used in general form})
       end
     end
 
@@ -105,10 +111,9 @@ describe 'apt::pin', :type => :define do
           'release' => 'foo',
         }
       end
+
       it do
-        expect {
-          is_expected.to compile
-        }.to raise_error(Puppet::Error, /parameters release and origin are mutually exclusive/)
+        is_expected.to raise_error(Puppet::Error, %r{parameters release and origin are mutually exclusive})
       end
     end
 
@@ -120,10 +125,9 @@ describe 'apt::pin', :type => :define do
           'packages' => 'vim',
         }
       end
+
       it do
-        expect {
-          is_expected.to compile
-        }.to raise_error(Puppet::Error, /parameters release, origin, and version are mutually exclusive/)
+        is_expected.to raise_error(Puppet::Error, %r{parameters release, origin, and version are mutually exclusive})
       end
     end
 
@@ -135,10 +139,9 @@ describe 'apt::pin', :type => :define do
           'packages' => 'vim',
         }
       end
+
       it do
-        expect {
-          is_expected.to compile
-        }.to raise_error(Puppet::Error, /parameters release, origin, and version are mutually exclusive/)
+        is_expected.to raise_error(Puppet::Error, %r{parameters release, origin, and version are mutually exclusive})
       end
     end
   end