- include PuppetSpec::Compiler
-
- before :each do
- Puppet::Parser::Functions.autoloader.loadall
- Puppet::Parser::Functions.function(:getparam)
- end
-
- let :node do Puppet::Node.new('localhost') end
- let :compiler do Puppet::Parser::Compiler.new(node) end
- if Puppet.version.to_f >= 3.0
- let :scope do Puppet::Parser::Scope.new(compiler) end
- else
- let :scope do
- newscope = Puppet::Parser::Scope.new
- newscope.compiler = compiler
- newscope.source = Puppet::Resource::Type.new(:node, :localhost)
- newscope
- end
- end
-
- it "should exist" do
- expect(Puppet::Parser::Functions.function("getparam")).to eq("function_getparam")
- end
-
- describe 'when a resource is not specified' do
- it { expect { scope.function_getparam([]) }.to raise_error }
- it { expect { scope.function_getparam(['User[dan]']) }.to raise_error }
- it { expect { scope.function_getparam(['User[dan]']) }.to raise_error }
- it { expect { scope.function_getparam(['User[dan]', {}]) }.to raise_error }
- # This seems to be OK because we just check for a string.
- it { expect { scope.function_getparam(['User[dan]', '']) }.to_not raise_error }
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params().and_raise_error(ArgumentError, /Must specify a reference/) }
+ it { is_expected.to run.with_params('User[one]').and_raise_error(ArgumentError, /Must specify name of a parameter/) }
+ it { is_expected.to run.with_params('User[one]', 2).and_raise_error(ArgumentError, /Must specify name of a parameter/) }
+ it { is_expected.to run.with_params('User[one]', []).and_raise_error(ArgumentError, /Must specify name of a parameter/) }
+ it { is_expected.to run.with_params('User[one]', {}).and_raise_error(ArgumentError, /Must specify name of a parameter/) }
+
+ describe 'when compared against a user resource with no params' do
+ let(:pre_condition) { 'user { "one": }' }
+
+ it { is_expected.to run.with_params('User[one]', 'ensure').and_return('') }
+ it { is_expected.to run.with_params('User[two]', 'ensure').and_return('') }
+ it { is_expected.to run.with_params('User[one]', 'shell').and_return('') }