Permalink
Browse files

Add support for testing undefined resource parameters

Closes #13
  • Loading branch information...
1 parent 20cfb2d commit ac695d604319580e90fd1acae0ac98ca005b663c @rodjek committed Aug 29, 2011
Showing with 22 additions and 1 deletion.
  1. +7 −0 README.md
  2. +13 −0 lib/rspec-puppet/matchers/create_generic.rb
  3. +2 −1 spec/defines/sysctl_spec.rb
View
@@ -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 @@ def method_missing(method, *args, &block)
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 @@ def matches?(catalogue)
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 @@
.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

0 comments on commit ac695d6

Please sign in to comment.