From 7a27b790538234f584303a3fb6792a0addd13167 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Sat, 19 Aug 2023 11:55:32 +0200 Subject: [PATCH] Drop RSpec 2 support --- lib/rspec-puppet/monkey_patches.rb | 6 ----- lib/rspec-puppet/spec_helper.rb | 2 +- lib/rspec-puppet/support.rb | 8 ------ rspec-puppet.gemspec | 2 +- spec/classes/server_facts_spec.rb | 13 +++++---- spec/spec_helper.rb | 9 ++++--- spec/spec_helper_unit.rb | 34 ------------------------ spec/unit/adapters_spec.rb | 10 +++---- spec/unit/matchers/count_generic_spec.rb | 4 +-- spec/unit/matchers/include_class_spec.rb | 23 +++------------- spec/unit/matchers/run_spec.rb | 2 +- 11 files changed, 25 insertions(+), 88 deletions(-) diff --git a/lib/rspec-puppet/monkey_patches.rb b/lib/rspec-puppet/monkey_patches.rb index e46490f77..798fb257d 100644 --- a/lib/rspec-puppet/monkey_patches.rb +++ b/lib/rspec-puppet/monkey_patches.rb @@ -34,12 +34,6 @@ def self.rspec_puppet_example? @rspec_puppet_example || false end - def self.rspec3? - @rspec3 = defined?(RSpec::Core::Notifications) if @rspec3.nil? - - @rspec3 - end - class << self attr_reader :current_example end diff --git a/lib/rspec-puppet/spec_helper.rb b/lib/rspec-puppet/spec_helper.rb index 5f32a01c7..3c3e5c174 100644 --- a/lib/rspec-puppet/spec_helper.rb +++ b/lib/rspec-puppet/spec_helper.rb @@ -3,7 +3,7 @@ require 'rspec-puppet' RSpec.configure do |c| - c.module_path = File.join(__dir__, 'fixtures', 'modules') + 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 bb8201a50..692bfe92a 100644 --- a/lib/rspec-puppet/support.rb +++ b/lib/rspec-puppet/support.rb @@ -468,14 +468,6 @@ def escape_special_chars(string) string.gsub('$', '\\$') end - def rspec_compatibility - return unless RSpec::Version::STRING < '3' - - # RSpec 2 compatibility: - alias_method :failure_message_for_should, :failure_message - alias_method :failure_message_for_should_not, :failure_message_when_negated - end - def fixture_spec_hiera_conf(mod) return @@fixture_hiera_configs[mod.name] if @@fixture_hiera_configs.key?(mod.name) diff --git a/rspec-puppet.gemspec b/rspec-puppet.gemspec index bd4cc20ec..eadd0f8c0 100644 --- a/rspec-puppet.gemspec +++ b/rspec-puppet.gemspec @@ -16,7 +16,7 @@ Gem::Specification.new do |s| s.files = Dir['CHANGELOG.md', 'LICENSE.md', 'README.md', 'lib/**/*', 'bin/**/*'] - s.add_dependency 'rspec' + s.add_dependency 'rspec', '~> 3.0' s.authors = ['Tim Sharpe', 'Puppet, Inc.', 'Community Contributors'] s.email = ['tim@sharpe.id.au', 'modules-team@puppet.com'] diff --git a/spec/classes/server_facts_spec.rb b/spec/classes/server_facts_spec.rb index a41f3d697..66d73135b 100644 --- a/spec/classes/server_facts_spec.rb +++ b/spec/classes/server_facts_spec.rb @@ -10,11 +10,10 @@ end let(:node) { 'test123.test.com' } - it { is_expected.to contain_class('server_facts') } - it { is_expected.to compile.with_all_deps } - it { is_expected.to contain_notify('servername-test123.test.com') } - it { is_expected.to contain_notify('serverip-192.168.1.10') } - it { is_expected.to contain_notify("serverversion-#{Puppet.version}") } - it { is_expected.to contain_notify('environment-rp_env') } - end + it { is_expected.to contain_class('server_facts') } + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_notify('servername-test123.test.com') } + it { is_expected.to contain_notify('serverip-192.168.1.10') } + it { is_expected.to contain_notify("serverversion-#{Puppet.version}") } + it { is_expected.to contain_notify('environment-rp_env') } end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 060766c66..3cc73c581 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -14,12 +14,15 @@ require 'rspec-puppet' -# rspec 2.x doesn't have RSpec::Support, so fall back to File::ALT_SEPARATOR to -# detect if running on windows +# TODO: drop? def windows? return @windowsp unless @windowsp.nil? - @windowsp = defined?(RSpec::Support) ? RSpec::Support::OS.windows? : !!File::ALT_SEPARATOR + @windowsp = RSpec::Support::OS.windows? +end + +def sensitive? + defined?(Puppet::Pops::Types::PSensitiveType) end RSpec.configure do |c| diff --git a/spec/spec_helper_unit.rb b/spec/spec_helper_unit.rb index 23d192dde..2be7d12e2 100644 --- a/spec/spec_helper_unit.rb +++ b/spec/spec_helper_unit.rb @@ -13,37 +13,3 @@ end require 'rspec-puppet' - -module Helpers - def rspec2? - RSpec::Version::STRING < '3' - end - module_function :rspec2? - - def test_double(type, *args) - if rspec2? - double(type.to_s, *args) - else - instance_double(type, *args) - end - end -end - -RSpec.configure do |c| - c.include Helpers - c.extend Helpers - - if Helpers.rspec2? - RSpec::Matchers.define :be_truthy do - match do |actual| - !actual.nil? == true - end - end - - RSpec::Matchers.define :be_falsey do - match do |actual| - !actual.nil? == false - end - end - end -end diff --git a/spec/unit/adapters_spec.rb b/spec/unit/adapters_spec.rb index 47571058c..09b3703a9 100644 --- a/spec/unit/adapters_spec.rb +++ b/spec/unit/adapters_spec.rb @@ -32,19 +32,19 @@ def context_double(options = {}) end it 'sets Puppet[:strict_variables] to false by default' do - subject.setup_puppet(test_context) + subject.setup_puppet(context_double) 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) + allow(context_double).to receive(:strict_variables).and_return(true) + subject.setup_puppet(context_double) 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) + allow(context_double).to receive(:environmentpath).and_return('/path/to/my/environments') + subject.setup_puppet(context_double) expect(Puppet[:environmentpath]).to match(%r{(C:)?/path/to/my/environments}) end diff --git a/spec/unit/matchers/count_generic_spec.rb b/spec/unit/matchers/count_generic_spec.rb index 45df78c3c..03cac7501 100644 --- a/spec/unit/matchers/count_generic_spec.rb +++ b/spec/unit/matchers/count_generic_spec.rb @@ -6,12 +6,12 @@ subject(:matcher) { described_class.new(type, expected, method) } let(:actual) do - -> { test_double(Puppet::Resource::Catalog, resources: resource_objects) } + -> { instance_double(Puppet::Resource::Catalog, resources: resource_objects) } end let(:resource_objects) do resources.map do |type, title| - test_double(Puppet::Resource, ref: "#{type}[#{title}]", type: type) + instance_double(Puppet::Resource, ref: "#{type}[#{title}]", type: type) end end diff --git a/spec/unit/matchers/include_class_spec.rb b/spec/unit/matchers/include_class_spec.rb index dc685ad0a..c67490dca 100644 --- a/spec/unit/matchers/include_class_spec.rb +++ b/spec/unit/matchers/include_class_spec.rb @@ -6,7 +6,7 @@ subject(:matcher) { Class.new { extend RSpec::Puppet::ManifestMatchers }.include_class(expected) } let(:actual) do - -> { test_double(Puppet::Resource::Catalog, classes: included_classes) } + -> { instance_double(Puppet::Resource::Catalog, classes: included_classes) } end let(:expected) { 'test_class' } @@ -44,31 +44,14 @@ end end - describe '#failure_message_for_should', if: rspec2? do - it 'provides a description and the expected class' do - matcher.matches?(actual) - expect(matcher.failure_message_for_should).to eq("expected that the catalogue would include Class[#{expected}]") - end - end - - describe '#failure_message', unless: rspec2? do + describe '#failure_message' do it 'provides a description and the expected class' do matcher.matches?(actual) expect(matcher.failure_message).to eq("expected that the catalogue would include Class[#{expected}]") end end - describe '#failure_message_for_should_not', if: rspec2? do - let(:included_classes) { [expected] } - - it 'provides a description and the expected class' do - pending 'not implemented' - matcher.matches?(actual) - expect(matcher.failure_message_when_negated).to eq("expected that the catalogue would not include Class[#{expected}]") - end - end - - describe '#failure_message_when_negated', unless: rspec2? do + describe '#failure_message_when_negated' do let(:included_classes) { [expected] } it 'provides a description and the expected class' do diff --git a/spec/unit/matchers/run_spec.rb b/spec/unit/matchers/run_spec.rb index d468f521f..a470f3f20 100644 --- a/spec/unit/matchers/run_spec.rb +++ b/spec/unit/matchers/run_spec.rb @@ -5,7 +5,7 @@ describe RSpec::Puppet::FunctionMatchers::Run do subject(:matcher) { described_class.new } - let(:wrapper) { test_double(RSpec::Puppet::FunctionExampleGroup::V4FunctionWrapper) } + let(:wrapper) { instance_double(RSpec::Puppet::FunctionExampleGroup::V4FunctionWrapper) } describe '#matches?' do context 'when the function takes no arguments and has no expected return value' do