summaryrefslogtreecommitdiff
path: root/spec/functions/getvar_spec.rb
diff options
context:
space:
mode:
authorDavid Schmitt <david.schmitt@puppetlabs.com>2015-06-01 12:21:59 +0100
committerDavid Schmitt <david.schmitt@puppetlabs.com>2015-06-01 18:02:22 +0100
commitf3e79ddcd56a221c7799b35efde7e9803a5c7923 (patch)
tree730386688574c94169d47d37f79af77c2cda2f08 /spec/functions/getvar_spec.rb
parentb62dff0c6e09faf9bacfb02575e689ed09ee5e56 (diff)
Convert tests to use plain rspec-puppet
Tests in the new style produces the following documentation output: abs should not eq nil should run abs() and raise an Puppet::ParseError should run abs(-34) and return 34 should run abs("-34") and return 34 should run abs(34) and return 34 should run abs("34") and return 34
Diffstat (limited to 'spec/functions/getvar_spec.rb')
-rwxr-xr-xspec/functions/getvar_spec.rb47
1 files changed, 19 insertions, 28 deletions
diff --git a/spec/functions/getvar_spec.rb b/spec/functions/getvar_spec.rb
index 87ab9b5..37125d1 100755
--- a/spec/functions/getvar_spec.rb
+++ b/spec/functions/getvar_spec.rb
@@ -1,37 +1,28 @@
-#! /usr/bin/env ruby -S rspec
require 'spec_helper'
-describe Puppet::Parser::Functions.function(:getvar) do
- let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
- describe 'when calling getvar from puppet' do
+describe 'getvar' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
+ it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
+ it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
- it "should not compile when no arguments are passed" do
- skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
- Puppet[:code] = '$foo = getvar()'
- expect {
- scope.compiler.compile
- }.to raise_error(Puppet::ParseError, /wrong number of arguments/)
- end
+ context 'given variables in namespaces' do
+ let(:pre_condition) {
+ <<-'ENDofPUPPETcode'
+ class site::data { $foo = 'baz' }
+ include site::data
+ ENDofPUPPETcode
+ }
- it "should not compile when too many arguments are passed" do
- skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
- Puppet[:code] = '$foo = getvar("foo::bar", "baz")'
- expect {
- scope.compiler.compile
- }.to raise_error(Puppet::ParseError, /wrong number of arguments/)
+ it { is_expected.to run.with_params('site::data::foo').and_return('baz') }
+ it { is_expected.to run.with_params('::site::data::foo').and_return('baz') }
+
+ context 'with strict variable checking', :if => RSpec.configuration.strict_variables do
+ it { is_expected.to run.with_params('::site::data::bar').and_raise_error(ArgumentError, /undefined_variable/) }
end
- it "should lookup variables in other namespaces" do
- skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
- Puppet[:code] = <<-'ENDofPUPPETcode'
- class site::data { $foo = 'baz' }
- include site::data
- $foo = getvar("site::data::foo")
- if $foo != 'baz' {
- fail('getvar did not return what we expect')
- }
- ENDofPUPPETcode
- scope.compiler.compile
+ context 'without strict variable checking', :unless => RSpec.configuration.strict_variables do
+ it { is_expected.to run.with_params('::site::data::bar').and_return(nil) }
end
end
end