diff --git a/README.md b/README.md index 1a37002e6..bace8512d 100644 --- a/README.md +++ b/README.md @@ -22,35 +22,16 @@ 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, create a metadata.json file for your module and then 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.module_path = File.join(File.dirname(File.expand_path(__FILE__)), 'fixtures', 'modules') c.environmentpath = File.join(Dir.pwd, 'spec') - + c.manifest = File.join(File.dirname(File.expand_path(__FILE__)), 'fixtures', 'manifests', 'site.pp') # Coverage generation c.after(:suite) do RSpec::Puppet::Coverage.report! @@ -69,54 +50,46 @@ RSpec.configure do |c| 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, 5.x +String | Required | any The path to the directory containing your Puppet modules. #### default\_facts Type | Default | Puppet Version(s) ---- | ------- | ------------------ -Hash | `{}` | 2.x, 3.x, 4.x, 5.x +Hash | `{}` | any 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, 5.x +String | `"/dev/null"` | any The path to your `hiera.yaml` file (if used). #### default\_node\_params Type | Default | Puppet Version(s) ---- | ------- | ----------------- -Hash | `{}` | 4.x, 5.x +Hash | `{}` | any 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, 5.x +Hash | `{}` | any 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`. +(available in the manifests as the `$trusted` hash). #### trusted\_node\_data Type | Default | Puppet Version(s) ------- | ------- | ----------------- -Boolean | `false` | >=3.4, 4.x, 5.x +Boolean | `false` | any Configures rspec-puppet to use the `$trusted` hash when compiling the catalogues. @@ -124,7 +97,7 @@ catalogues. #### trusted\_server\_facts Type | Default | Puppet Version(s) ------- | ------- | ----------------- -Boolean | `false` | >=4.3, 5.x +Boolean | `false` | any Configures rspec-puppet to use the `$server_facts` hash when compiling the catalogues. @@ -132,62 +105,28 @@ catalogues. #### confdir Type | Default | Puppet Version(s) ------ | --------------- | ------------------ -String | `"/etc/puppet"` | 2.x, 3.x, 4.x, 5.x +String | `"/etc/puppet"` | any 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, 5.x +String | Puppet's default value | any 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, 5.x +String | `"/etc/puppetlabs/code/environments"` | any The search path for environment directories. -#### parser -Type | Default | Puppet Version(s) ------- | ----------- | ----------------- -String | `"current"` | >= 3.2 - -This switches between the 3.x (`current`) and 4.x (`future`) parsers. - -#### ordering -Type | Default | Puppet Version(s) ------- | -------------- | ----------------- -String | `"title-hash"` | >= 3.3, 4.x, 5.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.5, 4.x, 5.x +Boolean | `false` | any 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 @@ -196,7 +135,7 @@ been defined (not including variables that have been explicitly set to #### stringify\_facts Type | Default | Puppet Version(s) ------- | ------- | ----------------- -Boolean | `true` | >= 3.3, 4.x, 5.x +Boolean | `true` | any Makes rspec-puppet coerce all the fact values into strings (matching the behaviour of older versions of Puppet). @@ -204,7 +143,7 @@ behaviour of older versions of Puppet). #### enable\_pathname\_stubbing Type | Default | Puppet Version(s) ------- | ------- | ------------------ -Boolean |`false` | 2.x, 3.x, 4.x, 5.x +Boolean |`false` | any 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 @@ -214,7 +153,7 @@ functions, etc) that use `Pathname#absolute?`. #### setup\_fixtures Type | Default | Puppet Version(s) ------- | ------- | ------------------ -Boolean | `true` | 2.x, 3.x, 4.x, 5.x +Boolean | `true` | any Configures rspec-puppet to automatically create a link from the root of your module to `spec/fixtures/` at the beginning of the test run. @@ -222,7 +161,7 @@ module to `spec/fixtures/` at the beginning of the test run. #### derive\_node\_facts\_from\_nodename Type | Default | Puppet Version(s) ------- | ------- | ----------------- -Boolean | `true` | 2.x, 3.x, 4.x, 5.x +Boolean | `true` | any If `true`, rspec-puppet will override the `fdqn`, `hostname`, and `domain` facts with values that it derives from the node name (specified with @@ -235,7 +174,7 @@ setting to `false`. #### facter\_implementation Type | Default | Puppet Version(s) ------- | -------- | ----------------- -String | `facter` | 6.25+, 7.12+ +String | `facter` | any Configures rspec-puppet to use a specific Facter implementation for running unit tests. If the `rspec` implementation is set and Puppet does not support @@ -699,8 +638,6 @@ RSpec.configure do |c| end ``` -**NOTE** Setting top-scope variables is not supported in Puppet < 3.0. - #### Specifying extra code to load (pre-conditions) If the manifest being tested relies on another class or variables to be set, these can be added via @@ -752,7 +689,7 @@ let(:module_path) { '/path/to/your/module/dir' } #### Specifying trusted facts -When testing with Puppet >= 4.3 the trusted facts hash will have the standard trusted fact keys +The trusted facts hash will have the standard trusted fact keys (certname, domain, and hostname) populated based on the node name (as set with `:node`). By default, the test environment contains no custom trusted facts (as usually obtained @@ -777,8 +714,7 @@ end #### Specifying trusted external data -When testing with Puppet >= 6.14, the trusted facts hash will have an additional `external` -key for trusted external data. +The trusted facts hash will have an `external` key for trusted external data. By default, the test environment contains no trusted external data (as usually obtained from trusted external commands and found in the `external` key). If you need to test against specific diff --git a/docs/documentation/configuration/index.md b/docs/documentation/configuration/index.md index 3d2510250..1ea09e655 100644 --- a/docs/documentation/configuration/index.md +++ b/docs/documentation/configuration/index.md @@ -19,15 +19,10 @@ end {% endhighlight %} ## Required settings -### manifest\_dir -**Type:** String
-**Puppet Version(s):** 2.x, 3.x - -The path to the directory containing your basic manifests like `site.pp`. ### module\_path **Type:** String
-**Puppet Version(s):** 2.x, 3.x, 4.x, 5.x +**Puppet Version(s):** any The path to the directory containing the Puppet modules. @@ -35,44 +30,36 @@ The path to the directory containing the Puppet modules. ### default\_facts **Type:** Hash
**Default:** None
-**Puppet Version(s):** 2.x, 3.x, 4.x, 5.x +**Puppet Version(s):** any A hash of default facts that should be used for all the tests. ### hiera\_config **Type:** String
**Default:** `/dev/null`
-**Puppet Version(s):** 3.x, 4.x, 5.x +**Puppet Version(s):** any The path to your `hiera.yaml` file (if used). ### default\_node\_params **Type:** Hash
**Default:** None
-**Puppet Version(s):** 4.x, 5.x +**Puppet Version(s):** any A hash of default node parameters that should be used for all the tests. ### default\_trusted\_facts **Type:** Hash
**Default:** None
-**Puppet Version(s):** 4.x, 5.x +**Puppet Version(s):** any A hash of default trusted facts that should be used for all the tests -(available in the manifests as `$trusted`). In order to use this, -`trusted_node_data` must also be set to `true`. - -### trusted\_node\_data -**Type:** Boolean
-**Default:** `false`
-**Puppet Version(s):** ~> 3.4, 4.x, 5.x - -Makes rspec-puppet use the `$trusted` hash when testing catalogues. +(available in the manifests as `$trusted`). ### setup\_fixtures **Type:** Boolean
**Default:** `true`
-**Puppet Version(s):** 2.x, 3.x, 4.x, 5.x +**Puppet Version(s):** any Configures rspec-puppet to automatically create a link from the root of your module to `spec/fixtures/` at the beginning of the test run. @@ -80,7 +67,7 @@ module to `spec/fixtures/` at the beginning of the test run. ### trusted\_server\_facts **Type:** Boolean
**Default:** `false`
-**Puppet Version(s):** >= 4.3, 5.x +**Puppet Version(s):** any Configures rspec-puppet to use the `$server_facts` hash when compiling the catalogues. @@ -92,7 +79,7 @@ determining the values itself, but if you need to override them you can. ### confdir **Type:** String
**Default:** `/etc/puppet`
-**Puppet Version(s):** 2.x, 3.x, 4.x, 5.x +**Puppet Version(s):** any The path to the main Puppet configuration directory. @@ -103,40 +90,17 @@ for further details. ### config **Type:** String
**Default:** Puppet's default value
-**Puppet Version(s):** 2.x, 3.x, 4.x, 5.x +**Puppet Version(s):** any The path to `puppet.conf`. See the [Puppet documentation](https://docs.puppet.com/puppet/latest/configuration.html#config) for further details. -### manifest -**Type:** String
-**Default:** Puppet's default value
-**Puppet Version(s):** 2.x, 3.x - -The entry-point manifest for Puppet, usually `/site.pp`. - -See the [Puppet -documentation](https://docs.puppet.com/puppet/latest/configuration.html#manifest) -for further details. - -### template\_dir -**Type**: String
-**Default:** None
-**Puppet Version(s):** 2.x, 3.x - -The path to the directory that Puppet should search for templates stored -outside of modules. - -See the [Puppet -documentation](https://docs.puppet.com/puppet/3.8/deprecated_settings.html#templatedir) -for further details. - ### environmentpath **Type:** String
**Default:** `/etc/puppetlabs/code/environments`
-**Puppet Version(s):** 4.x, 5.x +**Puppet Version(s):** any The search path for environment directories. @@ -144,38 +108,10 @@ See the [Puppet documentation](https://docs.puppet.com/puppet/latest/configuration.html#environmentpath) for further details. -### parser -**Type:** String
-**Default:** `current`
-**Puppet Version(s):** ~> 3.2 - -This switches between the 3.x (`current`) and 4.x (`future`) parsers. - -See the [Puppet -documentation](https://docs.puppet.com/puppet/3.8/deprecated_settings.html#parser) -for further details. - -### ordering -**Type:** String
-**Default:** `title-hash`
-**Puppet Version(s):** ~> 3.3, 4.x, 5.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 code changes). - * `random` - Order the resources randomly (ideal for finding resources that - do not have explicit dependencies). - -See the [Puppet -documentation](https://docs.puppet.com/puppet/latest/configuration.html#ordering) -for further details. - ### strict\_variables **Type:** Boolean
**Default:** `false`
-**Puppet Version(s):** ~> 3.5, 4.x, 5.x +**Puppet Version(s):** any 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 @@ -184,7 +120,7 @@ been defined (not including variables that have been explicitly set to ### stringify\_facts **Type:** Boolean
**Default:** `true`
-**Puppet Version(s):** ~> 3.3, 4.x, 5.x +**Puppet Version(s):** any Makes rspec-puppet coerce all the fact values into strings (matching the behaviour of older versions of Puppet). @@ -192,7 +128,7 @@ behaviour of older versions of Puppet). ### enable\_pathname\_stubbing **Type:** Boolean
**Default:** `false`
-**Puppet Version(s):** 2.x, 3.x, 4.x, 5.x +**Puppet Version(s):** any Configures rspec-puppet to stub out `Pathname#absolute?` with its own implementation. This should only be enabled if you're running into an issue @@ -202,7 +138,7 @@ functions, etc) that use `Pathname#absolute?`. ### derive\_node\_facts\_from\_nodename **Type:** Boolean
**Default:** `true`
-**Puppet Version(s):** 2.x, 3.x, 4.x, 5.x +**Puppet Version(s):** any If `true`, rspec-puppet will override the `fdqn`, `hostname`, and `domain` facts with values that it derives from the node name (specified with @@ -215,7 +151,7 @@ setting to `false`. ### vendormoduledir **Type:** String
**Default:** `'/dev/null'` (or `'c:/nul/'` on Windows) -**Puppet Version(s):** 6.x +**Puppet Version(s):** any The path to the directory containing vendored modules. Almost always unnecessary in a testing environment. @@ -223,7 +159,7 @@ unnecessary in a testing environment. ### basemodulepath **Type:** String
**Default:** `'/dev/null'` (or `'c:/nul/'` on Windows) -**Puppet Version(s):** 6.x +**Puppet Version(s):** any The search path for global modules. Almost always unnecessary in a testing environment. @@ -231,7 +167,7 @@ environment. ### disable_module_hiera **Type:** Boolean
**Default:** `false`
-**Puppet Version(s):** 4.9+, 5.x, 6.x +**Puppet Version(s):** any Enabling this will prevent Puppet from using module-layer Hiera data entirely. This includes the module being tested as well as any fixture modules. @@ -240,7 +176,7 @@ The end effect is that only Hiera data from the global `:hiera_config` parameter ### fixture_hiera_configs **Type:** Hash
**Default:** `{}`
-**Puppet Version(s):** 4.9+, 5.x, 6.x +**Puppet Version(s):** any A hash of module names and their respective module-layer Hiera config file paths. This can be used to override the path to the module-layer hiera.yaml @@ -248,14 +184,14 @@ This can be used to override the path to the module-layer hiera.yaml ### use_fixture_spec_hiera **Type:** Boolean
**Default:** `false`
-**Puppet Version(s):** 4.9+, 5.x, 6.x +**Puppet Version(s):** any Enabling this will prevent Puppet from using the module-layer Hiera config file and instead search the module spec folder for a file named hiera.yaml. ### fallback_to_default_hiera **Type:** Boolean
**Default:** `true`
-**Puppet Version(s):** 4.9+, 5.x, 6.x +**Puppet Version(s):** any A hash of module names and their respective module-layer Hiera config file paths. This can be used to override the path to the module-layer hiera.yaml. diff --git a/docs/documentation/coverage/index.md b/docs/documentation/coverage/index.md index fba690dc2..b147ffa73 100644 --- a/docs/documentation/coverage/index.md +++ b/docs/documentation/coverage/index.md @@ -56,16 +56,6 @@ If this percentage is not achieved, a test failure will be raised. Resources declared outside of the module being tested (i.e. resources added by module dependencies) are automatically excluded from the coverage report. -
-
-
-Prior to Puppet 4.6.0, resources created by functions -(create_resources, ensure_packages etc) did not have -the required information in them to determine which manifest they came from and -so can not be excluded from the coverage report. -
-
- To exclude other resources from the coverage reports, for example to avoid `anchor`s, use the `add_filter(type, title)` and `add_filter_regex(type, regex)` methods: diff --git a/docs/documentation/setup/index.md b/docs/documentation/setup/index.md index eb0d10970..dd5820ec8 100644 --- a/docs/documentation/setup/index.md +++ b/docs/documentation/setup/index.md @@ -82,11 +82,9 @@ content. {% highlight ruby %} require 'rspec-puppet' -fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures')) - RSpec.configure do |c| - c.module_path = File.join(fixture_path, 'modules') - c.manifest_dir = File.join(fixture_path, 'manifests') + c.environmentpath = __dir__ + c.module_path = File.join(__dir__, 'fixtures', 'modules') end {% endhighlight %} diff --git a/lib/rspec-puppet.rb b/lib/rspec-puppet.rb index 887eb1075..2588da4a5 100644 --- a/lib/rspec-puppet.rb +++ b/lib/rspec-puppet.rb @@ -36,9 +36,7 @@ def self.current_example RSpec.configure do |c| c.add_setting :environmentpath, default: Puppet::Util::Platform.actually_windows? ? 'c:/nul/' : '/dev/null' c.add_setting :module_path, default: nil - c.add_setting :manifest_dir, default: nil c.add_setting :manifest, default: nil - c.add_setting :template_dir, default: nil c.add_setting :config, default: nil c.add_setting :confdir, default: Puppet::Util::Platform.actually_windows? ? 'c:/nul/' : '/dev/null' c.add_setting :default_facts, default: {} @@ -47,9 +45,6 @@ def self.current_example c.add_setting :default_trusted_external_data, default: {} c.add_setting :facter_implementation, default: :facter c.add_setting :hiera_config, default: Puppet::Util::Platform.actually_windows? ? 'c:/nul/' : '/dev/null' - c.add_setting :parser, default: 'current' - c.add_setting :trusted_node_data, default: false - c.add_setting :ordering, default: 'title-hash' c.add_setting :stringify_facts, default: true c.add_setting :strict_variables, default: false c.add_setting :setup_fixtures, default: true @@ -63,17 +58,6 @@ def self.current_example c.add_setting :use_fixture_spec_hiera, default: false c.add_setting :fallback_to_default_hiera, default: true - c.instance_eval do - def trusted_server_facts - @trusted_server_facts.nil? ? false : @trusted_server_facts - end - - def trusted_server_facts=(value) - @trusted_server_facts = value - adapter&.setup_puppet(RSpec::Puppet.current_example) - end - end - c.before(:all) do RSpec::Puppet::Setup.safe_setup_directories(nil, false) if RSpec.configuration.setup_fixtures? end diff --git a/lib/rspec-puppet/adapters.rb b/lib/rspec-puppet/adapters.rb index 0cf9904d2..eb1128f41 100644 --- a/lib/rspec-puppet/adapters.rb +++ b/lib/rspec-puppet/adapters.rb @@ -12,12 +12,6 @@ class Base # executing RSpec context. When a setting is specified both in the global configuration and in # the example group, the setting in the example group is preferred. # - # @example Configuring a Puppet setting from a global RSpec configuration value - # RSpec.configure do |config| - # config.parser = "future" - # end - # # => Puppet[:parser] will be future - # # @example Configuring a Puppet setting from within an RSpec example group # RSpec.describe 'my_module::my_class', :type => :class do # let(:module_path) { "/Users/luke/modules" } @@ -42,6 +36,19 @@ class Base # @param example_group [RSpec::Core::ExampleGroup] The RSpec context to use for local settings # @return [void] def setup_puppet(example_group) + case RSpec.configuration.facter_implementation.to_sym + when :rspec + # Lazily instantiate FacterTestImpl here to optimize memory + # allocation, as the proc will only be called if FacterImpl is unset + set_facter_impl(proc { RSpec::Puppet::FacterTestImpl.new }) + when :facter + set_facter_impl(Facter) + else + raise "Unsupported facter_implementation '#{RSpec.configuration.facter_implementation}'" + end + + Puppet.runtime[:facter] = FacterImpl + settings = settings_map.map do |puppet_setting, rspec_setting| [puppet_setting, get_setting(example_group, rspec_setting)] end.flatten @@ -56,82 +63,14 @@ def setup_puppet(example_group) end end - if Puppet.settings.respond_to?(:initialize_app_defaults) - Puppet.settings.initialize_app_defaults(settings_hash) + Puppet.settings.initialize_app_defaults(settings_hash) - # Forcefully apply the environmentpath setting instead of relying on - # the application defaults as Puppet::Test::TestHelper automatically - # sets this value as well, overriding our application default - Puppet.settings[:environmentpath] = settings_hash[:environmentpath] if settings_hash.key?(:environmentpath) - else - # Set settings the old way for Puppet 2.x, because that's how - # they're defaulted in that version of Puppet::Test::TestHelper and - # we won't be able to override them otherwise. - settings_hash.each do |setting, value| - Puppet.settings[setting] = value - end - end + # Forcefully apply the environmentpath setting instead of relying on + # the application defaults as Puppet::Test::TestHelper automatically + # sets this value as well, overriding our application default + Puppet.settings[:environmentpath] = settings_hash[:environmentpath] if settings_hash.key?(:environmentpath) @environment_name = example_group.environment - end - - def get_setting(example_group, rspec_setting) - if example_group.respond_to?(rspec_setting) - example_group.send(rspec_setting) - else - RSpec.configuration.send(rspec_setting) - end - end - - def catalog(node, exported) - if exported - # Use the compiler directly to skip the filtering done by the indirector - Puppet::Parser::Compiler.compile(node).filter { |r| !r.exported? } - else - Puppet::Resource::Catalog.indirection.find(node.name, use_node: node) - end - end - - def current_environment - Puppet::Node::Environment.new(@environment_name) - end - - def settings_map - [ - %i[modulepath module_path], - %i[config config], - %i[confdir confdir] - ] - end - - def modulepath - Puppet[:modulepath].split(File::PATH_SEPARATOR) - end - - # @return [String, nil] The path to the Puppet manifest if it is present and set, nil otherwise. - def manifest - Puppet[:manifest] - end - end - - class Adapter40 < Base - # - # @api private - # - # Set the FacterImpl constant to the given Facter implementation or noop - # if the constant is already set. If a proc is given, it will only be - # called if FacterImpl is not defined. - # - # @param impl [Object, Proc] An object or a proc that implements the Facter API - def set_facter_impl(impl) - return if defined?(FacterImpl) - - impl = impl.call if impl.is_a?(Proc) - Object.send(:const_set, :FacterImpl, impl) - end - - def setup_puppet(example_group) - super modulepath = if (rspec_modulepath = RSpec.configuration.module_path) rspec_modulepath.split(File::PATH_SEPARATOR) @@ -141,20 +80,16 @@ def setup_puppet(example_group) end end - if (rspec_manifest = RSpec.configuration.manifest) - manifest = rspec_manifest - else - manifest_paths = Puppet[:environmentpath].split(File::PATH_SEPARATOR).map do |path| - File.join(path, 'fixtures', 'manifests') - end - - manifest = manifest_paths.find do |path| - File.exist?(path) - end + manifest_paths = Puppet[:environmentpath].split(File::PATH_SEPARATOR).map do |path| + File.join(path, 'fixtures', 'manifests') + end - manifest ||= Puppet::Node::Environment::NO_MANIFEST + manifest = manifest_paths.find do |path| + File.exist?(path) end + manifest ||= Puppet::Node::Environment::NO_MANIFEST + env = Puppet::Node::Environment.create(@environment_name, modulepath, manifest) loader = Puppet::Environments::Static.new(env) @@ -168,13 +103,12 @@ def setup_puppet(example_group) ) end - def settings_map - super.push( - %i[environmentpath environmentpath], - %i[hiera_config hiera_config], - %i[strict_variables strict_variables], - %i[manifest manifest] - ) + def get_setting(example_group, rspec_setting) + if example_group.respond_to?(rspec_setting) + example_group.send(rspec_setting) + else + RSpec.configuration.send(rspec_setting) + end end def catalog(node, exported) @@ -182,10 +116,36 @@ def catalog(node, exported) # Override $::environment to workaround PUP-5835, where Puppet otherwise # stores a symbol for the parameter if node.parameters['environment'] != node.parameters['environment'].to_s - node.parameters['environment'] = - current_environment.name.to_s + node.parameters['environment'] = current_environment.name.to_s end - super + + catalog = if exported + # Use the compiler directly to skip the filtering done by the indirector + Puppet::Parser::Compiler.compile(node).filter { |r| !r.exported? } + else + Puppet::Resource::Catalog.indirection.find(node.name, use_node: node) + end + + Puppet::Pops::Evaluator::DeferredResolver.resolve_and_replace(node.facts, catalog) + + catalog + end + + def current_environment + Puppet::Node::Environment.new(@environment_name) + end + + def settings_map + [ + %i[modulepath module_path], + %i[basemodulepath basemodulepath], + %i[config config], + %i[confdir confdir], + %i[environmentpath environmentpath], + %i[hiera_config hiera_config], + %i[strict_variables strict_variables], + %i[vendormoduledir vendormoduledir] + ] end def current_environment @@ -196,9 +156,6 @@ def modulepath current_environment.modulepath end - # Puppet 4.0 specially handles environments that don't have a manifest set, so we check for the no manifest value - # and return nil when it is set. - # # @return [String, nil] The path to the Puppet manifest if it is present and set, nil otherwise. def manifest m = current_environment.manifest @@ -208,144 +165,25 @@ def manifest m end end - end - - class Adapter4X < Adapter40 - def setup_puppet(example_group) - super - - set_facter_impl(Facter) - end - - def settings_map - super.push( - %i[trusted_server_facts trusted_server_facts] - ) - end - end - class Adapter6X < Adapter40 - # # @api private # - # Check to see if Facter runtime implementations are supported in the - # current Puppet version + # Set the FacterImpl constant to the given Facter implementation or noop + # if the constant is already set. If a proc is given, it will only be + # called if FacterImpl is not defined. # - # @return [Boolean] true if runtime implementations are supported - def supports_facter_runtime? - unless defined?(@supports_facter_runtime) - begin - Puppet.runtime[:facter] - @supports_facter_runtime = true - rescue StandardError - @supports_facter_runtime = false - end - end - - @supports_facter_runtime - end - - def setup_puppet(example_group) - case RSpec.configuration.facter_implementation.to_sym - when :rspec - if supports_facter_runtime? - # Lazily instantiate FacterTestImpl here to optimize memory - # allocation, as the proc will only be called if FacterImpl is unset - set_facter_impl(proc { RSpec::Puppet::FacterTestImpl.new }) - Puppet.runtime[:facter] = FacterImpl - else - warn "Facter runtime implementations are not supported in Puppet #{Puppet.version}, continuing with facter_implementation 'facter'" - RSpec.configuration.facter_implementation = :facter - set_facter_impl(Facter) - end - when :facter - set_facter_impl(Facter) - else - raise "Unsupported facter_implementation '#{RSpec.configuration.facter_implementation}'" - end - - super - end - - def settings_map - super.push( - %i[basemodulepath basemodulepath], - %i[vendormoduledir vendormoduledir] - ) - end - - def catalog(node, _exported) - super.tap do |c| - Puppet::Pops::Evaluator::DeferredResolver.resolve_and_replace(node.facts, c) - end - end - end - - class Adapter30 < Base - def settings_map - super.push( - %i[manifestdir manifest_dir], - %i[manifest manifest], - %i[templatedir template_dir], - %i[hiera_config hiera_config] - ) - end - end - - class Adapter32 < Adapter30 - def settings_map - super.push( - %i[parser parser] - ) - end - end - - class Adapter33 < Adapter32 - def settings_map - super.push( - %i[ordering ordering], - %i[stringify_facts stringify_facts] - ) - end - end - - class Adapter34 < Adapter33 - def settings_map - super.push( - %i[trusted_node_data trusted_node_data] - ) - end - end - - class Adapter35 < Adapter34 - def settings_map - super.push( - %i[strict_variables strict_variables] - ) - end - end + # @param impl [Object, Proc] An object or a proc that implements the Facter API + def set_facter_impl(impl) + return if defined?(FacterImpl) - class Adapter27 < Base - def settings_map - super.push( - %i[manifestdir manifest_dir], - %i[manifest manifest], - %i[templatedir template_dir] - ) + impl = impl.call if impl.is_a?(Proc) + Object.send(:const_set, :FacterImpl, impl) end end def self.get [ - ['6.0', Adapter6X], - ['4.1', Adapter4X], - ['4.0', Adapter40], - ['3.5', Adapter35], - ['3.4', Adapter34], - ['3.3', Adapter33], - ['3.2', Adapter32], - ['3.0', Adapter30], - ['2.7', Adapter27] + ['7.11', Base] ].each do |(version, klass)| return klass.new if Puppet::Util::Package.versioncmp(Puppet.version, version) >= 0 end diff --git a/lib/rspec-puppet/monkey_patches.rb b/lib/rspec-puppet/monkey_patches.rb index dc307ca9b..e46490f77 100644 --- a/lib/rspec-puppet/monkey_patches.rb +++ b/lib/rspec-puppet/monkey_patches.rb @@ -11,16 +11,11 @@ class RSpec::Puppet::EventListener def self.example_started(example) - if rspec3? - @rspec_puppet_example = example.example.example_group.ancestors.include?(RSpec::Puppet::Support) - @current_example = example.example - if !@current_example.respond_to?(:environment) && @current_example.respond_to?(:example_group_instance) - @current_example = @current_example.example_group_instance - end - else - @rspec_puppet_example = example.example_group.ancestors.include?(RSpec::Puppet::Support) - @current_example = example - end + @rspec_puppet_example = example.example.example_group.ancestors.include?(RSpec::Puppet::Support) + @current_example = example.example + return unless !@current_example.respond_to?(:environment) && @current_example.respond_to?(:example_group_instance) + + @current_example = @current_example.example_group_instance end def self.example_passed(_example) diff --git a/lib/rspec-puppet/sensitive.rb b/lib/rspec-puppet/sensitive.rb index dd942b088..c35962b37 100644 --- a/lib/rspec-puppet/sensitive.rb +++ b/lib/rspec-puppet/sensitive.rb @@ -1,53 +1,43 @@ # frozen_string_literal: true module RSpec::Puppet - if defined?(::Puppet::Pops::Types::PSensitiveType::Sensitive) - # A wrapper representing Sensitive data type, eg. in class params. - class Sensitive < ::Puppet::Pops::Types::PSensitiveType::Sensitive - # Create a new Sensitive object - # @param [Object] value to wrap - def initialize(value) - @value = value - end + # A wrapper representing Sensitive data type, eg. in class params. + class Sensitive < ::Puppet::Pops::Types::PSensitiveType::Sensitive + # Create a new Sensitive object + # @param [Object] value to wrap + def initialize(value) + @value = value + end - # @return the wrapped value - def unwrap - @value - end + # @return the wrapped value + def unwrap + @value + end - # @return true - def sensitive? - true - end + # @return true + def sensitive? + true + end - # @return inspect of the wrapped value, inside Sensitive() - def inspect - "Sensitive(#{@value.inspect})" - end + # @return inspect of the wrapped value, inside Sensitive() + def inspect + "Sensitive(#{@value.inspect})" + end - # Check for equality with another value. - # If compared to Puppet Sensitive type, it compares the wrapped values. + # Check for equality with another value. + # If compared to Puppet Sensitive type, it compares the wrapped values. - # @param other [#unwrap, Object] value to compare to - def ==(other) - if other.respond_to? :unwrap - if unwrap.is_a?(Regexp) - unwrap =~ other.unwrap - else - unwrap == other.unwrap - end + # @param other [#unwrap, Object] value to compare to + def ==(other) + if other.respond_to? :unwrap + if unwrap.is_a?(Regexp) + unwrap =~ other.unwrap else - super + unwrap == other.unwrap end + else + super end end - else - # :nocov: - class Sensitive - def initialize(_value) - raise 'The use of the Sensitive data type is not supported by this Puppet version' - end - end - # :nocov: end end diff --git a/lib/rspec-puppet/setup.rb b/lib/rspec-puppet/setup.rb index f70e9f5bf..f11985830 100644 --- a/lib/rspec-puppet/setup.rb +++ b/lib/rspec-puppet/setup.rb @@ -91,8 +91,6 @@ def self.get_module_name end def self.get_module_name_from_file(file) - # FIXME: see discussion at - # https://github.com/rodjek/rspec-puppet/issues/290 require 'puppet/pops' p = Puppet::Pops::Parser::Lexer2.new module_name = nil diff --git a/lib/rspec-puppet/spec_helper.rb b/lib/rspec-puppet/spec_helper.rb index 541391ecc..5f32a01c7 100644 --- a/lib/rspec-puppet/spec_helper.rb +++ b/lib/rspec-puppet/spec_helper.rb @@ -2,11 +2,8 @@ require 'rspec-puppet' -fixture_path = File.join(File.dirname(File.expand_path(__FILE__)), 'fixtures') - RSpec.configure do |c| - c.module_path = File.join(fixture_path, 'modules') - c.manifest_dir = File.join(fixture_path, 'manifests') - c.manifest = File.join(fixture_path, 'manifests', 'site.pp') - c.environmentpath = File.join(Dir.pwd, 'spec') + c.module_path = File.join(__dir__, 'fixtures', 'modules') + c.manifest = File.join(fixture_path, 'manifests', 'site.pp') + c.environmentpath = __dir__ end diff --git a/lib/rspec-puppet/support.rb b/lib/rspec-puppet/support.rb index ac1964ca1..bb8201a50 100644 --- a/lib/rspec-puppet/support.rb +++ b/lib/rspec-puppet/support.rb @@ -84,7 +84,6 @@ def load_catalogue(type, exported = false, manifest_opts = {}) hiera_data_value = respond_to?(:hiera_data) ? hiera_data : nil rspec_config_values = %i[ - trusted_server_facts disable_module_hiera use_fixture_spec_hiera fixture_hiera_configs @@ -122,30 +121,6 @@ def load_catalogue(type, exported = false, manifest_opts = {}) end end - def import_str - import_str = '' - adapter.modulepath.each do |d| - if File.exist?(File.join(d, 'manifests', 'init.pp')) - path_to_manifest = File.join([ - d, - 'manifests', - class_name.split('::')[1..] - ].flatten) - import_str = [ - "import '#{d}/manifests/init.pp'", - "import '#{path_to_manifest}.pp'", - '' - ].join("\n") - break - elsif File.exist?(d) - import_str = "import '#{adapter.manifest}'\n" - break - end - end - - import_str - end - def site_pp_str return '' unless (path = adapter.manifest) @@ -328,7 +303,7 @@ def server_facts_hash # And then add the server name and IP { 'servername' => 'fqdn', 'serverip' => 'ipaddress' }.each do |var, fact| - if (value = FacterImpl.value(fact)) + if (value = Puppet.runtime[:facter].value(fact)) server_facts[var] = value else warn "Could not retrieve fact #{fact}" @@ -336,8 +311,8 @@ def server_facts_hash end if server_facts['servername'].nil? - host = FacterImpl.value(:hostname) - server_facts['servername'] = if (domain = FacterImpl.value(:domain)) + host = Puppet.runtime[:facter].value(:hostname) + server_facts['servername'] = if (domain = Puppet.runtime[:facter].value(:domain)) [host, domain].join('.') else host @@ -452,15 +427,15 @@ def build_catalog_without_cache_v2( 'Context for spec trusted hash' ) - node_obj.add_server_facts(server_facts_hash) if RSpec.configuration.trusted_server_facts + node_obj.add_server_facts(server_facts_hash) adapter.catalog(node_obj, exported) end def stub_facts!(facts) Puppet.settings[:autosign] = false if Puppet.settings.include? :autosign - FacterImpl.clear - facts.each { |k, v| FacterImpl.add(k, weight: 999) { setcode { v } } } + Puppet.runtime[:facter].clear + facts.each { |k, v| Puppet.runtime[:facter].add(k, weight: 999) { setcode { v } } } end def build_catalog(*args) diff --git a/spec/classes/array_spec.rb b/spec/classes/array_spec.rb index 237eef398..a8ec22b75 100644 --- a/spec/classes/array_spec.rb +++ b/spec/classes/array_spec.rb @@ -38,18 +38,16 @@ ] } end - describe 'on Puppet 2.7 and later' do - it { - expect(subject).to contain_structured_data__def('thing').with( - { 'data' => [ - 'first', - 'second', - %w[third fourth], - 5, - 6 - ] } - ) - } - end + it { + expect(subject).to contain_structured_data__def('thing').with( + { 'data' => [ + 'first', + 'second', + %w[third fourth], + 5, + 6 + ] } + ) + } end end diff --git a/spec/classes/hash_spec.rb b/spec/classes/hash_spec.rb index ccbf89e52..464e09ab5 100644 --- a/spec/classes/hash_spec.rb +++ b/spec/classes/hash_spec.rb @@ -20,13 +20,11 @@ { 'data' => { 1 => 'uno', 2 => 'dos' } } end - context 'puppet 4 or greater' do - it { - expect(subject).to contain_structured_data__def('thing').with( - { 'data' => { 1 => 'uno', 2 => 'dos' } } - ) - } - end + it { + expect(subject).to contain_structured_data__def('thing').with( + { 'data' => { 1 => 'uno', 2 => 'dos' } } + ) + } end describe 'with integers as values' do diff --git a/spec/classes/hiera_integration_spec.rb b/spec/classes/hiera_integration_spec.rb index 2c6b8a7a6..0b5eaf341 100644 --- a/spec/classes/hiera_integration_spec.rb +++ b/spec/classes/hiera_integration_spec.rb @@ -2,7 +2,6 @@ require 'spec_helper' -# hiera is not supported before 2.7 describe 'test::hiera' do context 'with :hiera_config set' do let(:hiera_config) { 'spec/fixtures/hiera.yaml' } diff --git a/spec/classes/server_facts_spec.rb b/spec/classes/server_facts_spec.rb index ccf92496c..a41f3d697 100644 --- a/spec/classes/server_facts_spec.rb +++ b/spec/classes/server_facts_spec.rb @@ -3,17 +3,12 @@ require 'spec_helper' describe 'server_facts' do - context 'with server_facts' do - before do - RSpec.configuration.trusted_server_facts = true - end - - let(:facts) do - { - ipaddress: '192.168.1.10' - } - end - let(:node) { 'test123.test.com' } + let(:facts) do + { + ipaddress: '192.168.1.10' + } + end + let(:node) { 'test123.test.com' } it { is_expected.to contain_class('server_facts') } it { is_expected.to compile.with_all_deps } diff --git a/spec/functions/nil_function_spec.rb b/spec/functions/nil_function_spec.rb index dfd07a605..3f796b4ec 100644 --- a/spec/functions/nil_function_spec.rb +++ b/spec/functions/nil_function_spec.rb @@ -3,10 +3,6 @@ require 'spec_helper' describe 'nil_function' do - let(:version) { 'new version' } - it { is_expected.to run.with_params(false).and_return(nil) } - it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, /Forced Failure/) } - - it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, /Forced Failure - #{version}/) } + it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, /Forced Failure - new version/) } end diff --git a/spec/functions/split_spec.rb b/spec/functions/split_spec.rb index 170d97aa9..1e495610c 100644 --- a/spec/functions/split_spec.rb +++ b/spec/functions/split_spec.rb @@ -6,7 +6,9 @@ it { is_expected.to run.with_params('aoeu', 'o').and_return(%w[a eu]) } it { is_expected.not_to run.with_params('foo').and_raise_error(Puppet::DevError) } - it { is_expected.to run.with_params('foo').and_raise_error(ArgumentError) } + expected_error = ArgumentError + + it { is_expected.to run.with_params('foo').and_raise_error(expected_error) } it { is_expected.to run.with_params('foo').and_raise_error(ArgumentError, /expects \d+ arguments/) } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6062a0b5d..060766c66 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -22,28 +22,12 @@ def windows? @windowsp = defined?(RSpec::Support) ? RSpec::Support::OS.windows? : !!File::ALT_SEPARATOR end -def sensitive? - defined?(Puppet::Pops::Types::PSensitiveType) -end - -module Helpers - def rspec2? - RSpec::Version::STRING < '3' - end - module_function :rspec2? -end - RSpec.configure do |c| c.module_path = File.join(File.dirname(File.expand_path(__FILE__)), 'fixtures', 'modules') - c.manifest_dir = File.join(File.dirname(File.expand_path(__FILE__)), 'fixtures', 'manifests') - c.manifest = File.join(File.dirname(File.expand_path(__FILE__)), 'fixtures', 'manifests', 'site.pp') c.environmentpath = File.join(Dir.pwd, 'spec') - c.parser = ENV['FUTURE_PARSER'] == 'yes' ? 'future' : 'current' + c.manifest = File.join(File.dirname(File.expand_path(__FILE__)), 'fixtures', 'manifests', 'site.pp') c.after(:suite) do RSpec::Puppet::Coverage.report!(0) end - - c.include Helpers - c.extend Helpers end diff --git a/spec/support_spec.rb b/spec/support_spec.rb index e7ef2d6c2..94576da75 100644 --- a/spec/support_spec.rb +++ b/spec/support_spec.rb @@ -36,18 +36,10 @@ end describe '#sensitive' do - context 'when using a version of Puppet that supports the Sensitive type', if: sensitive? do - it 'returns a new Sensitive with the given contents' do - sens = subject.sensitive('test content') - expect(sens).to be_sensitive - expect(sens.unwrap).to eq 'test content' - end - end - - context 'when using a version of Puppet that does not support Sensitive', unless: sensitive? do - it 'raises an error' do - expect { subject.sensitive('test content') }.to raise_error - end + it 'returns a new Sensitive with the given contents' do + sens = subject.sensitive('test content') + expect(sens).to be_sensitive + expect(sens.unwrap).to eq 'test content' end end @@ -143,10 +135,6 @@ def class_name def site_pp_str '' end - - def import_str - '' - end end end diff --git a/spec/unit/adapters_spec.rb b/spec/unit/adapters_spec.rb index 5a8ba2b1b..47571058c 100644 --- a/spec/unit/adapters_spec.rb +++ b/spec/unit/adapters_spec.rb @@ -24,13 +24,30 @@ def context_double(options = {}) null_path = windows? ? 'c:/nul/' : '/dev/null' - %i[vardir confdir].each do |setting| + %i[vardir codedir rundir logdir hiera_config confdir].each do |setting| it "sets #{setting} to #{null_path}" do expect(Puppet[setting]).to eq(File.expand_path(null_path)) end end end + it 'sets Puppet[:strict_variables] to false by default' do + subject.setup_puppet(test_context) + expect(Puppet[:strict_variables]).to be(false) + end + + it 'reads the :strict_variables setting' do + allow(test_context).to receive(:strict_variables).and_return(true) + subject.setup_puppet(test_context) + expect(Puppet[:strict_variables]).to be(true) + end + + it 'overrides the environmentpath set by Puppet::Test::TestHelper' do + allow(test_context).to receive(:environmentpath).and_return('/path/to/my/environments') + subject.setup_puppet(test_context) + expect(Puppet[:environmentpath]).to match(%r{(C:)?/path/to/my/environments}) + end + describe '#set_setting' do describe 'with a context specific setting' do it 'sets the Puppet setting based on the example group setting' do @@ -77,124 +94,6 @@ def context_double(options = {}) end end end -end - -describe RSpec::Puppet::Adapters::Adapter35, if: (3.5...4.0).cover?(Puppet.version.to_f) do - let(:test_context) { double environment: 'rp_env' } - - context 'when running on puppet 3.5 or later', if: (3.5...4.0).cover?(Puppet.version.to_f) do - it 'sets Puppet[:strict_variables] to false by default' do - subject.setup_puppet(test_context) - expect(Puppet[:strict_variables]).to be(false) - end - - it 'reads the :strict_variables setting' do - allow(test_context).to receive(:strict_variables).and_return true - subject.setup_puppet(test_context) - expect(Puppet[:strict_variables]).to be(true) - end - end -end - -describe RSpec::Puppet::Adapters::Adapter34, if: (3.4...4.0).cover?(Puppet.version.to_f) do - let(:test_context) { double environment: 'rp_env' } - - context 'when running on puppet 3.4 or later', if: (3.4...4.0).cover?(Puppet.version.to_f) do - it 'sets Puppet[:trusted_node_data] to false by default' do - subject.setup_puppet(test_context) - expect(Puppet[:trusted_node_data]).to be(false) - end - - it 'reads the :trusted_node_data setting' do - allow(test_context).to receive(:trusted_node_data).and_return(true) - subject.setup_puppet(test_context) - expect(Puppet[:trusted_node_data]).to be(true) - end - end -end - -describe RSpec::Puppet::Adapters::Adapter33, if: (3.3...4.0).cover?(Puppet.version.to_f) do - let(:test_context) { double environment: 'rp_env' } - - context 'when running on puppet ~> 3.3', if: (3.3...4.0).cover?(Puppet.version.to_f) do - it 'sets Puppet[:stringify_facts] to true by default' do - subject.setup_puppet(test_context) - expect(Puppet[:stringify_facts]).to be(true) - end - - it 'reads the :stringify_facts setting' do - allow(test_context).to receive(:stringify_facts).and_return false - subject.setup_puppet(test_context) - expect(Puppet[:stringify_facts]).to be(false) - end - - it 'sets Puppet[:ordering] to title-hash by default' do - subject.setup_puppet(test_context) - expect(Puppet[:ordering]).to eq('title-hash') - end - - it 'reads the :ordering setting' do - allow(test_context).to receive(:ordering).and_return('manifest') - subject.setup_puppet(test_context) - expect(Puppet[:ordering]).to eq('manifest') - end - end -end - -describe RSpec::Puppet::Adapters::Adapter32, if: (3.2...4.0).cover?(Puppet.version.to_f) do - let(:test_context) { double environment: 'rp_env' } - - context 'when running on puppet ~> 3.2', if: (3.2...4.0).cover?(Puppet.version.to_f) do - it 'sets Puppet[:parser] to "current" by default' do - subject.setup_puppet(test_context) - expect(Puppet[:parser]).to eq('current') - end - - it 'reads the :parser setting' do - allow(test_context).to receive(:parser).and_return('future') - subject.setup_puppet(test_context) - expect(Puppet[:parser]).to eq('future') - end - end - - describe 'default settings' do - before do - subject.setup_puppet(context_double) - end - - null_path = windows? ? 'c:/nul/' : '/dev/null' - - %i[vardir rundir logdir hiera_config confdir].each do |setting| - it "sets #{setting} to #{null_path}" do - expect(Puppet[setting]).to eq(File.expand_path(null_path)) - end - end - end -end - -describe RSpec::Puppet::Adapters::Adapter6X, if: (6.0...6.25).cover?(Puppet.version.to_f) do - let(:test_context) { double environment: 'rp_env' } - - describe '#setup_puppet' do - describe 'when managing the facter_implementation' do - after do - Object.send(:remove_const, :FacterImpl) if defined? FacterImpl - end - - it 'warns and falls back if hash implementation is set and facter runtime is not supported' do - context = context_double - allow(RSpec.configuration).to receive(:facter_implementation).and_return('rspec') - expect(subject).to receive(:warn) - .with("Facter runtime implementations are not supported in Puppet #{Puppet.version}, continuing with facter_implementation 'facter'") - subject.setup_puppet(context) - expect(FacterImpl).to be(Facter) - end - end - end -end - -describe RSpec::Puppet::Adapters::Adapter6X, if: Puppet::Util::Package.versioncmp(Puppet.version, '6.25.0') >= 0 do - let(:test_context) { double environment: 'rp_env' } describe '#setup_puppet' do describe 'when managing the facter_implementation' do @@ -237,53 +136,3 @@ def context_double(options = {}) end end end - -describe RSpec::Puppet::Adapters::Adapter4X, if: (4.0...6.0).cover?(Puppet.version.to_f) do - let(:test_context) { double environment: 'rp_env' } - - it 'sets Puppet[:strict_variables] to false by default' do - subject.setup_puppet(test_context) - expect(Puppet[:strict_variables]).to be(false) - end - - it 'reads the :strict_variables setting' do - allow(test_context).to receive(:strict_variables).and_return(true) - subject.setup_puppet(test_context) - expect(Puppet[:strict_variables]).to be(true) - end - - it 'overrides the environmentpath set by Puppet::Test::TestHelper' do - allow(test_context).to receive(:environmentpath).and_return('/path/to/my/environments') - subject.setup_puppet(test_context) - expect(Puppet[:environmentpath]).to match(%r{(C:)?/path/to/my/environments}) - end - - describe '#manifest' do - it 'returns the configured environment manifest when set' do - allow(RSpec.configuration).to receive(:manifest).and_return('/path/to/manifest') - subject.setup_puppet(double(environment: 'rp_puppet')) - expect(subject.manifest).to match(%r{(C:)?/path/to/manifest}) - end - - it 'returns nil when the configured environment manifest is not set' do - allow(RSpec.configuration).to receive(:manifest) - allow(RSpec.configuration).to receive(:environmentpath).and_return('/some/missing/path:/another/missing/path') - subject.setup_puppet(double(environment: 'rp_puppet')) - expect(subject.manifest).to be_nil - end - end - - describe 'default settings' do - before do - subject.setup_puppet(context_double) - end - - null_path = windows? ? 'c:/nul/' : '/dev/null' - - %i[vardir codedir rundir logdir hiera_config confdir].each do |setting| - it "sets #{setting} to #{null_path}" do - expect(Puppet[setting]).to eq(File.expand_path(null_path)) - end - end - end -end diff --git a/spec/unit/matchers/compile_spec.rb b/spec/unit/matchers/compile_spec.rb index 7cfd49537..a2ddebe69 100644 --- a/spec/unit/matchers/compile_spec.rb +++ b/spec/unit/matchers/compile_spec.rb @@ -172,9 +172,8 @@ context 'when expecting the failure' do let(:expected_error) do - "Evaluation Error: Error while evaluating a Function Call, #{error_detail} on node rspec::puppet::manifestmatchers::compile" + "Evaluation Error: Error while evaluating a Function Call, 'failure (line: 52, column: 1)' on node rspec::puppet::manifestmatchers::compile" end - let(:error_detail) { 'failure (line: 52, column: 1)' } before { subject.and_raise_error(expected_error) } diff --git a/spec/unit/monkey_patches_spec.rb b/spec/unit/monkey_patches_spec.rb index e566a5e46..4fdffd31c 100644 --- a/spec/unit/monkey_patches_spec.rb +++ b/spec/unit/monkey_patches_spec.rb @@ -133,19 +133,11 @@ describe 'Puppet::Module#match_manifests' do subject do - if Puppet::Module.instance_method(:initialize).arity == -2 - Puppet::Module.new( - 'escape', - path: File.join(RSpec.configuration.module_path, 'escape'), - environment: 'production' - ) - else - Puppet::Module.new( - 'escape', - File.join(RSpec.configuration.module_path, 'escape'), - 'production' - ) - end + Puppet::Module.new( + 'escape', + File.join(RSpec.configuration.module_path, 'escape'), + 'production' + ) end it 'returns init.pp for top level class' do diff --git a/spec/unit/sensitive_spec.rb b/spec/unit/sensitive_spec.rb index 117e75b44..ae77aa608 100644 --- a/spec/unit/sensitive_spec.rb +++ b/spec/unit/sensitive_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require 'rspec-puppet/sensitive' -describe RSpec::Puppet::Sensitive, if: sensitive? do +describe RSpec::Puppet::Sensitive do subject(:sensitive) { described_class.new contents } let(:contents) { double :contents }