summaryrefslogtreecommitdiff
path: root/spec/functions/ensure_packages_spec.rb
diff options
context:
space:
mode:
authorHunter Haugen <hunter@puppetlabs.com>2015-06-01 13:36:25 -0700
committerHunter Haugen <hunter@puppetlabs.com>2015-06-01 13:36:25 -0700
commita383705fdb133978e53503b7e01012367fac139d (patch)
treef044a3b9c65db499ae279a08328c18200201d094 /spec/functions/ensure_packages_spec.rb
parent1ae9058518d042ea81d42f46cebbb040b35a2b4d (diff)
parent18d4c21418e8d188ae659a92ff3a8df04d711f6a (diff)
downloadpuppet-stdlib-a383705fdb133978e53503b7e01012367fac139d.tar.gz
puppet-stdlib-a383705fdb133978e53503b7e01012367fac139d.tar.bz2
Merge pull request #464 from DavidS/modules-1882-convert-to-rspec
(MODULES-1882) convert function tests to rspec-puppet
Diffstat (limited to 'spec/functions/ensure_packages_spec.rb')
-rwxr-xr-xspec/functions/ensure_packages_spec.rb105
1 files changed, 30 insertions, 75 deletions
diff --git a/spec/functions/ensure_packages_spec.rb b/spec/functions/ensure_packages_spec.rb
index 436be10..c824732 100755
--- a/spec/functions/ensure_packages_spec.rb
+++ b/spec/functions/ensure_packages_spec.rb
@@ -1,81 +1,36 @@
-#! /usr/bin/env ruby
-
require 'spec_helper'
-require 'rspec-puppet'
-require 'puppet_spec/compiler'
describe 'ensure_packages' do
- include PuppetSpec::Compiler
-
- before :each do
- Puppet::Parser::Functions.autoloader.loadall
- Puppet::Parser::Functions.function(:ensure_packages)
- Puppet::Parser::Functions.function(:ensure_resource)
- Puppet::Parser::Functions.function(:defined_with_params)
- Puppet::Parser::Functions.function(:create_resources)
- end
-
- let :node do Puppet::Node.new('localhost') end
- let :compiler do Puppet::Parser::Compiler.new(node) end
- let :scope do
- if Puppet.version.to_f >= 3.0
- Puppet::Parser::Scope.new(compiler)
- else
- newscope = Puppet::Parser::Scope.new
- newscope.compiler = compiler
- newscope.source = Puppet::Resource::Type.new(:node, :localhost)
- newscope
- end
- end
-
- describe 'argument handling' do
- it 'fails with no arguments' do
- expect {
- scope.function_ensure_packages([])
- }.to raise_error(Puppet::ParseError, /0 for 1 or 2/)
- end
-
- it 'accepts an array of values' do
- scope.function_ensure_packages([['foo']])
- end
-
- it 'accepts a single package name as a string' do
- scope.function_ensure_packages(['foo'])
- end
- end
-
- context 'given a catalog with puppet package => absent' do
- let :catalog do
- compile_to_catalog(<<-EOS
- ensure_packages(['facter'])
- package { puppet: ensure => absent }
- EOS
- )
- end
-
- it 'has no effect on Package[puppet]' do
- expect(catalog.resource(:package, 'puppet')['ensure']).to eq('absent')
- end
- end
-
- context 'given a clean catalog' do
- let :catalog do
- compile_to_catalog('ensure_packages(["facter"])')
- end
-
- it 'declares package resources with ensure => present' do
- expect(catalog.resource(:package, 'facter')['ensure']).to eq('present')
- end
- end
-
- context 'given a clean catalog and specified defaults' do
- let :catalog do
- compile_to_catalog('ensure_packages(["facter"], {"provider" => "gem"})')
- end
-
- it 'declares package resources with ensure => present' do
- expect(catalog.resource(:package, 'facter')['ensure']).to eq('present')
- expect(catalog.resource(:package, 'facter')['provider']).to eq('gem')
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError) }
+ it {
+ pending("should not accept numbers as arguments")
+ is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError)
+ }
+ it {
+ pending("should not accept numbers as arguments")
+ is_expected.to run.with_params(["packagename", 1]).and_raise_error(Puppet::ParseError)
+ }
+ it { is_expected.to run.with_params("packagename") }
+ it { is_expected.to run.with_params(["packagename1", "packagename2"]) }
+
+ context 'given a catalog with "package { puppet: ensure => absent }"' do
+ let(:pre_condition) { 'package { puppet: ensure => absent }' }
+
+ describe 'after running ensure_package("facter")' do
+ before { subject.call(['facter']) }
+
+ # this lambda is required due to strangeness within rspec-puppet's expectation handling
+ it { expect(lambda { catalogue }).to contain_package('puppet').with_ensure('absent') }
+ it { expect(lambda { catalogue }).to contain_package('facter').with_ensure('present') }
+ end
+
+ describe 'after running ensure_package("facter", { "provider" => "gem" })' do
+ before { subject.call(['facter', { "provider" => "gem" }]) }
+
+ # this lambda is required due to strangeness within rspec-puppet's expectation handling
+ it { expect(lambda { catalogue }).to contain_package('puppet').with_ensure('absent').without_provider() }
+ it { expect(lambda { catalogue }).to contain_package('facter').with_ensure('present').with_provider("gem") }
end
end
end