rspec-puppet 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,10 +6,6 @@ require 'rspec-puppet/matchers'
6
6
  require 'rspec-puppet/example'
7
7
  require 'rspec-puppet/setup'
8
8
 
9
- if Integer(Puppet.version.split('.').first) >= 3
10
- Puppet.initialize_settings
11
- end
12
-
13
9
  RSpec.configure do |c|
14
10
  c.add_setting :module_path, :default => '/etc/puppet/modules'
15
11
  c.add_setting :manifest_dir, :default => nil
@@ -31,7 +31,11 @@ module RSpec::Puppet
31
31
  end
32
32
 
33
33
  if self.respond_to? :pre_condition
34
- pre_cond = pre_condition
34
+ if pre_condition.kind_of?(Array)
35
+ pre_cond = pre_condition.join("\n")
36
+ else
37
+ pre_cond = pre_condition
38
+ end
35
39
  else
36
40
  pre_cond = ''
37
41
  end
@@ -39,7 +39,11 @@ module RSpec::Puppet
39
39
  end
40
40
 
41
41
  if self.respond_to? :pre_condition
42
- pre_cond = pre_condition
42
+ if pre_condition.kind_of?(Array)
43
+ pre_cond = pre_condition.join("\n")
44
+ else
45
+ pre_cond = pre_condition
46
+ end
43
47
  else
44
48
  pre_cond = ""
45
49
  end
@@ -11,17 +11,23 @@ module RSpec::Puppet
11
11
  Puppet[:modulepath] = self.respond_to?(:module_path) ? module_path : RSpec.configuration.module_path
12
12
  Puppet[:libdir] = Dir["#{Puppet[:modulepath]}/*/lib"].entries.join(File::PATH_SEPARATOR)
13
13
 
14
+ nodename = self.respond_to?(:node) ? node : Puppet[:certname]
15
+ facts_val = {
16
+ 'hostname' => nodename.split('.').first,
17
+ 'fqdn' => nodename,
18
+ 'domain' => nodename.split('.').last,
19
+ }
20
+ facts_val.merge!(munge_facts(facts)) if self.respond_to?(:facts)
21
+ facts_val.each { |k, v| Facter.add(k) { setcode { v } } }
22
+
14
23
  # if we specify a pre_condition, we should ensure that we compile that code
15
24
  # into a catalog that is accessible from the scope where the function is called
16
25
  if self.respond_to? :pre_condition
17
- Puppet[:code] = pre_condition
18
- nodename = self.respond_to?(:node) ? node : Puppet[:certname]
19
- facts_val = {
20
- 'hostname' => nodename.split('.').first,
21
- 'fqdn' => nodename,
22
- 'domain' => nodename.split('.').last,
23
- }
24
- facts_val.merge!(munge_facts(facts)) if self.respond_to?(:facts)
26
+ if pre_condition.kind_of?(Array)
27
+ Puppet[:code] = pre_condition.join("\n")
28
+ else
29
+ Puppet[:code] = pre_condition
30
+ end
25
31
  # we need to get a compiler, b/c we can attach that to a scope
26
32
  @compiler = build_compiler(nodename, facts_val)
27
33
  else
@@ -47,7 +47,7 @@ module RSpec::Puppet
47
47
  end
48
48
 
49
49
  failure_message_for_should do |func_obj|
50
- func_name = func_obj.name.gsub(/^function_/, '')
50
+ func_name = func_obj.name.to_s.gsub(/^function_/, '')
51
51
  func_params = @params.inspect[1..-2]
52
52
 
53
53
  if @expected_return
@@ -5,8 +5,14 @@ module RSpec::Puppet
5
5
 
6
6
  protected
7
7
  def build_catalog_without_cache(nodename, facts_val, code)
8
+ if Integer(Puppet.version.split('.').first) >= 3
9
+ Puppet.initialize_settings
10
+ end
11
+
8
12
  Puppet[:code] = code
9
13
 
14
+ facts_val.each { |k, v| Facter.add(k) { setcode { v } } }
15
+
10
16
  node_obj = Puppet::Node.new(nodename)
11
17
 
12
18
  node_obj.merge(facts_val)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'rspec-puppet'
3
- s.version = '0.1.5'
3
+ s.version = '0.1.6'
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'
@@ -13,7 +13,9 @@ end
13
13
 
14
14
  describe 'sysctl::before' do
15
15
  let(:title) { 'test define' }
16
- let(:pre_condition) { 'class {"sysctl::common":}' }
16
+ let(:pre_condition) {
17
+ [ '# we need sysctl common',
18
+ 'class {"sysctl::common":}' ] }
17
19
  let(:params) { { :value => "title" } }
18
20
 
19
21
  it { should create_resource("sysctl::before", 'test define')\
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-puppet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-03 00:00:00.000000000 Z
12
+ date: 2013-01-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec