diff --git a/lib/rspec-puppet/adapters.rb b/lib/rspec-puppet/adapters.rb index d2f9d711f..32753e14c 100644 --- a/lib/rspec-puppet/adapters.rb +++ b/lib/rspec-puppet/adapters.rb @@ -162,7 +162,7 @@ def setup_puppet(example_group) { environments: loader, current_environment: env, - loaders: (Puppet::Pops::Loaders.new(env) if Gem::Version.new(Puppet.version) >= Gem::Version.new('6.0.0')) + loaders: (Puppet::Pops::Loaders.new(env)) }, 'Setup rspec-puppet environments' ) diff --git a/lib/rspec-puppet/example/function_example_group.rb b/lib/rspec-puppet/example/function_example_group.rb index c94bc0445..577534a96 100644 --- a/lib/rspec-puppet/example/function_example_group.rb +++ b/lib/rspec-puppet/example/function_example_group.rb @@ -88,19 +88,17 @@ def find_function(function_name = self.class.top_level_description) with_vardir do env = adapter.current_environment - if Puppet.version.to_f >= 4.0 - context_overrides = compiler.context_overrides - func = nil - loaders = Puppet.lookup(:loaders) - Puppet.override(context_overrides, 'rspec-test scope') do - func = V4FunctionWrapper.new(function_name, - loaders.private_environment_loader.load(:function, function_name), context_overrides) - @scope = context_overrides[:global_scope] - end - - return func if func.func + context_overrides = compiler.context_overrides + func = nil + loaders = Puppet.lookup(:loaders) + Puppet.override(context_overrides, 'rspec-test scope') do + func = V4FunctionWrapper.new(function_name, + loaders.private_environment_loader.load(:function, function_name), context_overrides) + @scope = context_overrides[:global_scope] end + return func if func.func + if Puppet::Parser::Functions.function(function_name) V3FunctionWrapper.new(function_name, scope.method("function_#{function_name}".intern)) end @@ -157,46 +155,28 @@ def build_compiler node = build_node(node_name, node_options) - if Puppet::Util::Package.versioncmp(Puppet.version, '4.3.0') >= 0 - Puppet.push_context( - { - trusted_information: Puppet::Context::TrustedInformation.new('remote', node_name, trusted_values) - }, - 'Context for spec trusted hash' - ) - end + Puppet.push_context( + { + trusted_information: Puppet::Context::TrustedInformation.new('remote', node_name, trusted_values) + }, + 'Context for spec trusted hash' + ) compiler = Puppet::Parser::Compiler.new(node) compiler.compile - if Puppet::Util::Package.versioncmp(Puppet.version, '4.0.0') >= 0 - loaders = Puppet::Pops::Loaders.new(adapter.current_environment) - Puppet.push_context( - { - loaders: loaders, - global_scope: compiler.context_overrides[:global_scope] - }, - 'set globals' - ) - end + loaders = Puppet::Pops::Loaders.new(adapter.current_environment) + Puppet.push_context( + { + loaders: loaders, + global_scope: compiler.context_overrides[:global_scope] + }, + 'set globals' + ) compiler end def build_scope(compiler, node_name) - if Puppet.version.to_f >= 4.0 - return compiler.context_overrides[:global_scope] - elsif /^2\.[67]/.match?(Puppet.version) - # loadall should only be necessary prior to 3.x - # Please note, loadall needs to happen first when creating a scope, otherwise - # you might receive undefined method `function_*' errors - Puppet::Parser::Functions.autoloader.loadall - scope = Puppet::Parser::Scope.new(compiler: compiler) - else - scope = Puppet::Parser::Scope.new(compiler) - end - - scope.source = Puppet::Resource::Type.new(:node, node_name) - scope.parent = compiler.topscope - scope + compiler.context_overrides[:global_scope] end def build_node(name, opts = {}) diff --git a/lib/rspec-puppet/monkey_patches.rb b/lib/rspec-puppet/monkey_patches.rb index 8b67a4107..065891d8e 100644 --- a/lib/rspec-puppet/monkey_patches.rb +++ b/lib/rspec-puppet/monkey_patches.rb @@ -267,42 +267,40 @@ class Provider::Confine::Exists < Puppet::Provider::Confine end end - if Puppet::Util::Package.versioncmp(Puppet.version, '4.9.0') >= 0 - class Module - old_hiera_conf_file = instance_method(:hiera_conf_file) - define_method(:hiera_conf_file) do - if RSpec::Puppet.rspec_puppet_example? - if RSpec.configuration.disable_module_hiera - return nil - elsif RSpec.configuration.fixture_hiera_configs.key?(name) - config = RSpec.configuration.fixture_hiera_configs[name] - config = File.absolute_path(config, path) unless config.nil? - return config - elsif RSpec.configuration.use_fixture_spec_hiera - config = RSpec::Puppet.current_example.fixture_spec_hiera_conf(self) - return config unless config.nil? && RSpec.configuration.fallback_to_default_hiera - end + class Module + old_hiera_conf_file = instance_method(:hiera_conf_file) + define_method(:hiera_conf_file) do + if RSpec::Puppet.rspec_puppet_example? + if RSpec.configuration.disable_module_hiera + return nil + elsif RSpec.configuration.fixture_hiera_configs.key?(name) + config = RSpec.configuration.fixture_hiera_configs[name] + config = File.absolute_path(config, path) unless config.nil? + return config + elsif RSpec.configuration.use_fixture_spec_hiera + config = RSpec::Puppet.current_example.fixture_spec_hiera_conf(self) + return config unless config.nil? && RSpec.configuration.fallback_to_default_hiera end - old_hiera_conf_file.bind_call(self) end + old_hiera_conf_file.bind_call(self) end + end - class Pops::Lookup::ModuleDataProvider - old_configuration_path = instance_method(:configuration_path) - define_method(:configuration_path) do |lookup_invocation| - if RSpec::Puppet.rspec_puppet_example? - env = lookup_invocation.scope.environment - mod = env.module(module_name) - unless mod - raise Puppet::DataBinding::LookupError, - format(_("Environment '%s', cannot find module '%s'"), env: env.name, - module_name: module_name) - end - - return Pathname.new(mod.hiera_conf_file) + class Pops::Lookup::ModuleDataProvider + old_configuration_path = instance_method(:configuration_path) + define_method(:configuration_path) do |lookup_invocation| + if RSpec::Puppet.rspec_puppet_example? + env = lookup_invocation.scope.environment + mod = env.module(module_name) + unless mod + raise Puppet::DataBinding::LookupError, + format(_("Environment '%s', cannot find module '%s'"), env: env.name, + module_name: module_name) end - old_configuration_path.bind_call(self, lookup_invocation) + + return Pathname.new(mod.hiera_conf_file) end + old_configuration_path.bind_call(self, lookup_invocation) end end end diff --git a/lib/rspec-puppet/setup.rb b/lib/rspec-puppet/setup.rb index 138899eb9..f70e9f5bf 100644 --- a/lib/rspec-puppet/setup.rb +++ b/lib/rspec-puppet/setup.rb @@ -93,12 +93,8 @@ def self.get_module_name def self.get_module_name_from_file(file) # FIXME: see discussion at # https://github.com/rodjek/rspec-puppet/issues/290 - if Puppet.version.to_f >= 4.0 || RSpec.configuration.parser == 'future' - require 'puppet/pops' - p = Puppet::Pops::Parser::Lexer2.new - else - p = Puppet::Parser::Lexer.new - end + require 'puppet/pops' + p = Puppet::Pops::Parser::Lexer2.new module_name = nil p.string = File.read(file) tokens = p.fullscan diff --git a/lib/rspec-puppet/support.rb b/lib/rspec-puppet/support.rb index cc42639e5..ac1964ca1 100644 --- a/lib/rspec-puppet/support.rb +++ b/lib/rspec-puppet/support.rb @@ -21,11 +21,7 @@ def environment end def build_code(type, manifest_opts) - if (Puppet.version.to_f >= 4.0) || (Puppet[:parser] == 'future') - [site_pp_str, pre_cond, test_manifest(type, manifest_opts), post_cond].compact.join("\n") - else - [import_str, pre_cond, test_manifest(type, manifest_opts), post_cond].compact.join("\n") - end + [site_pp_str, pre_cond, test_manifest(type, manifest_opts), post_cond].compact.join("\n") end def guess_type_from_path(path) @@ -302,8 +298,6 @@ def param_str(params) end def trusted_facts_hash(_node_name) - return {} unless Puppet::Util::Package.versioncmp(Puppet.version, '4.3.0') >= 0 - extensions = {} if RSpec.configuration.default_trusted_facts.any? @@ -315,8 +309,6 @@ def trusted_facts_hash(_node_name) end def trusted_external_data_hash - return {} unless Puppet::Util::Package.versioncmp(Puppet.version, '6.14.0') >= 0 - external_data = {} if RSpec.configuration.default_trusted_external_data.any? @@ -389,11 +381,6 @@ def setup_puppet vardir = Dir.mktmpdir Puppet[:vardir] = vardir - # Enable app_management by default for Puppet versions that support it - if Puppet::Util::Package.versioncmp(Puppet.version, '4.3.0') >= 0 && Puppet.version.to_i < 5 - Puppet[:app_management] = !ENV.include?('PUPPET_NOAPP_MANAGMENT') - end - adapter.modulepath.map do |d| Dir["#{d}/*/lib"].entries end.flatten.each do |lib| @@ -457,17 +444,15 @@ def build_catalog_without_cache_v2( node_obj = Puppet::Node.new(nodename, { parameters: node_params, facts: node_facts }) trusted_info = ['remote', nodename, trusted_facts_val] - trusted_info.push(trusted_external_data) if Puppet::Util::Package.versioncmp(Puppet.version, '6.14.0') >= 0 - if Puppet::Util::Package.versioncmp(Puppet.version, '4.3.0') >= 0 - Puppet.push_context( - { - trusted_information: Puppet::Context::TrustedInformation.new(*trusted_info) - }, - 'Context for spec trusted hash' - ) - - node_obj.add_server_facts(server_facts_hash) if RSpec.configuration.trusted_server_facts - end + trusted_info.push(trusted_external_data) + Puppet.push_context( + { + trusted_information: Puppet::Context::TrustedInformation.new(*trusted_info) + }, + 'Context for spec trusted hash' + ) + + node_obj.add_server_facts(server_facts_hash) if RSpec.configuration.trusted_server_facts adapter.catalog(node_obj, exported) end diff --git a/spec/classes/array_spec.rb b/spec/classes/array_spec.rb index 859a56494..237eef398 100644 --- a/spec/classes/array_spec.rb +++ b/spec/classes/array_spec.rb @@ -38,25 +38,7 @@ ] } end - # Puppet 2.6 will automatically flatten nested arrays. If we're going - # to be testing recursive data structures, we might as well ensure that - # we're still handling numeric values correctly. - describe 'on Puppet 2.6', if: Puppet.version =~ /^2\.6/ do - it { - expect(subject).to contain_structured_data__def('thing').with( - { 'data' => [ - 'first', - 'second', - 'third', - 'fourth', - 5, - 6 - ] } - ) - } - end - - describe 'on Puppet 2.7 and later', unless: Puppet.version =~ /^2\.6/ do + describe 'on Puppet 2.7 and later' do it { expect(subject).to contain_structured_data__def('thing').with( { 'data' => [ diff --git a/spec/classes/default_spec.rb b/spec/classes/default_spec.rb index ce769de5a..f9bf409e8 100644 --- a/spec/classes/default_spec.rb +++ b/spec/classes/default_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe 'default_test', if: Puppet.version.to_f >= 4.0 do +describe 'default_test' do let(:params) { { value: :default } } it { is_expected.to compile.with_all_deps } diff --git a/spec/classes/deferred_spec.rb b/spec/classes/deferred_spec.rb index 4bdb361da..273df6f73 100644 --- a/spec/classes/deferred_spec.rb +++ b/spec/classes/deferred_spec.rb @@ -2,6 +2,6 @@ require 'spec_helper' -describe 'deferred', if: Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') >= 0 do +describe 'deferred' do it { is_expected.to contain_notify('deferred msg').with_message('A STRING') } end diff --git a/spec/classes/facts_spec.rb b/spec/classes/facts_spec.rb index f7202751a..b91f56175 100644 --- a/spec/classes/facts_spec.rb +++ b/spec/classes/facts_spec.rb @@ -8,7 +8,7 @@ # with the description of "Facter should not downcast fact names". The "mixed case in facts" tests this functionality. describe 'structured_facts::hash' do - context 'symbols and strings in facts', if: Puppet.version.to_f >= 4.0 do + context 'symbols and strings in facts' do let(:facts) do { os: { @@ -23,7 +23,7 @@ it { is_expected.to contain_notify(family) } end - context 'only symbols in facts', if: Puppet.version.to_f >= 4.0 do + context 'only symbols in facts' do let(:facts) do { os: { @@ -39,7 +39,7 @@ end # See note concerning mixed case in facts at the beginning of the file - context 'mixed case symbols in facts', if: Puppet.version.to_f >= 4.0 do + context 'mixed case symbols in facts' do let(:facts) do { oS: { @@ -54,7 +54,7 @@ it { is_expected.to contain_notify(family) } end - context 'only strings in facts', if: Puppet.version.to_f >= 4.0 do + context 'only strings in facts' do let(:facts) do { 'os' => { @@ -70,7 +70,7 @@ end # See note concerning mixed case in facts at the beginning of the file - context 'mixed case strings in facts', if: Puppet.version.to_f >= 4.0 do + context 'mixed case strings in facts' do let(:facts) do { 'oS' => { @@ -166,7 +166,7 @@ end describe 'structured_facts::case_check' do - context 'mixed case in structure fact nested keys', if: Puppet.version.to_f >= 4.0 do + context 'mixed case in structure fact nested keys' do let(:facts) do { 'custom_fact' => { diff --git a/spec/classes/hash_spec.rb b/spec/classes/hash_spec.rb index 6e5cac0a1..eea883ec8 100644 --- a/spec/classes/hash_spec.rb +++ b/spec/classes/hash_spec.rb @@ -20,15 +20,7 @@ { 'data' => { 1 => 'uno', 2 => 'dos' } } end - context 'puppet less than 4', unless: Puppet.version.to_f >= 4.0 do - it { - expect(subject).to contain_structured_data__def('thing').with( - { 'data' => { '1' => 'uno', '2' => 'dos' } } - ) - } - end - - context 'puppet 4 or greater', if: Puppet.version.to_f >= 4.0 do + context 'puppet 4 or greater' do it { expect(subject).to contain_structured_data__def('thing').with( { 'data' => { 1 => 'uno', 2 => 'dos' } } diff --git a/spec/classes/hiera_integration_spec.rb b/spec/classes/hiera_integration_spec.rb index d4521fda3..2c6b8a7a6 100644 --- a/spec/classes/hiera_integration_spec.rb +++ b/spec/classes/hiera_integration_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' # hiera is not supported before 2.7 -describe 'test::hiera', if: Puppet.version.to_f >= 3.0 do +describe 'test::hiera' do context 'with :hiera_config set' do let(:hiera_config) { 'spec/fixtures/hiera.yaml' } @@ -15,7 +15,7 @@ end end -describe 'hiera_test', if: Puppet::Util::Package.versioncmp(Puppet.version, '4.9.0') >= 0 do +describe 'hiera_test' do before do RSpec.configuration.disable_module_hiera = false RSpec.configuration.use_fixture_spec_hiera = false @@ -106,7 +106,7 @@ end end -describe 'hiera_test2', if: Puppet::Util::Package.versioncmp(Puppet.version, '4.9.0') >= 0 do +describe 'hiera_test2' do before do RSpec.configuration.disable_module_hiera = false RSpec.configuration.use_fixture_spec_hiera = false diff --git a/spec/classes/map_reduce_spec.rb b/spec/classes/map_reduce_spec.rb index 844f222f0..fd5f992ff 100644 --- a/spec/classes/map_reduce_spec.rb +++ b/spec/classes/map_reduce_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe 'map_reduce', if: (Puppet.version.to_f >= 4.0 || RSpec.configuration.parser == 'future') do +describe 'map_reduce' do let(:params) do { values: [0, 1, 2] diff --git a/spec/classes/node_params_spec.rb b/spec/classes/node_params_spec.rb index a391c43e1..2814b774f 100644 --- a/spec/classes/node_params_spec.rb +++ b/spec/classes/node_params_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe 'node_params', if: Puppet::Util::Package.versioncmp(Puppet.version, '3.0.0') >= 0 do +describe 'node_params' do fuzzed = { string: 'foo bar baz', hash: { 'foo' => 'bar', 'baz' => 'foo' }, @@ -27,7 +27,7 @@ end end - it "doesn't leak to the facts hash", if: Puppet::Util::Package.versioncmp(Puppet.version, '4.0.0') >= 0 do + it "doesn't leak to the facts hash" do expect(subject).to contain_notify('stringfact').with(message: '') end end diff --git a/spec/classes/relationships__type_with_auto_spec.rb b/spec/classes/relationships__type_with_auto_spec.rb index a23d20ce0..1cd57a40d 100644 --- a/spec/classes/relationships__type_with_auto_spec.rb +++ b/spec/classes/relationships__type_with_auto_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe 'relationships::type_with_auto', if: Puppet::Util::Package.versioncmp(Puppet.version, '4.0.0') >= 0 do +describe 'relationships::type_with_auto' do it { is_expected.to compile.with_all_deps } it do diff --git a/spec/classes/server_facts_spec.rb b/spec/classes/server_facts_spec.rb index 6b90a53f7..ccf92496c 100644 --- a/spec/classes/server_facts_spec.rb +++ b/spec/classes/server_facts_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe 'server_facts', if: Puppet::Util::Package.versioncmp(Puppet.version, '4.3.0') >= 0 do +describe 'server_facts' do context 'with server_facts' do before do RSpec.configuration.trusted_server_facts = true diff --git a/spec/classes/test_api_spec.rb b/spec/classes/test_api_spec.rb index 3c183b02c..58e46c542 100644 --- a/spec/classes/test_api_spec.rb +++ b/spec/classes/test_api_spec.rb @@ -26,13 +26,9 @@ expect(RSpec::Puppet::Coverage.filters).to include('Class[Test::Bare_class]') end - # file and line information was only added to resources created with - # ensure_resource() in 4.6.0 (PUP-6530). - if Puppet::Util::Package.versioncmp(Puppet.version, '4.6.0') >= 0 - it 'does not include resources from other modules created with create_resources()' do - expect(RSpec::Puppet::Coverage.instance.results[:resources]).not_to include('Notify[create_resources notify]') - expect(subject).to contain_notify('create_resources notify') - end + it 'does not include resources from other modules created with create_resources()' do + expect(RSpec::Puppet::Coverage.instance.results[:resources]).not_to include('Notify[create_resources notify]') + expect(subject).to contain_notify('create_resources notify') end end end diff --git a/spec/classes/test_basic_spec.rb b/spec/classes/test_basic_spec.rb index 966871276..0a1bdd2cf 100644 --- a/spec/classes/test_basic_spec.rb +++ b/spec/classes/test_basic_spec.rb @@ -20,7 +20,7 @@ it { is_expected.to contain_notify('test123.test.com') } it { is_expected.not_to contain_notify('notthis.test.com') } - context 'existing networking facts should not be clobbered', if: Puppet.version.to_f >= 4.0 do + context 'existing networking facts should not be clobbered' do let(:pre_condition) { 'notify { [$facts["networking"]["primary"], $facts["networking"]["hostname"]]: }' } it { is_expected.to contain_notify('eth0') } diff --git a/spec/classes/test_registry_spec.rb b/spec/classes/test_registry_spec.rb index 784637775..b756fc272 100644 --- a/spec/classes/test_registry_spec.rb +++ b/spec/classes/test_registry_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe 'test::registry', if: Puppet.version.to_f >= 4.0 do +describe 'test::registry' do let(:facts) { { os: { name: 'windows' } } } it { is_expected.to compile.with_all_deps } diff --git a/spec/classes/test_sensitive_spec.rb b/spec/classes/test_sensitive_spec.rb index bd189e4f4..d9ca40f66 100644 --- a/spec/classes/test_sensitive_spec.rb +++ b/spec/classes/test_sensitive_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe 'test::sensitive', if: Puppet::Util::Package.versioncmp(Puppet.version, '4.6.0') >= 0 do +describe 'test::sensitive' do it { is_expected.to contain_class('test::sensitive::user').with_password(sensitive('myPassword')) } it { is_expected.to contain_class('test::sensitive::user').with_password(sensitive(/Pass/)) } end diff --git a/spec/classes/trusted_external_data_spec.rb b/spec/classes/trusted_external_data_spec.rb index 472212a26..2bea5232f 100644 --- a/spec/classes/trusted_external_data_spec.rb +++ b/spec/classes/trusted_external_data_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe 'trusted_external_data', if: Puppet::Util::Package.versioncmp(Puppet.version, '6.14.0') >= 0 do +describe 'trusted_external_data' do context 'no trusted external data' do it { is_expected.to contain_class('trusted_external_data') } it { is_expected.to compile.with_all_deps } diff --git a/spec/classes/trusted_facts_spec.rb b/spec/classes/trusted_facts_spec.rb index 3b3a3c04a..b10648210 100644 --- a/spec/classes/trusted_facts_spec.rb +++ b/spec/classes/trusted_facts_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe 'trusted_facts', if: Puppet::Util::Package.versioncmp(Puppet.version, '4.3.0') >= 0 do +describe 'trusted_facts' do context 'FQDN as certname' do let(:node) { 'trusted.example.com' } diff --git a/spec/classes/type_mismatch_spec.rb b/spec/classes/type_mismatch_spec.rb index f090b285d..2f15f370e 100644 --- a/spec/classes/type_mismatch_spec.rb +++ b/spec/classes/type_mismatch_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe 'type_mismatch', if: Puppet.version.to_f >= 4.0 do +describe 'type_mismatch' do it { is_expected.to compile.with_all_deps } it do diff --git a/spec/classes/undef_spec.rb b/spec/classes/undef_spec.rb index ba4c921ca..d8f3cc8f0 100644 --- a/spec/classes/undef_spec.rb +++ b/spec/classes/undef_spec.rb @@ -47,7 +47,7 @@ end end - context 'with required_attribute => :undef', unless: Puppet.version =~ /^2/ do + context 'with required_attribute => :undef' do context 'and defaults_to_undef unspecified' do let(:params) { { required_attribute: :undef } } diff --git a/spec/defines/undef_def_spec.rb b/spec/defines/undef_def_spec.rb index 76b8de5b8..4f9255eea 100644 --- a/spec/defines/undef_def_spec.rb +++ b/spec/defines/undef_def_spec.rb @@ -27,7 +27,7 @@ end end - context 'with required_attribute => :undef', unless: Puppet.version =~ /^2/ do + context 'with required_attribute => :undef' do context 'and defaults_to_undef unspecified' do let(:params) { { required_attribute: :undef } } diff --git a/spec/functions/facts_lookup_spec.rb b/spec/functions/facts_lookup_spec.rb index c9e88a3fc..50c667772 100644 --- a/spec/functions/facts_lookup_spec.rb +++ b/spec/functions/facts_lookup_spec.rb @@ -2,7 +2,7 @@ require 'rspec-puppet' -describe 'structured_facts::lookup', if: Puppet::Util::Package.versioncmp(Puppet.version, '4.3.0') >= 0 do +describe 'structured_facts::lookup' do context 'with one set of values' do let(:facts) { { 'os' => { 'family' => 'RedHat' } } } diff --git a/spec/functions/lambda_function_spec.rb b/spec/functions/lambda_function_spec.rb index 469fbd4fc..62b77630c 100644 --- a/spec/functions/lambda_function_spec.rb +++ b/spec/functions/lambda_function_spec.rb @@ -2,6 +2,6 @@ require 'spec_helper' -describe 'map', if: Puppet.version.to_i >= 4 do +describe 'map' do it { is_expected.to run.with_params([1, 2]).with_lambda { |x| "test-#{x}" }.and_return(%w[test-1 test-2]) } end diff --git a/spec/functions/nil_function_spec.rb b/spec/functions/nil_function_spec.rb index ff02d5267..dfd07a605 100644 --- a/spec/functions/nil_function_spec.rb +++ b/spec/functions/nil_function_spec.rb @@ -3,13 +3,7 @@ require 'spec_helper' describe 'nil_function' do - let(:version) do - if (Puppet[:parser] == 'future') || (Puppet.version.to_f >= 4) - 'new version' - else - 'old version' - end - end + 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/) } diff --git a/spec/functions/split_spec.rb b/spec/functions/split_spec.rb index a98601adc..170d97aa9 100644 --- a/spec/functions/split_spec.rb +++ b/spec/functions/split_spec.rb @@ -6,25 +6,11 @@ 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) } - expected_error = if Puppet::Util::Package.versioncmp(Puppet.version, '3.1.0') >= 0 - ArgumentError - else - Puppet::ParseError - end + it { is_expected.to run.with_params('foo').and_raise_error(ArgumentError) } - expected_error_message = if Puppet::Util::Package.versioncmp(Puppet.version, '4.3.0') >= 0 - /expects \d+ arguments/ - elsif Puppet::Util::Package.versioncmp(Puppet.version, '4.0.0') >= 0 - /mis-matched arguments/ - else - /number of arguments/ - end + it { is_expected.to run.with_params('foo').and_raise_error(ArgumentError, /expects \d+ arguments/) } - it { is_expected.to run.with_params('foo').and_raise_error(expected_error) } - - it { is_expected.to run.with_params('foo').and_raise_error(expected_error, expected_error_message) } - - it { is_expected.to run.with_params('foo').and_raise_error(expected_error_message) } + it { is_expected.to run.with_params('foo').and_raise_error(/expects \d+ arguments/) } it { expect do diff --git a/spec/functions/test_function_spec.rb b/spec/functions/test_function_spec.rb index dc23990d1..d75fd3aae 100644 --- a/spec/functions/test_function_spec.rb +++ b/spec/functions/test_function_spec.rb @@ -2,12 +2,12 @@ require 'spec_helper' -describe 'test_function', if: Puppet.version.to_f >= 4.0 do +describe 'test_function' do # Verify that we can load functions from modules it { is_expected.to run.with_params('foo').and_return(/value is foo/) } end -describe 'frozen_function', if: Puppet.version.to_f >= 4.0 do +describe 'frozen_function' do it { is_expected.to run.with_params('foo').and_return(true) } it { is_expected.to run.with_params(String).and_return(false) } it { is_expected.to run.with_params(true).and_return(true) } diff --git a/spec/functions/test_hiera_function_spec.rb b/spec/functions/test_hiera_function_spec.rb index a6b507aa5..219d6d9d0 100644 --- a/spec/functions/test_hiera_function_spec.rb +++ b/spec/functions/test_hiera_function_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe 'test::hiera_function', if: Puppet::Util::Package.versioncmp(Puppet.version, '4.3.0') >= 0 do +describe 'test::hiera_function' do context 'with :hiera_config set' do let(:hiera_config) { 'spec/fixtures/hiera.yaml' } diff --git a/spec/functions/trusted_facts_lookup_spec.rb b/spec/functions/trusted_facts_lookup_spec.rb index d11bd4d59..60d285f2b 100644 --- a/spec/functions/trusted_facts_lookup_spec.rb +++ b/spec/functions/trusted_facts_lookup_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe 'trusted_facts::lookup', if: Puppet::Util::Package.versioncmp(Puppet.version, '4.3.0') >= 0 do +describe 'trusted_facts::lookup' do let(:node) { 'trusted.example.com' } context 'without trusted fact extensions' do diff --git a/spec/hosts/environment_spec.rb b/spec/hosts/environment_spec.rb index 657b3230e..790c1ecfb 100644 --- a/spec/hosts/environment_spec.rb +++ b/spec/hosts/environment_spec.rb @@ -7,9 +7,7 @@ it { is_expected.to contain_file('environment').with_path('rp_env') } end - # Broken on ~> 3.8.5 since PUP-5522 - context 'when specifying an explicit environment', - unless: (Puppet.version >= '3.8.5' && Puppet.version.to_i < 4) do + context 'when specifying an explicit environment' do let(:environment) { 'test_env' } it { is_expected.to contain_file('environment').with_path('test_env') } diff --git a/spec/type_aliases/onlyarray_spec.rb b/spec/type_aliases/onlyarray_spec.rb index 19ef9e782..60c5d2f37 100644 --- a/spec/type_aliases/onlyarray_spec.rb +++ b/spec/type_aliases/onlyarray_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe 'Aliases::OnlyArray', if: Puppet::Util::Package.versioncmp(Puppet.version, '4.4.0') >= 0 do +describe 'Aliases::OnlyArray' do it { is_expected.not_to allow_value(nil, 'string') } it { is_expected.to allow_value(%w[a b]) } end diff --git a/spec/type_aliases/onlyhash_spec.rb b/spec/type_aliases/onlyhash_spec.rb index c4baba52d..0deab622d 100644 --- a/spec/type_aliases/onlyhash_spec.rb +++ b/spec/type_aliases/onlyhash_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe 'Aliases::OnlyHash', if: Puppet::Util::Package.versioncmp(Puppet.version, '4.4.0') >= 0 do +describe 'Aliases::OnlyHash' do it { is_expected.not_to allow_value(nil, 'string') } it { is_expected.to allow_value({ 'a' => 'b' }) } it { is_expected.to allow_value({ 'a' => { 'b' => 'c' } }) } diff --git a/spec/type_aliases/shape_spec.rb b/spec/type_aliases/shape_spec.rb index f427a1448..7d7e27e56 100644 --- a/spec/type_aliases/shape_spec.rb +++ b/spec/type_aliases/shape_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe 'Aliases::Shape', if: Puppet::Util::Package.versioncmp(Puppet.version, '4.4.0') >= 0 do +describe 'Aliases::Shape' do it { is_expected.to allow_value('square') } it { is_expected.to allow_value('circle') } it { is_expected.not_to allow_value('triangle') } diff --git a/spec/unit/example/function_example_group_spec.rb b/spec/unit/example/function_example_group_spec.rb index 2753976a5..ca729f23f 100644 --- a/spec/unit/example/function_example_group_spec.rb +++ b/spec/unit/example/function_example_group_spec.rb @@ -2,27 +2,25 @@ require 'spec_helper' -if Puppet.version.to_f >= 4.0 - describe RSpec::Puppet::FunctionExampleGroup::V4FunctionWrapper do - let(:name) { 'test_function' } - let(:func) { double('func') } - let(:global_scope) { double('global_scope') } - let(:overrides) { { global_scope: global_scope } } - - describe 'when calling with params' do - subject { described_class.new(name, func, overrides) } - it do - expect(func).to receive(:call).with(global_scope, 1, 2).once - subject.call({}, 1, 2) - end +describe RSpec::Puppet::FunctionExampleGroup::V4FunctionWrapper do + let(:name) { 'test_function' } + let(:func) { double('func') } + let(:global_scope) { double('global_scope') } + let(:overrides) { { global_scope: global_scope } } + + describe 'when calling with params' do + subject { described_class.new(name, func, overrides) } + it do + expect(func).to receive(:call).with(global_scope, 1, 2).once + subject.call({}, 1, 2) end + end - describe 'when executing with params' do - subject { described_class.new(name, func, overrides) } - it do - expect(func).to receive(:call).with(global_scope, 1, 2).once - subject.execute(1, 2) - end + describe 'when executing with params' do + subject { described_class.new(name, func, overrides) } + it do + expect(func).to receive(:call).with(global_scope, 1, 2).once + subject.execute(1, 2) end end end diff --git a/spec/unit/matchers/allow_value_spec.rb b/spec/unit/matchers/allow_value_spec.rb index 0b45a5585..d4d08d276 100644 --- a/spec/unit/matchers/allow_value_spec.rb +++ b/spec/unit/matchers/allow_value_spec.rb @@ -3,8 +3,7 @@ require 'spec_helper' require 'rspec-puppet/support' -# is_expected.to not available with rspec 2.14, which is only used for puppet < 3 -describe RSpec::Puppet::TypeAliasMatchers::AllowValue, if: Puppet.version.to_f >= 3.0 do +describe RSpec::Puppet::TypeAliasMatchers::AllowValue do subject { described_class.new(values) } let(:catalogue) { double('catalogue builder') } diff --git a/spec/unit/matchers/compile_spec.rb b/spec/unit/matchers/compile_spec.rb index 4b1e9c84b..394a15673 100644 --- a/spec/unit/matchers/compile_spec.rb +++ b/spec/unit/matchers/compile_spec.rb @@ -3,90 +3,124 @@ require 'spec_helper' require 'rspec-puppet/support' -# is_expected.to and a_string_starting_with not available with rspec 2.14, which is only used for puppet < 3 -if Puppet.version.to_f >= 3.0 - describe RSpec::Puppet::ManifestMatchers::Compile do - include RSpec::Puppet::Support - # override RSpec::Puppet::Support's subject with the original default - subject { described_class.new } +describe RSpec::Puppet::ManifestMatchers::Compile do + include RSpec::Puppet::Support + # override RSpec::Puppet::Support's subject with the original default + subject { described_class.new } - let(:catalogue) { -> { load_catalogue(:host) } } - let(:facts) { { 'operatingsystem' => 'Debian' } } + let(:catalogue) { -> { load_catalogue(:host) } } + let(:facts) { { 'operatingsystem' => 'Debian' } } - describe 'a valid manifest' do - let(:pre_condition) { 'file { "/tmp/resource": }' } + describe 'a valid manifest' do + let(:pre_condition) { 'file { "/tmp/resource": }' } - it('matches') { is_expected.to be_matches catalogue } + it('matches') { is_expected.to be_matches catalogue } + + it { + expect(subject).to have_attributes( + description: 'compile into a catalogue without dependency cycles' + ) + } + + context 'when expecting an "example" error' do + before { subject.and_raise_error('example') } + + it("doesn't match") { is_expected.not_to be_matches catalogue } it { expect(subject).to have_attributes( - description: 'compile into a catalogue without dependency cycles' + description: 'fail to compile and raise the error "example"' ) } - context 'when expecting an "example" error' do - before { subject.and_raise_error('example') } - - it("doesn't match") { is_expected.not_to be_matches catalogue } + context 'after matching' do + before { subject.matches? catalogue } it { expect(subject).to have_attributes( - description: 'fail to compile and raise the error "example"' + failure_message: a_string_starting_with('expected that the catalogue would fail to compile and raise the error "example"') ) } + end + end - context 'after matching' do - before { subject.matches? catalogue } + context 'when matching an "example" error' do + before { subject.and_raise_error(/example/) } - it { - expect(subject).to have_attributes( - failure_message: a_string_starting_with('expected that the catalogue would fail to compile and raise the error "example"') - ) - } - end - end + it("doesn't match") { is_expected.not_to be_matches catalogue } - context 'when matching an "example" error' do - before { subject.and_raise_error(/example/) } + it { + expect(subject).to have_attributes( + description: 'fail to compile and raise an error matching /example/' + ) + } - it("doesn't match") { is_expected.not_to be_matches catalogue } + context 'after matching' do + before { subject.matches? catalogue } it { expect(subject).to have_attributes( - description: 'fail to compile and raise an error matching /example/' + failure_message: a_string_starting_with('expected that the catalogue would fail to compile and raise an error matching /example/') ) } + end + end + end - context 'after matching' do - before { subject.matches? catalogue } + describe 'a manifest with missing dependencies' do + let(:pre_condition) { 'file { "/tmp/resource": require => File["/tmp/missing"] }' } - it { - expect(subject).to have_attributes( - failure_message: a_string_starting_with('expected that the catalogue would fail to compile and raise an error matching /example/') - ) - } - end - end + it("doesn't match") { is_expected.not_to be_matches catalogue } + + context 'after matching' do + before { subject.matches? catalogue } + + it { + expect(subject).to have_attributes( + failure_message: a_string_matching(%r{\Aerror during compilation: Could not (retrieve dependency|find resource) 'File\[/tmp/missing\]'}) + ) + } end + end - describe 'a manifest with missing dependencies' do - let(:pre_condition) { 'file { "/tmp/resource": require => File["/tmp/missing"] }' } + describe 'a manifest with syntax error' do + let(:pre_condition) { 'file { "/tmp/resource": ' } - it("doesn't match") { is_expected.not_to be_matches catalogue } + it("doesn't match") { is_expected.not_to be_matches catalogue } - context 'after matching' do - before { subject.matches? catalogue } + context 'after matching' do + before { subject.matches? catalogue } - it { - expect(subject).to have_attributes( - failure_message: a_string_matching(%r{\Aerror during compilation: Could not (retrieve dependency|find resource) 'File\[/tmp/missing\]'}) - ) - } - end + it { + expect(subject).to have_attributes( + failure_message: a_string_starting_with('error during compilation: ') + ) + } + end + end + + describe 'a manifest with a dependency cycle' do + let(:pre_condition) do + <<-EOS + file { "/tmp/a": require => File["/tmp/b"] } + file { "/tmp/b": require => File["/tmp/a"] } + EOS end - describe 'a manifest with syntax error' do - let(:pre_condition) { 'file { "/tmp/resource": ' } + it("doesn't match") { is_expected.not_to be_matches catalogue } + + context 'after matching' do + before { subject.matches? catalogue } + + it { + expect(subject).to have_attributes( + failure_message: a_string_starting_with('dependency cycles found: ') + ) + } + end + + context 'when expecting an "example" error' do + before { subject.and_raise_error('example') } it("doesn't match") { is_expected.not_to be_matches catalogue } @@ -95,19 +129,15 @@ it { expect(subject).to have_attributes( - failure_message: a_string_starting_with('error during compilation: ') + description: 'fail to compile and raise the error "example"', + failure_message: a_string_starting_with('dependency cycles found: ') ) } end end - describe 'a manifest with a dependency cycle' do - let(:pre_condition) do - <<-EOS - file { "/tmp/a": require => File["/tmp/b"] } - file { "/tmp/b": require => File["/tmp/a"] } - EOS - end + context 'when matching an "example" error' do + before { subject.and_raise_error(/example/) } it("doesn't match") { is_expected.not_to be_matches catalogue } @@ -116,117 +146,76 @@ it { expect(subject).to have_attributes( + description: 'fail to compile and raise an error matching /example/', failure_message: a_string_starting_with('dependency cycles found: ') ) } end + end + end - context 'when expecting an "example" error' do - before { subject.and_raise_error('example') } - - it("doesn't match") { is_expected.not_to be_matches catalogue } - - context 'after matching' do - before { subject.matches? catalogue } - - it { - expect(subject).to have_attributes( - description: 'fail to compile and raise the error "example"', - failure_message: a_string_starting_with('dependency cycles found: ') - ) - } - end - end + describe 'a manifest with a real failure' do + let(:pre_condition) { 'fail("failure")' } - context 'when matching an "example" error' do - before { subject.and_raise_error(/example/) } + it("doesn't match") { is_expected.not_to be_matches catalogue } - it("doesn't match") { is_expected.not_to be_matches catalogue } + context 'after matching' do + before { subject.matches? catalogue } - context 'after matching' do - before { subject.matches? catalogue } + it { + expect(subject).to have_attributes( + description: 'compile into a catalogue without dependency cycles', + failure_message: a_string_starting_with('error during compilation: ') + ) + } + end - it { - expect(subject).to have_attributes( - description: 'fail to compile and raise an error matching /example/', - failure_message: a_string_starting_with('dependency cycles found: ') - ) - } - end + 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" end - end - describe 'a manifest with a real failure' do - let(:pre_condition) { 'fail("failure")' } + before { subject.and_raise_error(expected_error) } - it("doesn't match") { is_expected.not_to be_matches catalogue } + let(:error_detail) { 'failure (line: 52, column: 1)' } + it('matches') { is_expected.to be_matches catalogue } + + it { + expect(subject).to have_attributes( + description: "fail to compile and raise the error \"#{expected_error}\"" + ) + } context 'after matching' do before { subject.matches? catalogue } it { expect(subject).to have_attributes( - description: 'compile into a catalogue without dependency cycles', failure_message: a_string_starting_with('error during compilation: ') ) } end + end - 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" - end - - before { subject.and_raise_error(expected_error) } - - if Puppet::Util::Package.versioncmp(Puppet.version, '5.3.4') >= 0 - let(:error_detail) { 'failure (line: 52, column: 1)' } - else - let(:error_detail) { 'failure at line 52:1' } - end - - if Puppet.version.to_f >= 4.0 - # the error message above is puppet4 specific - it('matches') { is_expected.to be_matches catalogue } - end - - it { - expect(subject).to have_attributes( - description: "fail to compile and raise the error \"#{expected_error}\"" - ) - } - - context 'after matching' do - before { subject.matches? catalogue } + context 'when matching the failure' do + before { subject.and_raise_error(/failure/) } - it { - expect(subject).to have_attributes( - failure_message: a_string_starting_with('error during compilation: ') - ) - } - end - end + it('matches') { is_expected.to be_matches catalogue } - context 'when matching the failure' do - before { subject.and_raise_error(/failure/) } + it { + expect(subject).to have_attributes( + description: 'fail to compile and raise an error matching /failure/' + ) + } - it('matches') { is_expected.to be_matches catalogue } + context 'after matching' do + before { subject.matches? catalogue } it { expect(subject).to have_attributes( - description: 'fail to compile and raise an error matching /failure/' + failure_message: a_string_starting_with('error during compilation: ') ) } - - context 'after matching' do - before { subject.matches? catalogue } - - it { - expect(subject).to have_attributes( - failure_message: a_string_starting_with('error during compilation: ') - ) - } - end end end end diff --git a/spec/unit/sensitive_spec.rb b/spec/unit/sensitive_spec.rb index 0056fc820..117e75b44 100644 --- a/spec/unit/sensitive_spec.rb +++ b/spec/unit/sensitive_spec.rb @@ -26,7 +26,7 @@ end end - describe '#==', if: Puppet::Util::Package.versioncmp(Puppet.version, '4.6.0') >= 0 do + describe '#==' do it 'compares equal to Puppet sensitive type' do expect(sensitive).to eq Puppet::Pops::Types::PSensitiveType::Sensitive.new contents end