parent
20cfb2d7c0
commit
ac695d6043
|
@ -78,6 +78,13 @@ the generic `with_<parameter>` chains.
|
|||
it { should contain_package('mysql-server').with_ensure('present') }
|
||||
```
|
||||
|
||||
You can also test that specific parameters have been left undefined with the
|
||||
generic `without_<parameter>` chains.
|
||||
|
||||
```ruby
|
||||
it { should contain_file('/foo/bar').without_mode }
|
||||
```
|
||||
|
||||
## Writing tests
|
||||
|
||||
### Basic test structure
|
||||
|
|
|
@ -14,6 +14,10 @@ module RSpec::Puppet
|
|||
param = method.to_s.gsub(/^with_/, '')
|
||||
(@expected_params ||= []) << [param, args[0]]
|
||||
self
|
||||
elsif method.to_s =~ /^without_/
|
||||
param = method.to_s.gsub(/^without_/, '')
|
||||
(@expected_undef_params ||= []) << param
|
||||
self
|
||||
else
|
||||
super
|
||||
end
|
||||
|
@ -34,6 +38,15 @@ module RSpec::Puppet
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
if @expected_undef_params
|
||||
@expected_undef_params.each do |name|
|
||||
unless resource.send(:parameters)[name.to_sym].nil?
|
||||
ret = false
|
||||
(@errors ||= []) << "#{name.to_s} undefined"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
ret
|
||||
|
|
|
@ -9,5 +9,6 @@ describe 'sysctl' do
|
|||
.with_context('/files/etc/sysctl.conf') \
|
||||
.with_changes("set vm.swappiness '60'") \
|
||||
.with_onlyif("match vm.swappiness[.='60'] size == 0") \
|
||||
.with_notify('Exec[sysctl/reload]') }
|
||||
.with_notify('Exec[sysctl/reload]')\
|
||||
.without_foo }
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue