railsmachine-shadow_puppet 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/shadow_puppet/test.rb +69 -0
  2. metadata +2 -1
@@ -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: railsmachine-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
@@ -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: