Add 'without' method

Adds a method 'without' which accepts a list of
parameters that should not be defined in the resource.

Example:

  it { should contain_service('keystone').without(
    ['restart', 'status']
  )}
This commit is contained in:
Dan Bode 2011-12-29 15:41:29 -08:00
parent 4184c54118
commit 4588a91049
3 changed files with 29 additions and 0 deletions

View File

@ -106,6 +106,15 @@ generic `without_<parameter>` chains.
it { should contain_file('/foo/bar').without_mode }
```
You can use the without method to verify that a list of parameters have not been
defined
```ruby
it { should contain_service('keystone').without(
['restart', 'status']
)}
```
### Writing tests
#### Basic test structure

View File

@ -14,6 +14,13 @@ module RSpec::Puppet
@expected_params = (@expected_params || []) | params.to_a
self
end
def without(*args, &block)
params = args.shift
@expected_undef_params = (@expected_undef_params || []) | params.to_a
self
end
def method_missing(method, *args, &block)
if method.to_s =~ /^with_/
param = method.to_s.gsub(/^with_/, '')

View File

@ -17,6 +17,19 @@ describe 'sysctl::common' do
)
end
end
describe 'when using without to specify parameter name(s)' do
it 'should pass if the parameter name is not contained in the resource' do
subject.should contain_exec('sysctl/reload').without('foo')
end
it 'should pass if the parameter names are not contained in the resource' do
subject.should contain_exec('sysctl/reload').without(['foo', 'bar'])
end
it 'should fail if any of the parameter names are contained in the resource' do
expect do
subject.should contain_exec('sysctl/reload').without(['foo', 'returns'])
end.should raise_error(RSpec::Expectations::ExpectationNotMetError)
end
end
end
describe 'sysctl::common' do