puppetlabs_spec_helper 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ 2012-08-14 Puppet Labs <info@puppetlabs.com> - 0.3.0
2
+ * Add PuppetInternals compatibility module for
3
+ scope, node, compiler, and functions
4
+ * Add rspec-puppet convention directories to rake tasks
5
+
1
6
  2012-07-05 Puppet Labs <info@puppetlabs.com> - 0.2.0
2
7
  * Fix integration with mocha-0.12.0
3
8
  * Fix coverage rake task
@@ -1,5 +1,6 @@
1
1
  require 'rspec-puppet'
2
2
  require 'puppetlabs_spec_helper/puppet_spec_helper'
3
+ require 'puppetlabs_spec_helper/puppetlabs_spec/puppet_internals'
3
4
 
4
5
  def param_value(subject, type, title, param)
5
6
  subject.resource(type, title).send(:parameters)[param.to_sym]
@@ -0,0 +1,68 @@
1
+ # Initialize puppet for testing by loading the
2
+ # 'puppetlabs_spec_helper/puppet_spec_helper' library
3
+ require 'puppetlabs_spec_helper/puppet_spec_helper'
4
+
5
+ module PuppetlabsSpec
6
+ module PuppetInternals
7
+ # parser_scope is intended to return a Puppet::Parser::Scope
8
+ # instance suitable for placing in a test harness with the intent of
9
+ # testing parser functions from modules.
10
+ def scope(parts = {})
11
+ if Puppet.version =~ /^2\.[67]/
12
+ # loadall should only be necessary prior to 3.x
13
+ # Please note, loadall needs to happen first when creating a scope, otherwise
14
+ # you might receive undefined method `function_*' errors
15
+ Puppet::Parser::Functions.autoloader.loadall
16
+ end
17
+
18
+ scope_compiler = parts[:compiler] || compiler
19
+ scope_parent = parts[:parent] || scope_compiler.topscope
20
+ scope_resource = parts[:resource] || resource(:type => :node, :title => scope_compiler.node.name)
21
+
22
+ if Puppet.version =~ /^2\.[67]/
23
+ scope = Puppet::Parser::Scope.new(:compiler => scope_compiler)
24
+ else
25
+ scope = Puppet::Parser::Scope.new(scope_compiler)
26
+ end
27
+
28
+ scope.source = Puppet::Resource::Type.new(:node, "foo")
29
+ scope.parent = scope_parent
30
+ scope
31
+ end
32
+ module_function :scope
33
+
34
+ def resource(parts = {})
35
+ resource_type = parts[:type] || :hostclass
36
+ resource_name = parts[:name] || "testing"
37
+ Puppet::Resource::Type.new(resource_type, resource_name)
38
+ end
39
+ module_function :resource
40
+
41
+ def compiler(parts = {})
42
+ compiler_node = parts[:node] || node()
43
+ Puppet::Parser::Compiler.new(compiler_node)
44
+ end
45
+ module_function :compiler
46
+
47
+ def node(parts = {})
48
+ node_name = parts[:name] || 'testinghost'
49
+ options = parts[:options] || {}
50
+ node_environment = Puppet::Node::Environment.new(parts[:environment] || 'test')
51
+ options.merge!({:environment => node_environment})
52
+ Puppet::Node.new(node_name, options)
53
+ end
54
+ module_function :node
55
+
56
+ # Return a method instance for a given function. This is primarily useful
57
+ # for rspec-puppet
58
+ def function_method(name, parts = {})
59
+ scope = parts[:scope] || scope()
60
+ # Ensure the method instance is defined by side-effect of checking if it
61
+ # exists. This is a hack, but at least it's a hidden hack and not an
62
+ # exposed hack.
63
+ return nil unless Puppet::Parser::Functions.function(name)
64
+ scope.method("function_#{name}".intern)
65
+ end
66
+ module_function :function_method
67
+ end
68
+ end
@@ -9,6 +9,7 @@ end
9
9
  # Require all necessary helper libraries so they can be used later
10
10
  require 'puppetlabs_spec_helper/puppetlabs_spec/files'
11
11
  require 'puppetlabs_spec_helper/puppetlabs_spec/fixtures'
12
+ require 'puppetlabs_spec_helper/puppetlabs_spec/puppet_internals'
12
13
  require 'puppetlabs_spec_helper/puppetlabs_spec/matchers'
13
14
 
14
15
  RSpec.configure do |config|
@@ -7,7 +7,7 @@ task :default => [:help]
7
7
  desc "Run spec tests on an existing fixtures directory"
8
8
  RSpec::Core::RakeTask.new(:spec_standalone) do |t|
9
9
  t.rspec_opts = ['--color']
10
- t.pattern = 'spec/{classes,defines,unit}/**/*_spec.rb'
10
+ t.pattern = 'spec/{classes,defines,unit,functions,hosts}/**/*_spec.rb'
11
11
  end
12
12
 
13
13
  desc "Generate code coverage information"
metadata CHANGED
@@ -1,135 +1,120 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: puppetlabs_spec_helper
3
- version: !ruby/object:Gem::Version
4
- hash: 23
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 2
9
- - 0
10
- version: 0.2.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Puppet Labs
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-07-06 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-08-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: rake
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
32
22
  type: :runtime
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: rspec
36
23
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
38
33
  none: false
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- hash: 43
43
- segments:
44
- - 2
45
- - 9
46
- - 0
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
47
37
  version: 2.9.0
48
38
  type: :runtime
49
- version_requirements: *id002
50
- - !ruby/object:Gem::Dependency
51
- name: mocha
52
39
  prerelease: false
53
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 2.9.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: mocha
48
+ requirement: !ruby/object:Gem::Requirement
54
49
  none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- hash: 61
59
- segments:
60
- - 0
61
- - 10
62
- - 5
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
63
53
  version: 0.10.5
64
54
  type: :runtime
65
- version_requirements: *id003
66
- - !ruby/object:Gem::Dependency
67
- name: rspec-puppet
68
55
  prerelease: false
69
- requirement: &id004 !ruby/object:Gem::Requirement
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.10.5
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec-puppet
64
+ requirement: !ruby/object:Gem::Requirement
70
65
  none: false
71
- requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- hash: 25
75
- segments:
76
- - 0
77
- - 1
78
- - 1
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
79
69
  version: 0.1.1
80
70
  type: :runtime
81
- version_requirements: *id004
82
- description: Contains rake tasks and a standard spec_helper for running spec tests on puppet modules
83
- email:
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 0.1.1
78
+ description: Contains rake tasks and a standard spec_helper for running spec tests
79
+ on puppet modules
80
+ email:
84
81
  - puppet-dev@puppetlabs.com
85
82
  executables: []
86
-
87
83
  extensions: []
88
-
89
84
  extra_rdoc_files: []
90
-
91
- files:
85
+ files:
92
86
  - lib/puppetlabs_spec_helper/module_spec_helper.rb
93
87
  - lib/puppetlabs_spec_helper/puppet_spec_helper.rb
94
88
  - lib/puppetlabs_spec_helper/puppetlabs_spec/files.rb
95
89
  - lib/puppetlabs_spec_helper/puppetlabs_spec/fixtures.rb
96
90
  - lib/puppetlabs_spec_helper/puppetlabs_spec/matchers.rb
91
+ - lib/puppetlabs_spec_helper/puppetlabs_spec/puppet_internals.rb
97
92
  - lib/puppetlabs_spec_helper/puppetlabs_spec_helper.rb
98
93
  - lib/puppetlabs_spec_helper/rake_tasks.rb
99
94
  - LICENSE
100
95
  - CHANGELOG
101
96
  homepage: http://github.com/puppetlabs/puppetlabs_spec_helper
102
97
  licenses: []
103
-
104
98
  post_install_message:
105
99
  rdoc_options: []
106
-
107
- require_paths:
100
+ require_paths:
108
101
  - lib
109
- required_ruby_version: !ruby/object:Gem::Requirement
102
+ required_ruby_version: !ruby/object:Gem::Requirement
110
103
  none: false
111
- requirements:
112
- - - ">="
113
- - !ruby/object:Gem::Version
114
- hash: 3
115
- segments:
116
- - 0
117
- version: "0"
118
- required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
109
  none: false
120
- requirements:
121
- - - ">="
122
- - !ruby/object:Gem::Version
123
- hash: 3
124
- segments:
125
- - 0
126
- version: "0"
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
127
114
  requirements: []
128
-
129
115
  rubyforge_project:
130
116
  rubygems_version: 1.8.24
131
117
  signing_key:
132
118
  specification_version: 3
133
119
  summary: Standard tasks and configuration for module spec tests
134
120
  test_files: []
135
-