1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
### Specifying parameters
If the object being tested takes parameters, these can be specified as a hash
of values using `let(:params)`.
{% highlight ruby %}
let(:params) { {'ensure' => 'present', 'enable' => true} }
{% endhighlight %}
When passing `undef` as a parameter value, it should be passed as the symbol
`:undef`.
{% highlight ruby %}
let(:params) { {'user' => :undef} }
{% endhighlight %}
When passing a reference to a resource (e.g. `Package['apache2']`), it should
be passed as a call to the `ref` helper (`ref(<resource type>, <resource
title>)`)
{% highlight ruby %}
let(:params) { {'require' => ref('Package', 'apache2')} }
{% endhighlight %}
If have nested RSpec contexts to test the behaviour of different parameter
values, you can partially override the parameters by merging the changed
parameters into `super()` in your `let(:params)` block.
{% highlight ruby %}
describe 'My::Class' do
let(:params) do
{
'some_common_param' => 'value',
'ensure' => 'present',
}
end
context 'with ensure => absent' do
let(:params) do
super().merge({ 'ensure' => 'absent' })
end
it { should compile }
end
end
{% endhighlight %}
### Specifying the FQDN of the test node
If the object being tested depends upon the node having a certain name, it
can be specified using `let(:node)`.
{% highlight ruby %}
let(:node) { 'testhost.example.com' }
{% endhighlight %}
|