From 27514d58573ce1f844af4ea60afa72c7f58f1cd7 Mon Sep 17 00:00:00 2001 From: Jasper Ras Date: Thu, 21 Aug 2025 22:09:29 +0200 Subject: vault backup: 2025-08-21 22:09:29 --- Spec Testing.md | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Spec Testing.md (limited to 'Spec Testing.md') diff --git a/Spec Testing.md b/Spec Testing.md new file mode 100644 index 0000000..5728aeb --- /dev/null +++ b/Spec Testing.md @@ -0,0 +1,41 @@ +[[Puppet]] +[Rspec Puppet](https://rspec-puppet.com/) + +--- + +```ruby +require 'spec_helper' + +describe '' 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 +``` \ No newline at end of file -- cgit v1.2.3