From f3e79ddcd56a221c7799b35efde7e9803a5c7923 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Mon, 1 Jun 2015 12:21:59 +0100 Subject: 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 --- spec/functions/defined_with_params_spec.rb | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) (limited to 'spec/functions/defined_with_params_spec.rb') diff --git a/spec/functions/defined_with_params_spec.rb b/spec/functions/defined_with_params_spec.rb index 3590304..516d986 100755 --- a/spec/functions/defined_with_params_spec.rb +++ b/spec/functions/defined_with_params_spec.rb @@ -1,37 +1,26 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -require 'rspec-puppet' describe 'defined_with_params' do - describe 'when a resource is not specified' do + describe 'when no resource is specified' do it { is_expected.to run.with_params().and_raise_error(ArgumentError) } end describe 'when compared against a resource with no attributes' do let :pre_condition do 'user { "dan": }' end - it do - is_expected.to run.with_params('User[dan]', {}).and_return(true) - is_expected.to run.with_params('User[bob]', {}).and_return(false) - is_expected.to run.with_params('User[dan]', {'foo' => 'bar'}).and_return(false) - end + it { is_expected.to run.with_params('User[dan]', {}).and_return(true) } + it { is_expected.to run.with_params('User[bob]', {}).and_return(false) } + it { is_expected.to run.with_params('User[dan]', {'foo' => 'bar'}).and_return(false) } end describe 'when compared against a resource with attributes' do let :pre_condition do 'user { "dan": ensure => present, shell => "/bin/csh", managehome => false}' end - it do - is_expected.to run.with_params('User[dan]', {}).and_return(true) - is_expected.to run.with_params('User[dan]', '').and_return(true) - is_expected.to run.with_params('User[dan]', {'ensure' => 'present'} - ).and_return(true) - is_expected.to run.with_params('User[dan]', - {'ensure' => 'present', 'managehome' => false} - ).and_return(true) - is_expected.to run.with_params('User[dan]', - {'ensure' => 'absent', 'managehome' => false} - ).and_return(false) - end + it { is_expected.to run.with_params('User[dan]', {}).and_return(true) } + it { is_expected.to run.with_params('User[dan]', '').and_return(true) } + it { is_expected.to run.with_params('User[dan]', {'ensure' => 'present'}).and_return(true) } + it { is_expected.to run.with_params('User[dan]', {'ensure' => 'present', 'managehome' => false}).and_return(true) } + it { is_expected.to run.with_params('User[dan]', {'ensure' => 'absent', 'managehome' => false}).and_return(false) } end end -- cgit v1.2.3 From af875b11ff284cfe2ea95d208a614576a4342b2c Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Wed, 29 Jun 2016 21:33:00 +0100 Subject: (MODULES-3543) Fix define_with_params to handle undef properly As described in PUP-6422, ensure_resources('File[/tmp/a]', { owner => undef }) would not actually create the file. This fixes it, and adds tests to prove it. --- spec/functions/defined_with_params_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'spec/functions/defined_with_params_spec.rb') diff --git a/spec/functions/defined_with_params_spec.rb b/spec/functions/defined_with_params_spec.rb index 516d986..e00c423 100755 --- a/spec/functions/defined_with_params_spec.rb +++ b/spec/functions/defined_with_params_spec.rb @@ -23,4 +23,13 @@ describe 'defined_with_params' do it { is_expected.to run.with_params('User[dan]', {'ensure' => 'present', 'managehome' => false}).and_return(true) } it { is_expected.to run.with_params('User[dan]', {'ensure' => 'absent', 'managehome' => false}).and_return(false) } end + + describe 'when passing undef values' do + let :pre_condition do + 'file { "/tmp/a": }' + end + + it { is_expected.to run.with_params('File[/tmp/a]', {}).and_return(true) } + it { is_expected.to run.with_params('File[/tmp/a]', { 'owner' => :undef }).and_return(true) } + end end -- cgit v1.2.3 From 3f86e3a731b9e1be943a55fa12bd5e32716a20ef Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Thu, 30 Jun 2016 11:06:56 +0100 Subject: (MODULES-3543) Fixup defined_with_params to work on all puppet versions --- spec/functions/defined_with_params_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec/functions/defined_with_params_spec.rb') diff --git a/spec/functions/defined_with_params_spec.rb b/spec/functions/defined_with_params_spec.rb index e00c423..e2f3abe 100755 --- a/spec/functions/defined_with_params_spec.rb +++ b/spec/functions/defined_with_params_spec.rb @@ -26,10 +26,10 @@ describe 'defined_with_params' do describe 'when passing undef values' do let :pre_condition do - 'file { "/tmp/a": }' + 'file { "/tmp/a": ensure => present }' end it { is_expected.to run.with_params('File[/tmp/a]', {}).and_return(true) } - it { is_expected.to run.with_params('File[/tmp/a]', { 'owner' => :undef }).and_return(true) } + it { is_expected.to run.with_params('File[/tmp/a]', { 'ensure' => 'present', 'owner' => :undef }).and_return(true) } end end -- cgit v1.2.3