Skip to content

Commit

Permalink
Drop RSpec 2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
ekohl authored and jordanbreen28 committed Oct 2, 2023
1 parent 88076e2 commit b58bb47
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 88 deletions.
6 changes: 0 additions & 6 deletions lib/rspec-puppet/monkey_patches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec-puppet/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 0 additions & 8 deletions lib/rspec-puppet/support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion rspec-puppet.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ['[email protected]', '[email protected]']
Expand Down
13 changes: 6 additions & 7 deletions spec/classes/server_facts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 6 additions & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
34 changes: 0 additions & 34 deletions spec/spec_helper_unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions spec/unit/adapters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
context = context_double strict_variables: true
subject.setup_puppet(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)
context = context_double environmentpath: '/path/to/my/environments'
subject.setup_puppet(context)
expect(Puppet[:environmentpath]).to match(%r{(C:)?/path/to/my/environments})
end

Expand Down
4 changes: 2 additions & 2 deletions spec/unit/matchers/count_generic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
23 changes: 3 additions & 20 deletions spec/unit/matchers/include_class_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/matchers/run_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b58bb47

Please sign in to comment.