Skip to content

Commit fc65ffe

Browse files
ekohljordanbreen28
authored andcommitted
Drop RSpec 2 support
1 parent 88076e2 commit fc65ffe

10 files changed

+20
-83
lines changed

lib/rspec-puppet/monkey_patches.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ def self.rspec_puppet_example?
3434
@rspec_puppet_example || false
3535
end
3636

37-
def self.rspec3?
38-
@rspec3 = defined?(RSpec::Core::Notifications) if @rspec3.nil?
39-
40-
@rspec3
41-
end
42-
4337
class << self
4438
attr_reader :current_example
4539
end

lib/rspec-puppet/spec_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require 'rspec-puppet'
44

55
RSpec.configure do |c|
6-
c.module_path = File.join(__dir__, 'fixtures', 'modules')
6+
c.module_path = File.join(__dir__, 'fixtures', 'modules')
77
c.manifest = File.join(fixture_path, 'manifests', 'site.pp')
88
c.environmentpath = __dir__
99
end

lib/rspec-puppet/support.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -468,14 +468,6 @@ def escape_special_chars(string)
468468
string.gsub('$', '\\$')
469469
end
470470

471-
def rspec_compatibility
472-
return unless RSpec::Version::STRING < '3'
473-
474-
# RSpec 2 compatibility:
475-
alias_method :failure_message_for_should, :failure_message
476-
alias_method :failure_message_for_should_not, :failure_message_when_negated
477-
end
478-
479471
def fixture_spec_hiera_conf(mod)
480472
return @@fixture_hiera_configs[mod.name] if @@fixture_hiera_configs.key?(mod.name)
481473

rspec-puppet.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
1616

1717
s.files = Dir['CHANGELOG.md', 'LICENSE.md', 'README.md', 'lib/**/*', 'bin/**/*']
1818

19-
s.add_dependency 'rspec'
19+
s.add_dependency 'rspec', '~> 3.0'
2020

2121
s.authors = ['Tim Sharpe', 'Puppet, Inc.', 'Community Contributors']
2222
s.email = ['tim@sharpe.id.au', 'modules-team@puppet.com']

spec/classes/server_facts_spec.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@
1010
end
1111
let(:node) { 'test123.test.com' }
1212

13-
it { is_expected.to contain_class('server_facts') }
14-
it { is_expected.to compile.with_all_deps }
15-
it { is_expected.to contain_notify('servername-test123.test.com') }
16-
it { is_expected.to contain_notify('serverip-192.168.1.10') }
17-
it { is_expected.to contain_notify("serverversion-#{Puppet.version}") }
18-
it { is_expected.to contain_notify('environment-rp_env') }
19-
end
13+
it { is_expected.to contain_class('server_facts') }
14+
it { is_expected.to compile.with_all_deps }
15+
it { is_expected.to contain_notify('servername-test123.test.com') }
16+
it { is_expected.to contain_notify('serverip-192.168.1.10') }
17+
it { is_expected.to contain_notify("serverversion-#{Puppet.version}") }
18+
it { is_expected.to contain_notify('environment-rp_env') }
2019
end

spec/spec_helper.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@
1414

1515
require 'rspec-puppet'
1616

17-
# rspec 2.x doesn't have RSpec::Support, so fall back to File::ALT_SEPARATOR to
18-
# detect if running on windows
17+
# TODO: drop?
1918
def windows?
2019
return @windowsp unless @windowsp.nil?
2120

22-
@windowsp = defined?(RSpec::Support) ? RSpec::Support::OS.windows? : !!File::ALT_SEPARATOR
21+
@windowsp = RSpec::Support::OS.windows?
22+
end
23+
24+
def sensitive?
25+
defined?(Puppet::Pops::Types::PSensitiveType)
2326
end
2427

2528
RSpec.configure do |c|

spec/spec_helper_unit.rb

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,3 @@
1313
end
1414

1515
require 'rspec-puppet'
16-
17-
module Helpers
18-
def rspec2?
19-
RSpec::Version::STRING < '3'
20-
end
21-
module_function :rspec2?
22-
23-
def test_double(type, *args)
24-
if rspec2?
25-
double(type.to_s, *args)
26-
else
27-
instance_double(type, *args)
28-
end
29-
end
30-
end
31-
32-
RSpec.configure do |c|
33-
c.include Helpers
34-
c.extend Helpers
35-
36-
if Helpers.rspec2?
37-
RSpec::Matchers.define :be_truthy do
38-
match do |actual|
39-
!actual.nil? == true
40-
end
41-
end
42-
43-
RSpec::Matchers.define :be_falsey do
44-
match do |actual|
45-
!actual.nil? == false
46-
end
47-
end
48-
end
49-
end

spec/unit/matchers/count_generic_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
subject(:matcher) { described_class.new(type, expected, method) }
77

88
let(:actual) do
9-
-> { test_double(Puppet::Resource::Catalog, resources: resource_objects) }
9+
-> { instance_double(Puppet::Resource::Catalog, resources: resource_objects) }
1010
end
1111

1212
let(:resource_objects) do
1313
resources.map do |type, title|
14-
test_double(Puppet::Resource, ref: "#{type}[#{title}]", type: type)
14+
instance_double(Puppet::Resource, ref: "#{type}[#{title}]", type: type)
1515
end
1616
end
1717

spec/unit/matchers/include_class_spec.rb

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
subject(:matcher) { Class.new { extend RSpec::Puppet::ManifestMatchers }.include_class(expected) }
77

88
let(:actual) do
9-
-> { test_double(Puppet::Resource::Catalog, classes: included_classes) }
9+
-> { instance_double(Puppet::Resource::Catalog, classes: included_classes) }
1010
end
1111

1212
let(:expected) { 'test_class' }
@@ -44,31 +44,14 @@
4444
end
4545
end
4646

47-
describe '#failure_message_for_should', if: rspec2? do
48-
it 'provides a description and the expected class' do
49-
matcher.matches?(actual)
50-
expect(matcher.failure_message_for_should).to eq("expected that the catalogue would include Class[#{expected}]")
51-
end
52-
end
53-
54-
describe '#failure_message', unless: rspec2? do
47+
describe '#failure_message' do
5548
it 'provides a description and the expected class' do
5649
matcher.matches?(actual)
5750
expect(matcher.failure_message).to eq("expected that the catalogue would include Class[#{expected}]")
5851
end
5952
end
6053

61-
describe '#failure_message_for_should_not', if: rspec2? do
62-
let(:included_classes) { [expected] }
63-
64-
it 'provides a description and the expected class' do
65-
pending 'not implemented'
66-
matcher.matches?(actual)
67-
expect(matcher.failure_message_when_negated).to eq("expected that the catalogue would not include Class[#{expected}]")
68-
end
69-
end
70-
71-
describe '#failure_message_when_negated', unless: rspec2? do
54+
describe '#failure_message_when_negated' do
7255
let(:included_classes) { [expected] }
7356

7457
it 'provides a description and the expected class' do

spec/unit/matchers/run_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
describe RSpec::Puppet::FunctionMatchers::Run do
66
subject(:matcher) { described_class.new }
77

8-
let(:wrapper) { test_double(RSpec::Puppet::FunctionExampleGroup::V4FunctionWrapper) }
8+
let(:wrapper) { instance_double(RSpec::Puppet::FunctionExampleGroup::V4FunctionWrapper) }
99

1010
describe '#matches?' do
1111
context 'when the function takes no arguments and has no expected return value' do

0 commit comments

Comments
 (0)