summaryrefslogtreecommitdiff
path: root/Spec Testing.md
blob: 5728aeb2798bcc274a28be026f2cb02b7c50c5ca (plain)
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
[[Puppet]]
[Rspec Puppet](https://rspec-puppet.com/)

---

```ruby
require 'spec_helper'

describe '<name of the thing being tested>' do
  # Your tests go in here
end
```

---

`is_expected.to` or `is_expected.to_not`

defined types need a title: `let(:title) { 'title' }`
parameters: `let(:params) { { 'a' => 'b' } }`

`contain_class('name')` or `contain_name`

`contain_` < can be suffixed with anything, ie `contain_file`, `contain_exec`, `contain_class` or just `contain_apache__params` for defined types.
`::` in `apache::params` -> `apache__params` of a defined type.

To test parameters chain `.with()` which contains a hash of expected paremeters. With can also be suffixed with the name of the param, ie `.with_ensure()`.

`only_with` for ensuring that a argument is the only argument being set on given resource.

---

> If a class is an fully qualified class reference (start with`::`) then in the test **do not** include the double colon to reference the class only use its name.

```puppet
// manifest
class { '::tempest': }

// test
is_expected.to contain_class('tempest') <- valid
is_expected.to contain_class('::tempest') <- invalid
```