summaryrefslogtreecommitdiff
path: root/spec/functions/ensure_packages_spec.rb
diff options
context:
space:
mode:
authorAshley Penney <ashley.penney@puppetlabs.com>2014-03-05 15:43:58 -0500
committerAshley Penney <ashley.penney@puppetlabs.com>2014-03-08 00:42:51 +0000
commit3854e076ccb75d1bcb1ddd29f5976b194d857765 (patch)
tree2624c5c96549324719fbf6eaca781888d6d4646d /spec/functions/ensure_packages_spec.rb
parentfecb53d46ed9e926973cdf5be1289c1ea71c2f68 (diff)
Numerous changes to update testing gems.
This work updates a number of Gems to the latest versions (rspec, rspec-puppet), and updates and tweaks a bunch of tests to work with the updated gems.
Diffstat (limited to 'spec/functions/ensure_packages_spec.rb')
-rw-r--r--spec/functions/ensure_packages_spec.rb48
1 files changed, 36 insertions, 12 deletions
diff --git a/spec/functions/ensure_packages_spec.rb b/spec/functions/ensure_packages_spec.rb
index a13c282..bf62eff 100644
--- a/spec/functions/ensure_packages_spec.rb
+++ b/spec/functions/ensure_packages_spec.rb
@@ -2,9 +2,31 @@
require 'spec_helper'
require 'rspec-puppet'
+require 'puppet_spec/compiler'
describe 'ensure_packages' do
- let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+ 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
@@ -22,25 +44,27 @@ describe 'ensure_packages' do
end
end
- context 'given a catalog containing Package[puppet]{ensure => absent}' do
- let :pre_condition do
- 'package { puppet: ensure => absent }'
+ 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
- # NOTE: should run.with_params has the side effect of making the compiler
- # available to the test harness.
it 'has no effect on Package[puppet]' do
- should run.with_params(['puppet'])
- rsrc = compiler.catalog.resource('Package[puppet]')
- rsrc.to_hash.should == {:ensure => "absent"}
+ 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
- should run.with_params(['facter'])
- rsrc = compiler.catalog.resource('Package[facter]')
- rsrc.to_hash[:ensure].should eq("present")
+ expect(catalog.resource(:package, 'facter')['ensure']).to eq('present')
end
end
end