rspec-puppet 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,4 @@
1
+ require 'rspec-puppet/support'
1
2
  require 'rspec-puppet/example/define_example_group'
2
3
  require 'rspec-puppet/example/class_example_group'
3
4
 
@@ -1,6 +1,7 @@
1
1
  module RSpec::Puppet
2
2
  module ClassExampleGroup
3
3
  include RSpec::Puppet::Matchers
4
+ include RSpec::Puppet::Support
4
5
 
5
6
  def subject
6
7
  @catalogue ||= catalogue
@@ -20,27 +21,24 @@ module RSpec::Puppet
20
21
  import_str = ""
21
22
  end
22
23
 
24
+ if self.respond_to? :pre_condition
25
+ pre_cond = pre_condition
26
+ else
27
+ pre_cond = ''
28
+ end
29
+
23
30
  if !self.respond_to?(:params) || params == {}
24
31
  Puppet[:code] = import_str + "include #{klass_name}"
25
32
  else
26
- Puppet[:code] = import_str + 'class' + " { " + klass_name + ": " + params.keys.map { |r| "#{r.to_s} => '#{params[r].to_s}'"
27
- }.join(', ') + " }"
33
+ Puppet[:code] = import_str + 'class' + " { \"" + klass_name + "\": " + params.keys.map { |r| "#{r.to_s} => #{params[r].inspect}"
34
+ }.join(',' ) + " }"
28
35
  end
36
+ Puppet[:code] = pre_cond + "\n" + Puppet[:code]
29
37
 
30
38
  nodename = self.respond_to?(:node) ? node : Puppet[:certname]
31
39
  facts_val = self.respond_to?(:facts) ? facts : {}
32
40
 
33
- node_obj = Puppet::Node.new(nodename)
34
-
35
- node_obj.merge(facts_val)
36
-
37
- # trying to be compatible with 2.7 as well as 2.6
38
- if Puppet::Resource::Catalog.respond_to? :find
39
- Puppet::Resource::Catalog.find(node_obj.name, :use_node => node_obj)
40
- else
41
- require 'puppet/face'
42
- Puppet::Face[:catalog, :current].find(node_obj.name, :use_node => node_obj)
43
- end
41
+ build_catalog(nodename, facts_val)
44
42
  end
45
43
  end
46
44
  end
@@ -1,6 +1,7 @@
1
1
  module RSpec::Puppet
2
2
  module DefineExampleGroup
3
3
  include RSpec::Puppet::Matchers
4
+ include RSpec::Puppet::Support
4
5
 
5
6
  def subject
6
7
  @catalogue ||= catalogue
@@ -22,13 +23,19 @@ module RSpec::Puppet
22
23
 
23
24
  if self.respond_to? :params
24
25
  param_str = params.keys.map { |r|
25
- "#{r.to_s} => \"#{params[r].to_s}\""
26
+ "#{r.to_s} => #{params[r].inspect}"
26
27
  }.join(', ')
27
28
  else
28
29
  param_str = ""
29
30
  end
30
31
 
31
- Puppet[:code] = import_str + define_name + " { \"" + title + "\": " + param_str + " }"
32
+ if self.respond_to? :pre_condition
33
+ pre_cond = pre_condition
34
+ else
35
+ pre_cond = ""
36
+ end
37
+
38
+ Puppet[:code] = pre_cond + "\n" + import_str + define_name + " { \"" + title + "\": " + param_str + " }"
32
39
 
33
40
  nodename = self.respond_to?(:node) ? node : Puppet[:certname]
34
41
  facts_val = {
@@ -37,17 +44,7 @@ module RSpec::Puppet
37
44
  }
38
45
  facts_val.merge!(facts) if self.respond_to?(:facts)
39
46
 
40
- node_obj = Puppet::Node.new(nodename)
41
-
42
- node_obj.merge(facts_val)
43
-
44
- # trying to be compatible with 2.7 as well as 2.6
45
- if Puppet::Resource::Catalog.respond_to? :find
46
- Puppet::Resource::Catalog.find(node_obj.name, :use_node => node_obj)
47
- else
48
- require 'puppet/face'
49
- Puppet::Face[:catalog, :current].find(node_obj.name, :use_node => node)
50
- end
47
+ build_catalog(nodename, facts_val)
51
48
  end
52
49
  end
53
50
  end
@@ -21,18 +21,14 @@ module RSpec::Puppet
21
21
 
22
22
  def matches?(catalogue)
23
23
  ret = true
24
- resources = catalogue.resources.select { |r|
25
- r.type == @referenced_type
26
- }.select { |r|
27
- r.title == @title if r.respond_to? :title
28
- }
24
+ resource = catalogue.resource(@referenced_type, @title)
29
25
 
30
- unless resources.length == 1
26
+ if resource.nil?
31
27
  ret = false
32
28
  else
33
29
  if @expected_params
34
30
  @expected_params.each do |name, value|
35
- unless resources.first.send(:parameters)[name.to_sym].to_s == value.to_s
31
+ unless resource.send(:parameters)[name.to_sym].to_s == value.to_s
36
32
  ret = false
37
33
  (@errors ||= []) << "#{name.to_s} set to `#{value.inspect}`"
38
34
  end
@@ -15,7 +15,7 @@ module RSpec::Puppet
15
15
  ret = false
16
16
  end
17
17
 
18
- if @expected_params
18
+ if @expected_params and resources.length != 0
19
19
  @expected_params.each do |name, value|
20
20
  unless resources.first.send(:parameters)[name.to_sym] == value
21
21
  ret = false
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'rspec-puppet'
3
- s.version = '0.0.3'
3
+ s.version = '0.0.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'
@@ -5,3 +5,10 @@ describe 'sysctl::common' do
5
5
  .with_command('/sbin/sysctl -p /etc/sysctl.conf').with_returns([0, 2]) }
6
6
  it { should_not create_augeas('foo') }
7
7
  end
8
+
9
+ describe 'sysctl::common' do
10
+ let(:params) { { :test_param => "yes" } }
11
+
12
+ it { should create_class("sysctl::common")\
13
+ .with_test_param("yes") }
14
+ end
@@ -1,4 +1,4 @@
1
- class sysctl::common {
1
+ class sysctl::common ($test_param = 'yes') {
2
2
  exec { 'sysctl/reload':
3
3
  command => '/sbin/sysctl -p /etc/sysctl.conf',
4
4
  refreshonly => true,
@@ -16,3 +16,24 @@ define sysctl($value) {
16
16
  notify => Exec['sysctl/reload'],
17
17
  }
18
18
  }
19
+
20
+ class boolean($bool) {
21
+ $real_bool = $bool ? {
22
+ true => false,
23
+ false => true,
24
+ }
25
+
26
+ if ($real_bool) {
27
+ notify {"bool testing":
28
+ message => "This will print when \$bool is false."
29
+ }
30
+ }
31
+ }
32
+
33
+ define sysctl::before($value) {
34
+ Class['sysctl::common'] -> Sysctl::Before[$name]
35
+
36
+ notify {"message-${name}":
37
+ message => "This should print if the class is here first."
38
+ }
39
+ }
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-puppet
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease:
4
+ prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 0
9
- - 3
10
- version: 0.0.3
8
+ - 4
9
+ version: 0.0.4
11
10
  platform: ruby
12
11
  authors:
13
12
  - Tim Sharpe
@@ -15,18 +14,16 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2011-07-21 00:00:00 +10:00
17
+ date: 2011-08-07 00:00:00 -07:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: rspec
23
22
  prerelease: false
24
23
  requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
24
  requirements:
27
25
  - - ">="
28
26
  - !ruby/object:Gem::Version
29
- hash: 3
30
27
  segments:
31
28
  - 0
32
29
  version: "0"
@@ -67,27 +64,23 @@ rdoc_options: []
67
64
  require_paths:
68
65
  - lib
69
66
  required_ruby_version: !ruby/object:Gem::Requirement
70
- none: false
71
67
  requirements:
72
68
  - - ">="
73
69
  - !ruby/object:Gem::Version
74
- hash: 3
75
70
  segments:
76
71
  - 0
77
72
  version: "0"
78
73
  required_rubygems_version: !ruby/object:Gem::Requirement
79
- none: false
80
74
  requirements:
81
75
  - - ">="
82
76
  - !ruby/object:Gem::Version
83
- hash: 3
84
77
  segments:
85
78
  - 0
86
79
  version: "0"
87
80
  requirements: []
88
81
 
89
82
  rubyforge_project:
90
- rubygems_version: 1.3.10
83
+ rubygems_version: 1.3.6
91
84
  signing_key:
92
85
  specification_version: 3
93
86
  summary: RSpec tests for your Puppet manifests