Skip to content

Commit 0a72fd8

Browse files
committed
Drop RSpec 2 support
1 parent 5194e43 commit 0a72fd8

File tree

8 files changed

+13
-94
lines changed

8 files changed

+13
-94
lines changed

lib/rspec-puppet/monkey_patches.rb

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,10 @@
1111

1212
class RSpec::Puppet::EventListener
1313
def self.example_started(example)
14-
if rspec3?
15-
@rspec_puppet_example = example.example.example_group.ancestors.include?(RSpec::Puppet::Support)
16-
@current_example = example.example
17-
if !@current_example.respond_to?(:environment) && @current_example.respond_to?(:example_group_instance)
18-
@current_example = @current_example.example_group_instance
19-
end
20-
else
21-
@rspec_puppet_example = example.example_group.ancestors.include?(RSpec::Puppet::Support)
22-
@current_example = example
14+
@rspec_puppet_example = example.example.example_group.ancestors.include?(RSpec::Puppet::Support)
15+
@current_example = example.example
16+
if !@current_example.respond_to?(:environment) && @current_example.respond_to?(:example_group_instance)
17+
@current_example = @current_example.example_group_instance
2318
end
2419
end
2520

@@ -39,12 +34,6 @@ def self.rspec_puppet_example?
3934
@rspec_puppet_example || false
4035
end
4136

42-
def self.rspec3?
43-
@rspec3 = defined?(RSpec::Core::Notifications) if @rspec3.nil?
44-
45-
@rspec3
46-
end
47-
4837
class << self
4938
attr_reader :current_example
5039
end

lib/rspec-puppet/support.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -508,14 +508,6 @@ def escape_special_chars(string)
508508
string.gsub('$', '\\$')
509509
end
510510

511-
def rspec_compatibility
512-
return unless RSpec::Version::STRING < '3'
513-
514-
# RSpec 2 compatibility:
515-
alias_method :failure_message_for_should, :failure_message
516-
alias_method :failure_message_for_should_not, :failure_message_when_negated
517-
end
518-
519511
def fixture_spec_hiera_conf(mod)
520512
return @@fixture_hiera_configs[mod.name] if @@fixture_hiera_configs.key?(mod.name)
521513

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

spec/spec_helper.rb

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,17 @@
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?
2322
end
2423

2524
def sensitive?
2625
defined?(Puppet::Pops::Types::PSensitiveType)
2726
end
2827

29-
module Helpers
30-
def rspec2?
31-
RSpec::Version::STRING < '3'
32-
end
33-
module_function :rspec2?
34-
end
35-
3628
RSpec.configure do |c|
3729
c.module_path = File.join(File.dirname(File.expand_path(__FILE__)), 'fixtures', 'modules')
3830
c.manifest_dir = File.join(File.dirname(File.expand_path(__FILE__)), 'fixtures', 'manifests')
@@ -43,7 +35,4 @@ def rspec2?
4335
c.after(:suite) do
4436
RSpec::Puppet::Coverage.report!(0)
4537
end
46-
47-
c.include Helpers
48-
c.extend Helpers
4938
end

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)