Skip to content

Commit

Permalink
Update spec tests for rspec-puppet 2.0
Browse files Browse the repository at this point in the history
Update tests for rspec-puppet 2.0

This patch changes `should` to `catalogue` for raise_error matchers
since `should` has the same problems as `subject`, where it is not
evaluated the way it used to be. We also unpin rspec-puppet.

Guard validate_cmd test for older puppet versions

Test group membership only on newer puppet

The defined() function doesn't seem to work properly with puppet 3.4 and rspec.
defined() works on its own, rspec works on its own, but together they
determine that $gid is not defined and cause errors here. Work around
it by ignoring this check for older puppet version.
  • Loading branch information
Colleen Murphy authored and bmjen committed Jun 12, 2015
1 parent e71af81 commit 6ad7f74
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 32 deletions.
6 changes: 6 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,18 @@
true: {
$warn_message = $default_warn_message
}
# lint:ignore:quoted_booleans
'true', 'yes', 'on': {
# lint:endignore
warning($bool_warn_message)
$warn_message = $default_warn_message
}
false: {
$warn_message = ''
}
# lint:ignore:quoted_booleans
'false', 'no', 'off': {
# lint:endignore
warning($bool_warn_message)
$warn_message = ''
}
Expand Down Expand Up @@ -246,7 +250,9 @@
# lint:ignore:quoted_booleans
$absent_exec_command = $::kernel ? {
'windows' => 'cmd.exe /c exit 0',
# lint:ignore:quoted_booleans
default => 'true',
# lint:endignore
}
# lint:endignore

Expand Down
30 changes: 19 additions & 11 deletions spec/unit/defines/concat_fragment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,21 @@
should contain_file("#{fragdir}/fragments/#{p[:order]}_#{safe_name}").with({
:ensure => safe_ensure,
:owner => id,
:group => gid,
:mode => '0640',
:source => p[:source],
:content => p[:content],
:alias => "concat_fragment_#{title}",
:backup => 'puppet',
})
# The defined() function doesn't seem to work properly with puppet 3.4 and rspec.
# defined() works on its own, rspec works on its own, but together they
# determine that $gid is not defined and cause errors here. Work around
# it by ignoring this check for older puppet version.
if Puppet::Util::Package.versioncmp(Puppet.version, '3.5.0') >= 0
should contain_file("#{fragdir}/fragments/#{p[:order]}_#{safe_name}").with({
:group => gid,
})
end
end
end

Expand All @@ -79,7 +87,7 @@
let(:params) {{ :target => false }}

it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /is not a string/)
expect { catalogue }.to raise_error(Puppet::Error, /is not a string/)
end
end
end # target =>
Expand Down Expand Up @@ -121,7 +129,7 @@
let(:params) {{ :content => false, :target => '/etc/motd' }}

it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /is not a string/)
expect { catalogue }.to raise_error(Puppet::Error, /is not a string/)
end
end
end # content =>
Expand All @@ -142,7 +150,7 @@
let(:params) {{ :source => false, :target => '/etc/motd' }}

it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /is not a string or an Array/)
expect { catalogue }.to raise_error(Puppet::Error, /is not a string or an Array/)
end
end
end # source =>
Expand All @@ -163,7 +171,7 @@
let(:params) {{ :order => false, :target => '/etc/motd' }}

it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /is not a string or integer/)
expect { catalogue }.to raise_error(Puppet::Error, /is not a string or integer/)
end
end

Expand All @@ -173,7 +181,7 @@
let(:params) {{ :order => '123:456', :target => '/etc/motd' }}

it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /cannot contain/)
expect { catalogue }.to raise_error(Puppet::Error, /cannot contain/)
end
end
context '123/456' do
Expand All @@ -182,7 +190,7 @@
let(:params) {{ :order => '123/456', :target => '/etc/motd' }}

it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /cannot contain/)
expect { catalogue }.to raise_error(Puppet::Error, /cannot contain/)
end
end
context '123\n456' do
Expand All @@ -191,7 +199,7 @@
let(:params) {{ :order => "123\n456", :target => '/etc/motd' }}

it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /cannot contain/)
expect { catalogue }.to raise_error(Puppet::Error, /cannot contain/)
end
end
end # order =>
Expand Down Expand Up @@ -219,7 +227,7 @@
end

it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /#{Regexp.escape(error_msg)}/m)
expect { catalogue }.to raise_error(Puppet::Error, /#{Regexp.escape(error_msg)}/m)
end
end

Expand All @@ -243,7 +251,7 @@
end

it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /#{Regexp.escape(error_msg)}/m)
expect { catalogue }.to raise_error(Puppet::Error, /#{Regexp.escape(error_msg)}/m)
end
end

Expand All @@ -267,7 +275,7 @@
end

it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /#{Regexp.escape(error_msg)}/m)
expect { catalogue }.to raise_error(Puppet::Error, /#{Regexp.escape(error_msg)}/m)
end
end

Expand Down
44 changes: 23 additions & 21 deletions spec/unit/defines/concat_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
context title do
let(:title) { title }
it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /is not an absolute path/)
expect { catalogue }.to raise_error(Puppet::Error, /is not an absolute path/)
end
end
end
Expand Down Expand Up @@ -205,7 +205,7 @@
let(:title) { '/etc/foo.bar' }
let(:params) {{ :ensure => 'invalid' }}
it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /#{Regexp.escape('does not match "^present$|^absent$"')}/)
expect { catalogue }.to raise_error(Puppet::Error, /#{Regexp.escape('does not match "^present$|^absent$"')}/)
end
end
end # ensure =>
Expand All @@ -220,7 +220,7 @@
let(:title) { '/etc/foo.bar' }
let(:params) {{ :path => path }}
it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /is not an absolute path/)
expect { catalogue }.to raise_error(Puppet::Error, /is not an absolute path/)
end
end
end
Expand All @@ -235,7 +235,7 @@
let(:title) { '/etc/foo.bar' }
let(:params) {{ :owner => false }}
it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /is not a string/)
expect { catalogue }.to raise_error(Puppet::Error, /is not a string/)
end
end
end # owner =>
Expand All @@ -249,7 +249,7 @@
let(:title) { '/etc/foo.bar' }
let(:params) {{ :group => false }}
it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /is not a string/)
expect { catalogue }.to raise_error(Puppet::Error, /is not a string/)
end
end
end # group =>
Expand All @@ -263,7 +263,7 @@
let(:title) { '/etc/foo.bar' }
let(:params) {{ :mode => false }}
it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /is not a string/)
expect { catalogue }.to raise_error(Puppet::Error, /is not a string/)
end
end
end # mode =>
Expand Down Expand Up @@ -291,7 +291,7 @@
let(:title) { '/etc/foo.bar' }
let(:params) {{ :warn => 123 }}
it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /is not a string or boolean/)
expect { catalogue }.to raise_error(Puppet::Error, /is not a string or boolean/)
end
end
end # warn =>
Expand All @@ -307,7 +307,7 @@
let(:title) { '/etc/foo.bar' }
let(:params) {{ :force => 123 }}
it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /is not a boolean/)
expect { catalogue }.to raise_error(Puppet::Error, /is not a boolean/)
end
end
end # force =>
Expand All @@ -329,7 +329,7 @@
let(:title) { '/etc/foo.bar' }
let(:params) {{ :backup => [] }}
it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /backup must be string or bool/)
expect { catalogue }.to raise_error(Puppet::Error, /backup must be string or bool/)
end
end
end # backup =>
Expand All @@ -345,7 +345,7 @@
let(:title) { '/etc/foo.bar' }
let(:params) {{ :replace => 123 }}
it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /is not a boolean/)
expect { catalogue }.to raise_error(Puppet::Error, /is not a boolean/)
end
end
end # replace =>
Expand All @@ -361,7 +361,7 @@
let(:title) { '/etc/foo.bar' }
let(:params) {{ :order => 'invalid' }}
it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /#{Regexp.escape('does not match "^alpha$|^numeric$"')}/)
expect { catalogue }.to raise_error(Puppet::Error, /#{Regexp.escape('does not match "^alpha$|^numeric$"')}/)
end
end
end # order =>
Expand All @@ -377,22 +377,24 @@
let(:title) { '/etc/foo.bar' }
let(:params) {{ :ensure_newline => 123 }}
it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /is not a boolean/)
expect { catalogue }.to raise_error(Puppet::Error, /is not a boolean/)
end
end
end # ensure_newline =>

context 'validate_cmd =>' do
context '/usr/bin/test -e %' do
it_behaves_like 'concat', '/etc/foo.bar', { :validate_cmd => '/usr/bin/test -e %' }
end
if Puppet::Util::Package::versioncmp(Puppet::version, '3.5.0') > 0
context '/usr/bin/test -e %' do
it_behaves_like 'concat', '/etc/foo.bar', { :validate_cmd => '/usr/bin/test -e %' }
end

[ 1234, true ].each do |cmd|
context cmd do
let(:title) { '/etc/foo.bar' }
let(:params) {{ :validate_cmd => cmd }}
it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /\$validate_cmd must be a string/)
[ 1234, true ].each do |cmd|
context cmd do
let(:title) { '/etc/foo.bar' }
let(:params) {{ :validate_cmd => cmd }}
it 'should fail' do
expect { catalogue }.to raise_error(Puppet::Error, /\$validate_cmd must be a string/)
end
end
end
end
Expand Down

0 comments on commit 6ad7f74

Please sign in to comment.