Skip to content

Commit 83a439c

Browse files
committed
(CONT-237) - Remove scope method
1 parent 493f0cb commit 83a439c

File tree

2 files changed

+3
-59
lines changed

2 files changed

+3
-59
lines changed

lib/puppetlabs_spec_helper/puppetlabs_spec/puppet_internals.rb

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,6 @@
77
# PuppetInternals provides a set of methods that interface
88
# with internal puppet implementations.
99
module PuppetlabsSpec::PuppetInternals
10-
# parser_scope is intended to return a Puppet::Parser::Scope
11-
# instance suitable for placing in a test harness with the intent of
12-
# testing parser functions from modules.
13-
def scope(parts = {})
14-
RSpec.deprecate('scope', replacement: 'rspec-puppet 2.2.0 provides a scope property')
15-
16-
if %r{^2\.[67]}.match?(Puppet.version)
17-
# loadall should only be necessary prior to 3.x
18-
# Please note, loadall needs to happen first when creating a scope, otherwise
19-
# you might receive undefined method `function_*' errors
20-
Puppet::Parser::Functions.autoloader.loadall
21-
end
22-
23-
scope_compiler = parts[:compiler] || compiler
24-
scope_parent = parts[:parent] || scope_compiler.topscope
25-
26-
scope = if %r{^2\.[67]}.match?(Puppet.version)
27-
Puppet::Parser::Scope.new(compiler: scope_compiler)
28-
else
29-
Puppet::Parser::Scope.new(scope_compiler)
30-
end
31-
32-
scope.source = Puppet::Resource::Type.new(:node, 'foo')
33-
scope.parent = scope_parent
34-
scope
35-
end
36-
module_function :scope
37-
3810
def resource(parts = {})
3911
resource_type = parts[:type] || :hostclass
4012
resource_name = parts[:name] || 'testing'
@@ -51,11 +23,7 @@ def compiler(parts = {})
5123
def node(parts = {})
5224
node_name = parts[:name] || 'testinghost'
5325
options = parts[:options] || {}
54-
node_environment = if Puppet.version.to_f >= 4.0
55-
Puppet::Node::Environment.create(parts[:environment] || 'test', [])
56-
else
57-
Puppet::Node::Environment.new(parts[:environment] || 'test')
58-
end
26+
node_environment = Puppet::Node::Environment.create(parts[:environment] || 'test', [])
5927
options[:environment] = node_environment
6028
Puppet::Node.new(node_name, options)
6129
end

spec/unit/puppetlabs_spec_helper/puppetlabs_spec/puppet_internals_spec.rb

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,13 @@
11
# frozen_string_literal: true
22

33
require 'spec_helper'
4+
require 'rspec-puppet'
45

56
describe PuppetlabsSpec::PuppetInternals do
67
before(:all) do # this is only needed once # rubocop:disable RSpec/BeforeAfterAll
78
Puppet.initialize_settings
89
end
910

10-
describe '.scope' do
11-
subject(:scope) { described_class.scope }
12-
13-
it 'returns a Puppet::Parser::Scope instance' do
14-
expect(scope).to be_a_kind_of Puppet::Parser::Scope
15-
end
16-
17-
it 'is suitable for function testing' do
18-
expect(scope.function_inline_template(['foo'])).to eq('foo')
19-
end
20-
21-
it 'accepts a compiler' do
22-
compiler = described_class.compiler
23-
scope = described_class.scope(compiler: compiler)
24-
expect(scope.compiler).to eq(compiler)
25-
end
26-
27-
it 'has a source set' do
28-
expect(scope.source).not_to be_nil
29-
expect(scope.source.name).to eq('foo')
30-
end
31-
end
32-
3311
describe '.resource' do
3412
subject(:resource) { described_class.resource }
3513

@@ -78,17 +56,15 @@
7856
end
7957
end
8058

81-
describe '.function_method' do
59+
describe '.function_method', type: :puppet_function do
8260
it 'accepts an injected scope' do
8361
expect(Puppet::Parser::Functions).to receive(:function).with('my_func').and_return(true)
84-
scope = instance_double(described_class.scope.to_s)
8562
expect(scope).to receive(:method).with(:function_my_func).and_return(:fake_method)
8663
expect(described_class.function_method('my_func', scope: scope)).to eq(:fake_method)
8764
end
8865

8966
it "returns nil if the function doesn't exist" do
9067
expect(Puppet::Parser::Functions).to receive(:function).with('my_func').and_return(false)
91-
scope = instance_double(described_class.scope.to_s)
9268
expect(described_class.function_method('my_func', scope: scope)).to be_nil
9369
end
9470
end

0 commit comments

Comments
 (0)