<commit_before># RSpec tests for your Puppet manifests & modules
[![Build Status](https://travis-ci.org/rodjek/rspec-puppet.svg?branch=master)](https://travis-ci.org/rodjek/rspec-puppet)
[![Coverage Status](https://coveralls.io/repos/rodjek/rspec-puppet/badge.svg?branch=master)](https://coveralls.io/r/rodjek/rspec-puppet?branch=master)

## Installation

    gem install rspec-puppet

> Note for ruby 1.8 users:  while rspec-puppet itself supports ruby 1.8, you'll
> need to pin rspec itself to `~> 3.1.0`, as later rspec versions do not work
> on old rubies anymore.

## Starting out with a new module

When you start out on a new module, run `rspec-puppet-init` to create the necessary files to configure rspec-puppet for your module's tests.

## Configure manifests for Puppet 4

With Puppet 3, the manifest is set to `$manifestdir/site.pp`. However Puppet 4 defaults to an empty value. In order to test manifests you will need to set appropriate settings.

Puppet configuration reference for `manifest` can be found online:

* Puppet 3: https://docs.puppet.com/puppet/3.8/reference/configuration.html#manifest
* Puppet 4: https://docs.puppet.com/puppet/4.8/reference/configuration.html#manifest

Configuration is typically done in a `spec/spec_helper.rb` file which each of your spec will require. Example code:
```ruby
# /spec
base_dir = File.dirname(File.expand_path(__FILE__))

RSpec.configure do |c|
  c.module_path     = File.join(base_dir, 'fixtures', 'modules')
  c.manifest_dir    = File.join(base_dir, 'fixtures', 'manifests')
  c.manifest        = File.join(base_dir, 'fixtures', 'manifests', 'site.pp')
  c.environmentpath = File.join(Dir.pwd, 'spec')

  # Coverage generation
  c.after(:suite) do
    RSpec::Puppet::Coverage.report!
  end
end
```

## Configuration

rspec-puppet can be configured by modifying the `RSpec.configure` block in your
`spec/spec_helper.rb` file.

```
RSpec.configure do |c|
  c.<config option> = <value>
end
```

#### manifest\_dir
Type   | Default  | Puppet Version(s)
------ | -------- | -----------------
String | Required | 2.x, 3.x

The path to the directory containing your basic manifests like `site.pp`.

#### module\_path
Type   | Default  | Puppet Version(s)
------ | -------- | -----------------
String | Required | 2.x, 3.x, 4.x

The path to the directory containing your Puppet modules.

#### default\_facts
Type | Default | Puppet Version(s)
---- | ------- | -----------------
Hash | `{}`    | 2.x, 3.x, 4.x

A hash of default facts that should be used for all the tests.

#### hiera\_config
Type   | Default       | Puppet Version(s)
------ | ------------- | -----------------
String | `"/dev/null"` | 3.x, 4.x

The path to your `hiera.yaml` file (if used).

#### default\_node\_params
Type | Default | Puppet Version(s)
---- | ------- | -----------------
Hash | `{}`    | 4.x

A hash of default node parameters that should be used for all the tests.

#### default\_trusted\_facts
Type | Default | Puppet Version(s)
---- | ------- | -----------------
Hash | `{}`    | 4.x

A hash of default trusted facts that should be used for all the tests
(available in the manifests as the `$trusted` hash). In order to use this, the
`trusted_node_data` setting must be set to `true`.

#### trusted\_node\_data
Type    | Default | Puppet Version(s)
------- | ------- | -----------------
Boolean | `false` | 3.x, 4.x

Configures rspec-puppet to use the `$trusted` hash when compiling the
catalogues.

#### confdir
Type   | Default         | Puppet Version(s)
------ | --------------- | -----------------
String | `"/etc/puppet"` | 2.x, 3.x, 4.x

The path to the main Puppet configuration directory.

#### config
Type   | Default                | Puppet Version(s)
------ | ---------------------- | -----------------
String | Puppet's default value | 2.x, 3.x, 4.x

The path to `puppet.conf`.

#### manifest
Type   | Default                | Puppet Version(s)
------ | ---------------------- | -----------------
String | Puppet's default value | 2.x, 3.x

The entry-point manifest for Puppet, usually `$manifest_dir/site.pp`.

#### template\_dir
Type   | Default | Puppet Version(s)
------ | ------- | -----------------
String | `nil`   | 2.x, 3.x

The path to the directory that Puppet should search for templates that are
stored outside of modules.

#### environmentpath
Type   | Default                               | Puppet Version(s)
------ | ------------------------------------- | -----------------
String | `"/etc/puppetlabs/code/environments"` | 4.x

The search path for environment directories.

#### parser
Type   | Default     | Puppet Version(s)
------ | ----------- | -----------------
String | `"current"` | 3.x

This switches between the 3.x (`current`) and 4.x (`future`) parsers.

#### ordering
Type   | Default        | Puppet Version(s)
------ | -------------- | -----------------
String | `"title-hash"` | 3.x, 4.x

How unrelated resources should be ordered when applying a catalogue.
 * `manifest` - Use the order in which the resources are declared in the
   manifest.
 * `title-hash` - Order the resources randomly, but in a consistent manner
   across runs (the order will only change if the manifest changes).
 * `random` - Order the resources randomly.

#### strict\_variables
Type    | Default | Puppet Version(s)
------- | ------- | -----------------
Boolean | `false` | 3.x, 4.x

Makes Puppet raise an error when it tries to reference a variable that hasn't
been defined (not including variables that have been explicitly set to
`undef`).

#### stringify\_facts
Type    | Default | Puppet Version(s)
------- | ------- | -----------------
Boolean | `true`  | 3.x, 4.x

Makes rspec-puppet coerce all the fact values into strings (matching the
behaviour of older versions of Puppet).

#### enable\_pathname\_stubbing
Type    | Default | Puppet Version(s)
------- | ------- | -----------------
Boolean |`false`  | 2.x, 3.x, 4.x

Configures rspec-puppet to stub out `Pathname#absolute?` with it's own
implementation. This should only be enabled if you're running into an issue
running cross-platform tests where you have Ruby code (types, providers,
functions, etc) that use `Pathname#absolute?`.

## Naming conventions

For clarity and consistency, I recommend that you use the following directory
structure and naming convention.

    module/
      ├── manifests/<commit_msg>Document setup_fixtures configuration option in README<commit_after># RSpec tests for your Puppet manifests & modules
[![Build Status](https://travis-ci.org/rodjek/rspec-puppet.svg?branch=master)](https://travis-ci.org/rodjek/rspec-puppet)
[![Coverage Status](https://coveralls.io/repos/rodjek/rspec-puppet/badge.svg?branch=master)](https://coveralls.io/r/rodjek/rspec-puppet?branch=master)

## Installation

    gem install rspec-puppet

> Note for ruby 1.8 users:  while rspec-puppet itself supports ruby 1.8, you'll
> need to pin rspec itself to `~> 3.1.0`, as later rspec versions do not work
> on old rubies anymore.

## Starting out with a new module

When you start out on a new module, run `rspec-puppet-init` to create the necessary files to configure rspec-puppet for your module's tests.

## Configure manifests for Puppet 4

With Puppet 3, the manifest is set to `$manifestdir/site.pp`. However Puppet 4 defaults to an empty value. In order to test manifests you will need to set appropriate settings.

Puppet configuration reference for `manifest` can be found online:

* Puppet 3: https://docs.puppet.com/puppet/3.8/reference/configuration.html#manifest
* Puppet 4: https://docs.puppet.com/puppet/4.8/reference/configuration.html#manifest

Configuration is typically done in a `spec/spec_helper.rb` file which each of your spec will require. Example code:
```ruby
# /spec
base_dir = File.dirname(File.expand_path(__FILE__))

RSpec.configure do |c|
  c.module_path     = File.join(base_dir, 'fixtures', 'modules')
  c.manifest_dir    = File.join(base_dir, 'fixtures', 'manifests')
  c.manifest        = File.join(base_dir, 'fixtures', 'manifests', 'site.pp')
  c.environmentpath = File.join(Dir.pwd, 'spec')

  # Coverage generation
  c.after(:suite) do
    RSpec::Puppet::Coverage.report!
  end
end
```

## Configuration

rspec-puppet can be configured by modifying the `RSpec.configure` block in your
`spec/spec_helper.rb` file.

```
RSpec.configure do |c|
  c.<config option> = <value>
end
```

#### manifest\_dir
Type   | Default  | Puppet Version(s)
------ | -------- | -----------------
String | Required | 2.x, 3.x

The path to the directory containing your basic manifests like `site.pp`.

#### module\_path
Type   | Default  | Puppet Version(s)
------ | -------- | -----------------
String | Required | 2.x, 3.x, 4.x

The path to the directory containing your Puppet modules.

#### default\_facts
Type | Default | Puppet Version(s)
---- | ------- | -----------------
Hash | `{}`    | 2.x, 3.x, 4.x

A hash of default facts that should be used for all the tests.

#### hiera\_config
Type   | Default       | Puppet Version(s)
------ | ------------- | -----------------
String | `"/dev/null"` | 3.x, 4.x

The path to your `hiera.yaml` file (if used).

#### default\_node\_params
Type | Default | Puppet Version(s)
---- | ------- | -----------------
Hash | `{}`    | 4.x

A hash of default node parameters that should be used for all the tests.

#### default\_trusted\_facts
Type | Default | Puppet Version(s)
---- | ------- | -----------------
Hash | `{}`    | 4.x

A hash of default trusted facts that should be used for all the tests
(available in the manifests as the `$trusted` hash). In order to use this, the
`trusted_node_data` setting must be set to `true`.

#### trusted\_node\_data
Type    | Default | Puppet Version(s)
------- | ------- | -----------------
Boolean | `false` | 3.x, 4.x

Configures rspec-puppet to use the `$trusted` hash when compiling the
catalogues.

#### confdir
Type   | Default         | Puppet Version(s)
------ | --------------- | -----------------
String | `"/etc/puppet"` | 2.x, 3.x, 4.x

The path to the main Puppet configuration directory.

#### config
Type   | Default                | Puppet Version(s)
------ | ---------------------- | -----------------
String | Puppet's default value | 2.x, 3.x, 4.x

The path to `puppet.conf`.

#### manifest
Type   | Default                | Puppet Version(s)
------ | ---------------------- | -----------------
String | Puppet's default value | 2.x, 3.x

The entry-point manifest for Puppet, usually `$manifest_dir/site.pp`.

#### template\_dir
Type   | Default | Puppet Version(s)
------ | ------- | -----------------
String | `nil`   | 2.x, 3.x

The path to the directory that Puppet should search for templates that are
stored outside of modules.

#### environmentpath
Type   | Default                               | Puppet Version(s)
------ | ------------------------------------- | -----------------
String | `"/etc/puppetlabs/code/environments"` | 4.x

The search path for environment directories.

#### parser
Type   | Default     | Puppet Version(s)
------ | ----------- | -----------------
String | `"current"` | 3.x

This switches between the 3.x (`current`) and 4.x (`future`) parsers.

#### ordering
Type   | Default        | Puppet Version(s)
------ | -------------- | -----------------
String | `"title-hash"` | 3.x, 4.x

How unrelated resources should be ordered when applying a catalogue.
 * `manifest` - Use the order in which the resources are declared in the
   manifest.
 * `title-hash` - Order the resources randomly, but in a consistent manner
   across runs (the order will only change if the manifest changes).
 * `random` - Order the resources randomly.

#### strict\_variables
Type    | Default | Puppet Version(s)
------- | ------- | -----------------
Boolean | `false` | 3.x, 4.x

Makes Puppet raise an error when it tries to reference a variable that hasn't
been defined (not including variables that have been explicitly set to
`undef`).

#### stringify\_facts
Type    | Default | Puppet Version(s)
------- | ------- | -----------------
Boolean | `true`  | 3.x, 4.x

Makes rspec-puppet coerce all the fact values into strings (matching the
behaviour of older versions of Puppet).

#### enable\_pathname\_stubbing
Type    | Default | Puppet Version(s)
------- | ------- | -----------------
Boolean |`false`  | 2.x, 3.x, 4.x

Configures rspec-puppet to stub out `Pathname#absolute?` with it's own
implementation. This should only be enabled if you're running into an issue
running cross-platform tests where you have Ruby code (types, providers,
functions, etc) that use `Pathname#absolute?`.

#### setup\_fixtures
Type    | Default | Puppet Version(s)
------- | ------- | ---------------
Boolean | `true`  | 2.x, 3.x, 4.x

Configures rspec-puppet to automatically create a link from the root of your
module to `spec/fixtures/<module name>` at the beginning of the test run.

## Naming conventions

For clarity and consistency, I recommend that you use the following directory
structure and naming convention.

    module/
      ├── manifests/
{'fraction_non_alphanumeric': 0.20052223331541355, 'fraction_numerical': 0.00837109285001152, 'mean_word_length': 2.384095634095634, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 16, 'https://': 12, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2030762', 'n_tokens_mistral': 4101, 'n_tokens_neox': 3867, 'n_words': 1333}