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 46b747e
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 82 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
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 = ['tim@sharpe.id.au', 'modules-team@puppet.com']
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
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 46b747e

Please sign in to comment.