rspec-puppet 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rspec-puppet/example/class_example_group.rb +4 -4
- data/lib/rspec-puppet/example/define_example_group.rb +2 -2
- data/lib/rspec-puppet/example/function_example_group.rb +28 -1
- data/lib/rspec-puppet/example/host_example_group.rb +2 -2
- data/lib/rspec-puppet/matchers/create_generic.rb +1 -1
- data/lib/rspec-puppet/support.rb +12 -1
- data/rspec-puppet.gemspec +1 -1
- data/spec/classes/sysctl_common_spec.rb +2 -2
- data/spec/functions/split_spec.rb +1 -1
- metadata +4 -4
@@ -34,12 +34,12 @@ module RSpec::Puppet
|
|
34
34
|
end
|
35
35
|
|
36
36
|
if !self.respond_to?(:params) || params == {}
|
37
|
-
|
37
|
+
code = import_str + "include #{klass_name}"
|
38
38
|
else
|
39
|
-
|
39
|
+
code = import_str + 'class' + " { \"" + klass_name + "\": " + params.keys.map { |r| "#{r.to_s} => #{params[r].inspect}"
|
40
40
|
}.join(',' ) + " }"
|
41
41
|
end
|
42
|
-
|
42
|
+
code = pre_cond + "\n" + code
|
43
43
|
|
44
44
|
nodename = self.respond_to?(:node) ? node : Puppet[:certname]
|
45
45
|
facts_val = {
|
@@ -49,7 +49,7 @@ module RSpec::Puppet
|
|
49
49
|
}
|
50
50
|
facts_val.merge!(munge_facts(facts)) if self.respond_to?(:facts)
|
51
51
|
|
52
|
-
build_catalog(nodename, facts_val)
|
52
|
+
build_catalog(nodename, facts_val, code)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
@@ -41,7 +41,7 @@ module RSpec::Puppet
|
|
41
41
|
pre_cond = ""
|
42
42
|
end
|
43
43
|
|
44
|
-
|
44
|
+
code = pre_cond + "\n" + import_str + define_name + " { \"" + title + "\": " + param_str + " }"
|
45
45
|
|
46
46
|
nodename = self.respond_to?(:node) ? node : Puppet[:certname]
|
47
47
|
facts_val = {
|
@@ -51,7 +51,7 @@ module RSpec::Puppet
|
|
51
51
|
}
|
52
52
|
facts_val.merge!(munge_facts(facts)) if self.respond_to?(:facts)
|
53
53
|
|
54
|
-
build_catalog(nodename, facts_val)
|
54
|
+
build_catalog(nodename, facts_val, code)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
@@ -9,9 +9,36 @@ module RSpec::Puppet
|
|
9
9
|
Puppet[:libdir] = Dir["#{Puppet[:modulepath]}/*/lib"].entries.join(File::PATH_SEPARATOR)
|
10
10
|
Puppet::Parser::Functions.autoloader.loadall
|
11
11
|
|
12
|
-
|
12
|
+
# if we specify a pre_condition, we should ensure that we compile that code
|
13
|
+
# into a catalog that is accessible from the scope where the function is called
|
14
|
+
if self.respond_to? :pre_condition
|
15
|
+
Puppet[:code] = pre_condition
|
16
|
+
nodename = self.respond_to?(:node) ? node : Puppet[:certname]
|
17
|
+
facts_val = {
|
18
|
+
'hostname' => nodename.split('.').first,
|
19
|
+
'fqdn' => nodename,
|
20
|
+
'domain' => nodename.split('.').last,
|
21
|
+
}
|
22
|
+
facts_val.merge!(munge_facts(facts)) if self.respond_to?(:facts)
|
23
|
+
# we need to get a compiler, b/c we can attach that to a scope
|
24
|
+
@compiler = build_compiler(nodename, facts_val)
|
25
|
+
else
|
26
|
+
@compiler = nil
|
27
|
+
end
|
28
|
+
|
29
|
+
scope = Puppet::Parser::Scope.new(:compiler => @compiler)
|
13
30
|
|
14
31
|
scope.method "function_#{function_name}".to_sym
|
15
32
|
end
|
33
|
+
|
34
|
+
def compiler
|
35
|
+
@compiler
|
36
|
+
end
|
37
|
+
# get a compiler with an attached compiled catalog
|
38
|
+
def build_compiler(node_name, fact_values)
|
39
|
+
compiler = Puppet::Parser::Compiler.new(Puppet::Node.new(node_name, :parameters => fact_values))
|
40
|
+
compiler.compile
|
41
|
+
compiler
|
42
|
+
end
|
16
43
|
end
|
17
44
|
end
|
@@ -13,7 +13,7 @@ module RSpec::Puppet
|
|
13
13
|
Puppet[:manifest] = self.respond_to?(:manifest) ? manifest : RSpec.configuration.manifest
|
14
14
|
Puppet[:templatedir] = self.respond_to?(:template_dir) ? template_dir : RSpec.configuration.template_dir
|
15
15
|
Puppet[:config] = self.respond_to?(:config) ? config : RSpec.configuration.config
|
16
|
-
|
16
|
+
code = ""
|
17
17
|
|
18
18
|
nodename = self.class.top_level_description.downcase
|
19
19
|
|
@@ -24,7 +24,7 @@ module RSpec::Puppet
|
|
24
24
|
}
|
25
25
|
facts_val.merge!(munge_facts(facts)) if self.respond_to?(:facts)
|
26
26
|
|
27
|
-
build_catalog(nodename, facts_val)
|
27
|
+
build_catalog(nodename, facts_val, code)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -51,7 +51,7 @@ module RSpec::Puppet
|
|
51
51
|
(@errors ||= []) << "#{name.to_s} matching `#{value.inspect}` but its value of `#{rsrc_hsh[name.to_sym].inspect}` does not"
|
52
52
|
end
|
53
53
|
elsif value.kind_of?(Array) then
|
54
|
-
unless rsrc_hsh[name.to_sym].join == value.join
|
54
|
+
unless Array(rsrc_hsh[name.to_sym]).flatten.join == value.flatten.join
|
55
55
|
ret = false
|
56
56
|
(@errors ||= []) << "#{name.to_s} set to `#{value.inspect}` but it is set to `#{rsrc_hsh[name.to_sym].inspect}` in the catalogue"
|
57
57
|
end
|
data/lib/rspec-puppet/support.rb
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
module RSpec::Puppet
|
2
2
|
module Support
|
3
|
-
|
3
|
+
|
4
|
+
@@cache = {}
|
5
|
+
|
6
|
+
protected
|
7
|
+
def build_catalog_without_cache(nodename, facts_val, code)
|
8
|
+
Puppet[:code] = code
|
9
|
+
|
4
10
|
node_obj = Puppet::Node.new(nodename)
|
5
11
|
|
6
12
|
node_obj.merge(facts_val)
|
@@ -13,6 +19,11 @@ module RSpec::Puppet
|
|
13
19
|
end
|
14
20
|
end
|
15
21
|
|
22
|
+
public
|
23
|
+
def build_catalog *args
|
24
|
+
@@cache[args] ||= self.build_catalog_without_cache(*args)
|
25
|
+
end
|
26
|
+
|
16
27
|
def munge_facts(facts)
|
17
28
|
output = {}
|
18
29
|
facts.keys.each { |key| output[key.to_s] = facts[key] }
|
data/rspec-puppet.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'rspec-puppet'
|
3
|
-
s.version = '0.1.
|
3
|
+
s.version = '0.1.4'
|
4
4
|
s.homepage = 'https://github.com/rodjek/rspec-puppet/'
|
5
5
|
s.summary = 'RSpec tests for your Puppet manifests'
|
6
6
|
s.description = 'RSpec tests for your Puppet manifests'
|
@@ -8,7 +8,7 @@ describe 'sysctl::common' do
|
|
8
8
|
it 'should fail if the parameter is not contained in the resource' do
|
9
9
|
expect do
|
10
10
|
subject.should contain_exec('sysctl/reload').with('foo' => 'bar')
|
11
|
-
end.
|
11
|
+
end.to raise_error(RSpec::Expectations::ExpectationNotMetError)
|
12
12
|
end
|
13
13
|
it 'should pass if the parameters are contained in the resource' do
|
14
14
|
subject.should contain_exec('sysctl/reload').with(
|
@@ -27,7 +27,7 @@ describe 'sysctl::common' do
|
|
27
27
|
it 'should fail if any of the parameter names are contained in the resource' do
|
28
28
|
expect do
|
29
29
|
subject.should contain_exec('sysctl/reload').without(['foo', 'returns'])
|
30
|
-
end.
|
30
|
+
end.to raise_error(RSpec::Expectations::ExpectationNotMetError)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -6,6 +6,6 @@ describe 'split' do
|
|
6
6
|
it { should_not run.with_params('foo').and_raise_error(Puppet::DevError) }
|
7
7
|
|
8
8
|
it 'something' do
|
9
|
-
expect { subject.call('foo') }.
|
9
|
+
expect { subject.call('foo') }.to raise_error(Puppet::ParseError)
|
10
10
|
end
|
11
11
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-puppet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 4
|
10
|
+
version: 0.1.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tim Sharpe
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-08-09 00:00:00 +10:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|