Skip to content

Instantly share code, notes, and snippets.

@Cinderhaze
Created January 11, 2017 02:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Cinderhaze/b75f5f8e6c2a4f5f8ad842366b7f85bd to your computer and use it in GitHub Desktop.
Save Cinderhaze/b75f5f8e6c2a4f5f8ad842366b7f85bd to your computer and use it in GitHub Desktop.
Example of testing an individual element of an array from a parameter of a resource in rspec-puppet
require 'spec_helper'
describe 'hosttest' do
context 'with default values for all parameters' do
context 'With foo.local host pre_condition' do
let(:pre_condition) {"
host { 'foo.local':
ip => '1.2.3.4',
host_aliases => [ 'foo1.local', 'foo2.local' ],
}
"}
# This style works, but it requires the exact and full array for comparison
it { should contain_host('foo.local').with_host_aliases( ['foo1.local', 'foo2.local'] ) }
# This works, but it feels really awkard to do
it {
host_aliases = catalogue.resource('host', 'foo.local').send(:parameters)[:host_aliases]
expect(host_aliases).to include('foo1.local')
}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment