rspec-puppet 2.3.2 → 2.4.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 320021848da7cb4b21717e49b02ce505a6d507a9
4
- data.tar.gz: 132dc40418a858f94d097a9342bfdfc108cb7976
3
+ metadata.gz: 09f6ee077554387daa2811aecd6d308670c50693
4
+ data.tar.gz: c9c666f424696d2a649b0d034fcc645bb8cd1daf
5
5
  SHA512:
6
- metadata.gz: 3819322db7dbab18f6e943c21345aa26584bb7a2916aade4894b73af8e1a99a10cab204faf20ef6b31a26247845af3366872a4402d64acd89c3b3297f8ac0dac
7
- data.tar.gz: d564f7fc7f190f224f89a4ca4496e3892dc555dc067070a9f943bfa2601d78069979f05985b876eb94cf055125cb27bd75a6bb96cc849339c1787d9eff829cf0
6
+ metadata.gz: 9ee25b36e54a9d9fda26f4b1e2d876ee87dbf783a7f216c57c7fbbeae1550a006178edc9358748c6e703b8629a2d0971217c46f6106dddd1f96ed978a3c8c2cd
7
+ data.tar.gz: 3083ad10c6066c73da20e5a15a6befbe7f4f54451913046be9a0791c5d52f43f2b346c2d0b52c3551f3f976bd6015149a1d6bb52ffe55a7b448e75acf6bdb59e
data/CHANGELOG.md CHANGED
@@ -2,6 +2,25 @@
2
2
  All notable changes to this project will be documented in this file. This
3
3
  project adheres to [Semantic Versioning](http://semver.org/).
4
4
 
5
+ ## [2.4.0]
6
+
7
+ This release now supports testing exported resources in the same way that normal resources in the catalog are tested. Access them in your examples using `exported_resources`. See "Testing Exported Resources" in the README for examples.
8
+
9
+ ### Changed
10
+
11
+ * This release pulls out much of the version-specific code into separate classes to reduce complexity and enable easier maintenance going forward.
12
+
13
+ ### Added
14
+
15
+ * Support colon-separated module_path and environmentpath values.
16
+ * Support a threshold for the code coverage test, that can fail the whole run.
17
+ * Ensure a consistent environment for all examples by adding a forced initialization of puppet before each.
18
+
19
+ ### Credits
20
+
21
+ Thanks to Adrien Thebo, Arthur Gautier, Brett Gray, and Nicholas Hinds, as well as all the folks helping out on github for their contributions to this release.
22
+
23
+
5
24
  ## [2.3.2]
6
25
 
7
26
  Properly fix yesterday's issue by unsharing the cache key before passing the data to puppet. This also contains a new test matrix to avoid missing a half-baked fix like yesterday.
@@ -95,7 +114,8 @@ Thanks to Adrien Thebo, Alex Harvey, Brian, Dan Bode, Dominic Cleal, Javier Pala
95
114
  ## 1.0.1 and earlier
96
115
  For changelog of versions 1.0.1 and earlier, see http://rspec-puppet.com/changelog/
97
116
 
98
- [2.x]: https://github.com/rodjek/rspec-puppet/compare/v2.3.0...master
117
+ [2.x]: https://github.com/rodjek/rspec-puppet/compare/v2.4.0...master
118
+ [2.4.0]: https://github.com/rodjek/rspec-puppet/compare/v2.3.2...v2.4.0
99
119
  [2.3.2]: https://github.com/rodjek/rspec-puppet/compare/v2.3.1...v2.3.2
100
120
  [2.3.1]: https://github.com/rodjek/rspec-puppet/compare/v2.3.0...v2.3.1
101
121
  [2.3.0]: https://github.com/rodjek/rspec-puppet/compare/v2.2.0...v2.3.0
data/README.md CHANGED
@@ -429,6 +429,27 @@ However, if you want to specify it in each example, you can do so
429
429
  let(:module_path) { '/path/to/your/module/dir' }
430
430
  ```
431
431
 
432
+ #### Testing Exported Resources
433
+
434
+ You can test if a resource was exported from the catalogue by using the
435
+ `exported_resources` accessor in combination with any of the standard matchers.
436
+
437
+ You can use `exported_resources` as the subject of a child context:
438
+
439
+ ```ruby
440
+ context 'exported resources' do
441
+ subject { exported_resources }
442
+
443
+ it { is_expected.to contain_file('foo') }
444
+ end
445
+ ```
446
+
447
+ You can also use `exported_resources` directly in a test:
448
+
449
+ ```ruby
450
+ it { expect(exported_resources).to contain_file('foo') }
451
+ ```
452
+
432
453
  ## Functions
433
454
 
434
455
  ### Matchers
@@ -601,16 +622,30 @@ spec/fixtures/hiera/hiera.yaml
601
622
  ## Producing coverage reports
602
623
 
603
624
  You can output a basic resource coverage report with the following in
604
- you spec file.
625
+ your `spec_helper.rb`
605
626
 
606
627
  ```ruby
607
- at_exit { RSpec::Puppet::Coverage.report! }
628
+ RSpec.configure do |c|
629
+ c.after(:suite) do
630
+ RSpec::Puppet::Coverage.report!
631
+ end
632
+ end
608
633
  ```
609
634
 
610
635
  This checks which Puppet resources have been explicitly checked as part
611
636
  of the current test run and outputs both a coverage percentage and a
612
637
  list of untouched resources.
613
638
 
639
+ A desired code coverage level can be provided. If this level is not achieved, a test failure will be raised. This can be used with a CI service, such as Jenkins or Bamboo, to enforce code coverage. The following example requires the code coverage to be at least 95%.
640
+
641
+ ```ruby
642
+ RSpec.configure do |c|
643
+ c.after(:suite) do
644
+ RSpec::Puppet::Coverage.report!(95)
645
+ end
646
+ end
647
+ ```
648
+
614
649
  ## Related projects
615
650
 
616
651
  * [puppetlabs_spec_helper](https://github.com/puppetlabs/puppetlabs_spec_helper): shared spec helpers to setup puppet
data/lib/rspec-puppet.rb CHANGED
@@ -7,6 +7,7 @@ require 'rspec-puppet/matchers'
7
7
  require 'rspec-puppet/example'
8
8
  require 'rspec-puppet/setup'
9
9
  require 'rspec-puppet/coverage'
10
+ require 'rspec-puppet/adapters'
10
11
 
11
12
  begin
12
13
  require 'puppet/test/test_helper'
@@ -28,6 +29,7 @@ RSpec.configure do |c|
28
29
  c.add_setting :ordering, :default => 'title-hash'
29
30
  c.add_setting :stringify_facts, :default => true
30
31
  c.add_setting :strict_variables, :default => false
32
+ c.add_setting :adapter
31
33
 
32
34
  if defined?(Puppet::Test::TestHelper)
33
35
  begin
@@ -64,4 +66,12 @@ RSpec.configure do |c|
64
66
  end
65
67
  end
66
68
  end
69
+
70
+ c.before :each do
71
+ if self.class.ancestors.include? RSpec::Puppet::Support
72
+ @adapter = RSpec::Puppet::Adapters.get
73
+ @adapter.setup_puppet(self)
74
+ c.adapter = adapter
75
+ end
76
+ end
67
77
  end
@@ -0,0 +1,212 @@
1
+ module RSpec::Puppet
2
+ module Adapters
3
+
4
+ class Base
5
+ # Set up all Puppet settings applicable for this Puppet version
6
+ #
7
+ # @param example_group [RSpec::Core::ExampleGroup] The RSpec context to use for local settings
8
+ # @return [void]
9
+ def setup_puppet(example_group)
10
+ settings_map.each do |puppet_setting, rspec_setting|
11
+ set_setting(example_group, puppet_setting, rspec_setting)
12
+ end
13
+ @environment_name = example_group.environment
14
+ end
15
+
16
+ # Set up a specific Puppet setting.
17
+ # configuration setting.
18
+ #
19
+ # Puppet setting values can be taken from the global RSpec configuration, or from the currently
20
+ # executing RSpec context. When a setting is specified both in the global configuration and in
21
+ # the example group, the setting in the example group is preferred.
22
+ #
23
+ # @example Configuring a Puppet setting from a global RSpec configuration value
24
+ # RSpec.configure do |config|
25
+ # config.parser = "future"
26
+ # end
27
+ # # => Puppet[:parser] will be future
28
+ #
29
+ # @example Configuring a Puppet setting from within an RSpec example group
30
+ # RSpec.describe 'my_module::my_class', :type => :class do
31
+ # let(:module_path) { "/Users/luke/modules" }
32
+ # #=> Puppet[:modulepath] will be "/Users/luke/modules"
33
+ # end
34
+ #
35
+ # @example Configuring a Puppet setting with both a global RSpec configuration and local context
36
+ # RSpec.configure do |config|
37
+ # config.confdir = "/etc/puppet"
38
+ # end
39
+ # RSpec.describe 'my_module', :type => :class do
40
+ # # Puppet[:confdir] will be "/etc/puppet"
41
+ # end
42
+ # RSpec.describe 'my_module::my_class', :type => :class do
43
+ # let(:confdir) { "/etc/puppetlabs/puppet" }
44
+ # # => Puppet[:confdir] will be "/etc/puppetlabs/puppet" in this example group
45
+ # end
46
+ # RSpec.describe 'my_module::my_define', :type => :define do
47
+ # # Puppet[:confdir] will be "/etc/puppet" again
48
+ # end
49
+ #
50
+ # @param example_group [RSpec::Core::ExampleGroup] The RSpec context to use for local settings
51
+ # @param puppet_setting [Symbol] The name of the Puppet setting to configure
52
+ # @param rspec_setting [Symbol] The name of the RSpec context specific or global setting to use
53
+ # @return [void]
54
+ def set_setting(example_group, puppet_setting, rspec_setting)
55
+ if example_group.respond_to?(rspec_setting)
56
+ value = example_group.send(rspec_setting)
57
+ else
58
+ value = RSpec.configuration.send(rspec_setting)
59
+ end
60
+ begin
61
+ Puppet[puppet_setting] = value
62
+ rescue ArgumentError
63
+ # TODO: this silently swallows errors when applying settings that the current
64
+ # Puppet version does not accept, which means that user specified settings
65
+ # are ignored. This may lead to suprising behavior for users.
66
+ end
67
+ end
68
+
69
+ def catalog(node, exported)
70
+ if exported
71
+ # Use the compiler directly to skip the filtering done by the indirector
72
+ Puppet::Parser::Compiler.compile(node).filter { |r| !r.exported? }
73
+ else
74
+ Puppet::Resource::Catalog.indirection.find(node.name, :use_node => node)
75
+ end
76
+ end
77
+
78
+ def current_environment
79
+ Puppet::Node::Environment.new(@environment_name)
80
+ end
81
+
82
+ def settings_map
83
+ [
84
+ [:modulepath, :module_path],
85
+ [:config, :config],
86
+ [:confdir, :confdir],
87
+ ]
88
+ end
89
+
90
+ def modulepath
91
+ Puppet[:modulepath].split(File::PATH_SEPARATOR)
92
+ end
93
+
94
+ # @return [String, nil] The path to the Puppet manifest if it is present and set, nil otherwise.
95
+ def manifest
96
+ Puppet[:manifest]
97
+ end
98
+ end
99
+
100
+ class Adapter4X < Base
101
+ def setup_puppet(example_group)
102
+ super
103
+
104
+ if rspec_modulepath = RSpec.configuration.module_path
105
+ modulepath = rspec_modulepath.split(File::PATH_SEPARATOR)
106
+ else
107
+ modulepath = Puppet[:environmentpath].split(File::PATH_SEPARATOR).map do |path|
108
+ File.join(path, 'fixtures', 'modules')
109
+ end
110
+ end
111
+
112
+ if rspec_manifest = RSpec.configuration.manifest
113
+ manifest = rspec_manifest
114
+ else
115
+ manifest_paths = Puppet[:environmentpath].split(File::PATH_SEPARATOR).map do |path|
116
+ File.join(path, 'fixtures', 'manifests')
117
+ end
118
+
119
+ manifest = manifest_paths.find do |path|
120
+ File.exist?(path)
121
+ end
122
+
123
+ manifest ||= Puppet::Node::Environment::NO_MANIFEST
124
+ end
125
+
126
+ env = Puppet::Node::Environment.create(@environment_name, modulepath, manifest)
127
+ loader = Puppet::Environments::Static.new(env)
128
+
129
+ Puppet.push_context(
130
+ {
131
+ :environments => loader,
132
+ :current_environment => env
133
+ },
134
+ "Setup rspec-puppet environments"
135
+ )
136
+ end
137
+
138
+ def settings_map
139
+ super.concat([
140
+ [:environmentpath, :environmentpath],
141
+ [:hiera_config, :hiera_config],
142
+ [:strict_variables, :strict_variables],
143
+ ])
144
+ end
145
+
146
+ def catalog(node, exported)
147
+ node.environment = current_environment
148
+ super
149
+ end
150
+
151
+ def current_environment
152
+ Puppet.lookup(:current_environment)
153
+ end
154
+
155
+ def modulepath
156
+ current_environment.modulepath
157
+ end
158
+
159
+ # Puppet 4.0 specially handles environments that don't have a manifest set, so we check for the no manifest value
160
+ # and return nil when it is set.
161
+ #
162
+ # @return [String, nil] The path to the Puppet manifest if it is present and set, nil otherwise.
163
+ def manifest
164
+ m = current_environment.manifest
165
+ if m == Puppet::Node::Environment::NO_MANIFEST
166
+ nil
167
+ else
168
+ m
169
+ end
170
+ end
171
+ end
172
+
173
+ class Adapter3X < Base
174
+ def settings_map
175
+ super.concat([
176
+ [:manifestdir, :manifest_dir],
177
+ [:manifest, :manifest],
178
+ [:templatedir, :template_dir],
179
+ [:hiera_config, :hiera_config],
180
+ [:parser, :parser],
181
+ [:trusted_node_data, :trusted_node_data],
182
+ [:ordering, :ordering],
183
+ [:stringify_facts, :stringify_facts],
184
+ [:strict_variables, :strict_variables],
185
+ ])
186
+ end
187
+ end
188
+
189
+ class Adapter27 < Base
190
+ def settings_map
191
+ super.concat([
192
+ [:manifestdir, :manifest_dir],
193
+ [:manifest, :manifest],
194
+ [:templatedir, :template_dir],
195
+ ])
196
+ end
197
+ end
198
+
199
+ def self.get
200
+ [
201
+ [4.0, Adapter4X],
202
+ [3.0, Adapter3X],
203
+ [2.7, Adapter27]
204
+ ].each do |(version, klass)|
205
+ if Puppet.version.to_f >= version
206
+ return klass.new
207
+ end
208
+ end
209
+ raise "Puppet version #{Puppet.version.to_f} is not supported."
210
+ end
211
+ end
212
+ end
@@ -7,9 +7,13 @@ module RSpec::Puppet
7
7
  extend Forwardable
8
8
  def_delegators(:instance, :add, :cover!, :report!,
9
9
  :filters, :add_filter, :add_from_catalog)
10
- end
11
10
 
12
- include Singleton
11
+ attr_writer :instance
12
+
13
+ def instance
14
+ @instance ||= new
15
+ end
16
+ end
13
17
 
14
18
  def initialize
15
19
  @collection = {}
@@ -44,18 +48,8 @@ module RSpec::Puppet
44
48
  end
45
49
  end
46
50
 
47
- def report!
48
- report = {}
49
-
50
- report[:total] = @collection.size
51
- report[:touched] = @collection.count { |_, resource| resource.touched? }
52
- report[:untouched] = report[:total] - report[:touched]
53
- report[:coverage] = sprintf("%5.2f", ((report[:touched].to_f/report[:total].to_f)*100))
54
-
55
- report[:detailed] = Hash[*@collection.map do |name, wrapper|
56
- [name, wrapper.to_hash]
57
- end.flatten]
58
-
51
+ def report!(coverage_desired = nil)
52
+ report = results
59
53
  puts <<-EOH.gsub(/^ {8}/, '')
60
54
 
61
55
  Total resources: #{report[:total]}
@@ -68,16 +62,48 @@ module RSpec::Puppet
68
62
  Untouched resources:
69
63
 
70
64
  #{
71
- untouched_resources = report[:detailed].reject do |_,rsrc|
72
- rsrc["touched"]
65
+ untouched_resources = report[:resources].reject do |_,rsrc|
66
+ rsrc[:touched]
73
67
  end
74
68
  untouched_resources.inject([]) do |memo, (name,_)|
75
69
  memo << " #{name}"
76
70
  end.sort.join("\n")
77
71
  }
78
72
  EOH
73
+ if coverage_desired
74
+ coverage_test(coverage_desired, report[:coverage])
75
+ end
76
+ end
77
+ end
78
+
79
+ def coverage_test(coverage_desired, coverage_actual)
80
+ if coverage_desired.is_a?(Numeric) && coverage_desired.to_f <= 100.00 && coverage_desired.to_f >= 0.0
81
+ coverage_test = RSpec.describe("Code coverage.")
82
+ coverage_results = coverage_test.example("Must be at least #{coverage_desired}% of code coverage") {
83
+ expect( coverage_actual.to_f ).to be >= coverage_desired.to_f
84
+ }
85
+ coverage_test.run
86
+ passed = coverage_results.execution_result.status == :passed
87
+
88
+ RSpec.configuration.reporter.example_failed coverage_results unless passed
89
+ else
90
+ puts "The desired coverage must be 0 <= x <= 100, not '#{coverage_desired.inspect}'"
79
91
  end
92
+ end
93
+
94
+ def results
95
+ report = {}
96
+
97
+ report[:total] = @collection.size
98
+ report[:touched] = @collection.count { |_, resource| resource.touched? }
99
+ report[:untouched] = report[:total] - report[:touched]
100
+ report[:coverage] = "%5.2f" % ((report[:touched].to_f / report[:total].to_f) * 100)
101
+
102
+ report[:resources] = Hash[*@collection.map do |name, wrapper|
103
+ [name, wrapper.to_hash]
104
+ end.flatten]
80
105
 
106
+ report
81
107
  end
82
108
 
83
109
  private
@@ -122,16 +148,11 @@ module RSpec::Puppet
122
148
  #
123
149
  # @return [Array<String>]
124
150
  def module_paths(test_module)
125
- if Puppet.version.to_f >= 4.0
126
- modulepath = RSpec.configuration.module_path || File.join(Puppet[:environmentpath], 'fixtures', 'modules')
127
- manifest = RSpec.configuration.manifest || File.join(Puppet[:environmentpath], 'fixtures', 'manifests', 'site.pp')
128
- paths = [File.join(modulepath, test_module, 'manifests'), manifest]
129
- else
130
- paths = Puppet[:modulepath].split(File::PATH_SEPARATOR).map do |dir|
131
- File.join(dir, test_module, 'manifests')
132
- end
133
- paths << Puppet[:manifest]
151
+ adapter = RSpec.configuration.adapter
152
+ paths = adapter.modulepath.map do |dir|
153
+ File.join(dir, test_module, 'manifests')
134
154
  end
155
+ paths << adapter.manifest if adapter.manifest
135
156
  paths
136
157
  end
137
158
 
@@ -156,7 +177,7 @@ module RSpec::Puppet
156
177
 
157
178
  def to_hash
158
179
  {
159
- 'touched' => touched?,
180
+ :touched => touched?,
160
181
  }
161
182
  end
162
183
 
@@ -7,6 +7,10 @@ module RSpec::Puppet
7
7
  @catalogue ||= load_catalogue(:class)
8
8
  end
9
9
 
10
+ def exported_resources
11
+ lambda { load_catalogue(:class, true) }
12
+ end
13
+
10
14
  def rspec_puppet_cleanup
11
15
  @catalogue = nil
12
16
  end
@@ -7,6 +7,10 @@ module RSpec::Puppet
7
7
  @catalogue ||= load_catalogue(:define)
8
8
  end
9
9
 
10
+ def exported_resources
11
+ lambda { load_catalogue(:define, true) }
12
+ end
13
+
10
14
  def rspec_puppet_cleanup
11
15
  @catalogue = nil
12
16
  end
@@ -10,7 +10,7 @@ module RSpec::Puppet
10
10
  vardir = setup_puppet
11
11
 
12
12
  if Puppet.version.to_f >= 4.0
13
- env = build_4x_environment(environment)
13
+ env = adapter.current_environment
14
14
  loader = Puppet::Pops::Loaders.new(env)
15
15
  func = loader.private_environment_loader.load(:function,function_name)
16
16
  return func if func
@@ -87,11 +87,7 @@ module RSpec::Puppet
87
87
  end
88
88
 
89
89
  def build_node(name, opts = {})
90
- if Puppet.version.to_f >= 4.0
91
- node_environment = build_4x_environment(environment)
92
- else
93
- node_environment = Puppet::Node::Environment.new(environment)
94
- end
90
+ node_environment = adapter.current_environment
95
91
  opts.merge!({:environment => node_environment})
96
92
  Puppet::Node.new(name, opts)
97
93
  end
@@ -7,6 +7,10 @@ module RSpec::Puppet
7
7
  @catalogue ||= load_catalogue(:host)
8
8
  end
9
9
 
10
+ def exported_resources
11
+ lambda { load_catalogue(:host, true) }
12
+ end
13
+
10
14
  def rspec_puppet_cleanup
11
15
  @catalogue = nil
12
16
  end
@@ -1,4 +1,6 @@
1
1
  require 'rspec-puppet/cache'
2
+ require 'rspec-puppet/adapters'
3
+
2
4
  module RSpec::Puppet
3
5
  module Support
4
6
 
@@ -12,7 +14,7 @@ module RSpec::Puppet
12
14
  'rp_env'
13
15
  end
14
16
 
15
- def load_catalogue(type)
17
+ def load_catalogue(type, exported = false)
16
18
  vardir = setup_puppet
17
19
 
18
20
  if Puppet.version.to_f >= 4.0 or Puppet[:parser] == 'future'
@@ -25,7 +27,7 @@ module RSpec::Puppet
25
27
 
26
28
  hiera_config_value = self.respond_to?(:hiera_config) ? hiera_config : nil
27
29
 
28
- catalogue = build_catalog(node_name, facts_hash(node_name), hiera_config_value, code)
30
+ catalogue = build_catalog(node_name, facts_hash(node_name), hiera_config_value, code, exported)
29
31
 
30
32
  test_module = class_name.split('::').first
31
33
  RSpec::Puppet::Coverage.add_filter(type.to_s, self.class.description)
@@ -37,7 +39,7 @@ module RSpec::Puppet
37
39
 
38
40
  def import_str
39
41
  import_str = ""
40
- Puppet[:modulepath].split(File::PATH_SEPARATOR).each { |d|
42
+ adapter.modulepath.each { |d|
41
43
  if File.exists?(File.join(d, 'manifests', 'init.pp'))
42
44
  path_to_manifest = File.join([
43
45
  d,
@@ -51,7 +53,7 @@ module RSpec::Puppet
51
53
  ].join("\n")
52
54
  break
53
55
  elsif File.exists?(d)
54
- import_str = "import '#{Puppet[:manifest]}'\n"
56
+ import_str = "import '#{adapter.manifest}'\n"
55
57
  break
56
58
  end
57
59
  }
@@ -136,50 +138,7 @@ module RSpec::Puppet
136
138
  vardir = Dir.mktmpdir
137
139
  Puppet[:vardir] = vardir
138
140
 
139
- if Puppet.version.to_f >= 4.0
140
- settings = [
141
- [:modulepath, :module_path],
142
- [:environmentpath, :environmentpath],
143
- [:config, :config],
144
- [:confdir, :confdir],
145
- [:hiera_config, :hiera_config],
146
- [:strict_variables, :strict_variables],
147
- ]
148
- elsif Puppet.version.to_f >= 3.0
149
- settings = [
150
- [:modulepath, :module_path],
151
- [:manifestdir, :manifest_dir],
152
- [:manifest, :manifest],
153
- [:templatedir, :template_dir],
154
- [:config, :config],
155
- [:confdir, :confdir],
156
- [:hiera_config, :hiera_config],
157
- [:parser, :parser],
158
- [:trusted_node_data, :trusted_node_data],
159
- [:ordering, :ordering],
160
- [:stringify_facts, :stringify_facts],
161
- [:strict_variables, :strict_variables],
162
- ]
163
- else
164
- settings = [
165
- [:modulepath, :module_path],
166
- [:manifestdir, :manifest_dir],
167
- [:manifest, :manifest],
168
- [:templatedir, :template_dir],
169
- [:config, :config],
170
- [:confdir, :confdir],
171
- ]
172
- end
173
- settings.each do |a,b|
174
- value = self.respond_to?(b) ? self.send(b) : RSpec.configuration.send(b)
175
- begin
176
- Puppet[a] = value
177
- rescue ArgumentError
178
- Puppet.settings.setdefaults(:main, {a => {:default => value, :desc => a.to_s}})
179
- end
180
- end
181
-
182
- Puppet[:modulepath].split(File::PATH_SEPARATOR).map do |d|
141
+ adapter.modulepath.map do |d|
183
142
  Dir["#{d}/*/lib"].entries
184
143
  end.flatten.each do |lib|
185
144
  $LOAD_PATH << lib
@@ -188,7 +147,7 @@ module RSpec::Puppet
188
147
  vardir
189
148
  end
190
149
 
191
- def build_catalog_without_cache(nodename, facts_val, hiera_config_val, code)
150
+ def build_catalog_without_cache(nodename, facts_val, hiera_config_val, code, exported)
192
151
 
193
152
  # If we're going to rebuild the catalog, we should clear the cached instance
194
153
  # of Hiera that Puppet is using. This opens the possibility of the catalog
@@ -207,19 +166,7 @@ module RSpec::Puppet
207
166
 
208
167
  node_obj = Puppet::Node.new(nodename, { :parameters => facts_val, :facts => node_facts })
209
168
 
210
- # trying to be compatible with 2.7 as well as 2.6
211
- if Puppet::Resource::Catalog.respond_to? :find
212
- Puppet::Resource::Catalog.find(node_obj.name, :use_node => node_obj)
213
- elsif Puppet.version.to_f >= 4.0
214
- env = build_4x_environment(environment)
215
- loader = Puppet::Environments::Static.new(env)
216
- Puppet.override({:environments => loader}, 'Setup test environment') do
217
- node_obj.environment = env
218
- Puppet::Resource::Catalog.indirection.find(node_obj.name, :use_node => node_obj)
219
- end
220
- else
221
- Puppet::Resource::Catalog.indirection.find(node_obj.name, :use_node => node_obj)
222
- end
169
+ adapter.catalog(node_obj, exported)
223
170
  end
224
171
 
225
172
  def stub_facts!(facts)
@@ -259,10 +206,9 @@ module RSpec::Puppet
259
206
  end
260
207
  end
261
208
 
262
- def build_4x_environment(name)
263
- modulepath = RSpec.configuration.module_path || File.join(Puppet[:environmentpath], 'fixtures', 'modules')
264
- manifest = RSpec.configuration.manifest || File.join(Puppet[:environmentpath], 'fixtures', 'manifests')
265
- Puppet::Node::Environment.create(name, [modulepath], manifest)
266
- end
209
+ # @!attribute [r] adapter
210
+ # @api private
211
+ # @return [Class < RSpec::Puppet::Adapters::Base]
212
+ attr_accessor :adapter
267
213
  end
268
214
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-puppet
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.2
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Sharpe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-26 00:00:00.000000000 Z
11
+ date: 2016-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -35,6 +35,7 @@ files:
35
35
  - README.md
36
36
  - bin/rspec-puppet-init
37
37
  - lib/rspec-puppet.rb
38
+ - lib/rspec-puppet/adapters.rb
38
39
  - lib/rspec-puppet/cache.rb
39
40
  - lib/rspec-puppet/coverage.rb
40
41
  - lib/rspec-puppet/errors.rb
@@ -78,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
79
  version: '0'
79
80
  requirements: []
80
81
  rubyforge_project:
81
- rubygems_version: 2.4.5.1
82
+ rubygems_version: 2.5.1
82
83
  signing_key:
83
84
  specification_version: 4
84
85
  summary: RSpec tests for your Puppet manifests