shadow_puppet 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -197,8 +197,8 @@ module ShadowPuppet
197
197
  def self.register_puppet_types
198
198
  Puppet::Type.loadall
199
199
  Puppet::Type.eachtype do |type|
200
- #undefine the method rdoc placeholders
201
- undef_method(type.name) rescue nil
200
+ #remove the method rdoc placeholders
201
+ remove_method(type.name) rescue nil
202
202
  define_method(type.name) do |*args|
203
203
  if args && args.flatten.size == 1
204
204
  reference(type.name, args.first)
@@ -0,0 +1,69 @@
1
+ module Puppet
2
+ module Parser
3
+ class Resource
4
+
5
+ # clearing out some puppet methods that we probably won't need for testing
6
+ # that are also used in the params hash when defining the resource.
7
+ undef path
8
+ undef source
9
+ undef require
10
+
11
+ # This allows access to resource options as methods on the resource.
12
+ def method_missing name, *args
13
+ if params.keys.include? name.to_sym
14
+ params[name.to_sym].value
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ module ShadowPuppet
22
+ # To test manifests, access puppet resources using the plural form of the resource name.
23
+ # This returns a hash of all resources of that type.
24
+ #
25
+ # manifest.execs
26
+ # manifest.packages
27
+ #
28
+ # You can access resource options as methods on the resource
29
+ #
30
+ # manifest.files['/etc/motd'].content
31
+ # manifest.execs['service ssh restart'].onlyif
32
+ #
33
+ # ===Example
34
+ #
35
+ # Given this manifest:
36
+ #
37
+ # class TestManifest < ShadowPuppet::Manifest
38
+ # def myrecipe
39
+ # file '/etc/motd', :content => 'Welcome to the machine!', :mode => '644'
40
+ # exec 'newaliases', :refreshonly => true
41
+ # end
42
+ # recipe :myrecipe
43
+ # end
44
+ #
45
+ # A test for the manifest could look like this:
46
+ #
47
+ # manifest = TestManifest.new
48
+ # manifest.myrecipe
49
+ # assert_match /Welcome/, manifest.files['/etc/motd']
50
+ # assert manifest.execs['newaliases'].refreshonly
51
+ #
52
+ class Manifest
53
+ # Creates an instance method for every puppet type
54
+ # that either creates or references a resource
55
+ def self.register_puppet_types_for_testing
56
+ Puppet::Type.loadall
57
+ Puppet::Type.eachtype do |type|
58
+ plural_type = type.name.to_s.downcase.pluralize
59
+ #undefine the method rdoc placeholders
60
+ undef_method(plural_type) rescue nil
61
+ define_method(plural_type) do |*args|
62
+ puppet_resources[type]
63
+ end
64
+ end
65
+ end
66
+ register_puppet_types_for_testing
67
+
68
+ end
69
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shadow_puppet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesse Newland
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-12 00:00:00 -04:00
12
+ date: 2009-03-12 00:00:00 -07:00
13
13
  default_executable: shadow_puppet
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -80,6 +80,7 @@ files:
80
80
  - lib/shadow_puppet.rb
81
81
  - lib/shadow_puppet/manifest.rb
82
82
  - lib/shadow_puppet/core_ext.rb
83
+ - lib/shadow_puppet/test.rb
83
84
  has_rdoc: true
84
85
  homepage: http://railsmachine.github.com/shadow_puppet
85
86
  post_install_message: