Skip to content

Commit da76515

Browse files
author
Jeff McCune
committed
Merge pull request #18 from jeffmccune/maint/master/add_puppet_internals_module
(Maint) Rename PuppetlabsSpec::Puppet{Seams,Internals}
2 parents a6bbde7 + 8bacc8f commit da76515

File tree

7 files changed

+130
-72
lines changed

7 files changed

+130
-72
lines changed

README.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ This will not work beyond Puppet 2.7 as we have changed the behavior of the
130130
scope initializer in Puppet 3.0. Modules should instead initialize scope
131131
instances in a manner decoupled from the internal behavior of Puppet:
132132

133-
require 'puppetlabs_spec_helper/puppetlabs_spec/puppet_seams'
133+
require 'puppetlabs_spec_helper/puppetlabs_spec/puppet_internals'
134134
describe "split()" do
135-
let(:scope) { PuppetlabsSpec::PuppetSeams.parser_scope }
135+
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
136136
it "should split 'one;two' on ';' into [ 'one', 'two' ]" do
137137
scope.function_split(['one;two', ';']).should == [ 'one', 'two' ]
138138
end

lib/puppetlabs_spec_helper/module_spec_helper.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
require 'rspec-puppet'
22
require 'puppetlabs_spec_helper/puppet_spec_helper'
3-
4-
# We need to require 'puppetlabs_spec_helper/puppetlabs_spec/puppet_seams' so
5-
# that all Puppet modules have easy access to
6-
# PuppetlabsSpec::PuppetSeams.new.scope_for_test_harness The expectation is
7-
# that all Puppet modules require puppetlabs_spec_helper/module_spec_helper
8-
require 'puppetlabs_spec_helper/puppetlabs_spec/puppet_seams'
3+
require 'puppetlabs_spec_helper/puppetlabs_spec/puppet_internals'
94

105
def param_value(subject, type, title, param)
116
subject.resource(type, title).send(:parameters)[param.to_sym]
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Initialize puppet for testing by loading the
2+
# 'puppetlabs_spec_helper/puppet_spec_helper' library
3+
require 'puppetlabs_spec_helper/puppet_spec_helper'
4+
5+
module PuppetlabsSpec
6+
module PuppetInternals
7+
# parser_scope is intended to return a Puppet::Parser::Scope
8+
# instance suitable for placing in a test harness with the intent of
9+
# testing parser functions from modules.
10+
def scope(parts = {})
11+
if Puppet.version =~ /^2\.[67]/
12+
# loadall should only be necessary prior to 3.x
13+
# Please note, loadall needs to happen first when creating a scope, otherwise
14+
# you might receive undefined method `function_*' errors
15+
Puppet::Parser::Functions.autoloader.loadall
16+
end
17+
18+
scope_compiler = parts[:compiler] || compiler
19+
scope_parent = parts[:parent] || scope_compiler.topscope
20+
scope_resource = parts[:resource] || resource(:type => :node, :title => scope_compiler.node.name)
21+
22+
if Puppet.version =~ /^2\.[67]/
23+
scope = Puppet::Parser::Scope.new(:compiler => scope_compiler)
24+
else
25+
scope = Puppet::Parser::Scope.new(scope_compiler)
26+
end
27+
28+
scope.source = Puppet::Resource::Type.new(:node, "foo")
29+
scope.parent = scope_parent
30+
scope
31+
end
32+
module_function :scope
33+
34+
def resource(parts = {})
35+
resource_type = parts[:type] || :hostclass
36+
resource_name = parts[:name] || "testing"
37+
Puppet::Resource::Type.new(resource_type, resource_name)
38+
end
39+
module_function :resource
40+
41+
def compiler(parts = {})
42+
compiler_node = parts[:node] || node()
43+
Puppet::Parser::Compiler.new(compiler_node)
44+
end
45+
module_function :compiler
46+
47+
def node(parts = {})
48+
node_name = parts[:name] || 'testinghost'
49+
node_environment = Puppet::Node::Environment.new(parts[:environment] || 'test')
50+
Puppet::Node.new(node_name) #, :environment => node_environment)
51+
end
52+
module_function :node
53+
end
54+
end

lib/puppetlabs_spec_helper/puppetlabs_spec/puppet_seams.rb

Lines changed: 0 additions & 30 deletions
This file was deleted.

lib/puppetlabs_spec_helper/puppetlabs_spec_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module PuppetlabsSpec
99
# Require all necessary helper libraries so they can be used later
1010
require 'puppetlabs_spec_helper/puppetlabs_spec/files'
1111
require 'puppetlabs_spec_helper/puppetlabs_spec/fixtures'
12-
require 'puppetlabs_spec_helper/puppetlabs_spec/puppet_seams'
12+
require 'puppetlabs_spec_helper/puppetlabs_spec/puppet_internals'
1313
require 'puppetlabs_spec_helper/puppetlabs_spec/matchers'
1414

1515
RSpec.configure do |config|
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#! /usr/bin/env ruby -S rspec
2+
3+
require 'puppetlabs_spec_helper/puppet_spec_helper'
4+
require 'puppetlabs_spec_helper/puppetlabs_spec/puppet_internals'
5+
6+
describe PuppetlabsSpec::PuppetInternals do
7+
describe ".scope" do
8+
it "should return a Puppet::Parser::Scope instance" do
9+
subject.scope.should be_a_kind_of Puppet::Parser::Scope
10+
end
11+
12+
it "should be suitable for function testing" do
13+
scope = subject.scope
14+
scope.function_split(["one;two", ";"]).should == [ 'one', 'two' ]
15+
end
16+
17+
it "should accept a compiler" do
18+
compiler = subject.compiler
19+
20+
scope = subject.scope(:compiler => compiler)
21+
22+
scope.compiler.should == compiler
23+
end
24+
25+
it "should have a source set" do
26+
scope = subject.scope
27+
28+
scope.source.should_not be_nil
29+
scope.source.should_not be_false
30+
end
31+
end
32+
33+
describe ".resource" do
34+
it "can have a defined type" do
35+
subject.resource(:type => :node).type.should == :node
36+
end
37+
38+
it "defaults to a type of hostclass" do
39+
subject.resource.type.should == :hostclass
40+
end
41+
42+
it "can have a defined name" do
43+
subject.resource(:name => "testingrsrc").name.should == "testingrsrc"
44+
end
45+
46+
it "defaults to a name of testing" do
47+
subject.resource.name.should == "testing"
48+
end
49+
end
50+
51+
describe ".compiler" do
52+
let(:node) { subject.node }
53+
54+
it "can have a defined node" do
55+
subject.compiler(:node => node).node.should be node
56+
end
57+
end
58+
59+
describe ".node" do
60+
it "can have a defined name" do
61+
subject.node(:name => "mine").name.should == "mine"
62+
end
63+
64+
it "can have a defined environment" do
65+
subject.node(:environment => "mine").environment.name.should == :mine
66+
end
67+
68+
it "defaults to a name of testinghost" do
69+
subject.node.name.should == "testinghost"
70+
end
71+
end
72+
end

spec/unit/puppetlabs_spec_helper/puppetlabs_spec/puppet_seams_spec.rb

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)