poise-languages 2.1.0 → 2.1.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.
@@ -108,7 +108,7 @@ module PoiseLanguages
108
108
  # KNOW BY FILING A GITHUB ISSUE AT http://github.com/poise/poise-languages/issues/new.
109
109
  repo_name = "rhel-server-rhscl-#{node['platform_version'][0]}-rpms"
110
110
  execute "subscription-manager repos --enable #{repo_name}" do
111
- not_if { shell_out!('subscription-manager repos --list').stdout.include?(repo_name) }
111
+ not_if { shell_out!('subscription-manager repos --list-enabled').stdout.include?(repo_name) }
112
112
  end
113
113
  else
114
114
  package 'centos-release-scl-rh' do
@@ -97,60 +97,86 @@ module PoiseLanguages
97
97
  #
98
98
  # @return [void]
99
99
  def action_install
100
- run_package_action(:install)
100
+ notifying_block do
101
+ install_packages
102
+ run_action_hack
103
+ end
101
104
  end
102
105
 
103
106
  # The `upgrade` action for the `poise_languages_system` resource.
104
107
  #
105
108
  # @return [void]
106
109
  def action_upgrade
107
- run_package_action(:upgrade)
110
+ notifying_block do
111
+ upgrade_packages
112
+ run_action_hack
113
+ end
108
114
  end
109
115
 
110
116
  # The `uninstall` action for the `poise_languages_system` resource.
111
117
  #
112
118
  # @return [void]
113
119
  def action_uninstall
114
- action = node.platform_family?('debian') ? :purge : :remove
115
- package_resources(action).each do |resource|
116
- resource.run_action(action)
117
- new_resource.updated_by_last_action(true) if resource.updated_by_last_action?
120
+ notifying_block do
121
+ uninstall_packages
118
122
  end
119
123
  end
120
124
 
121
125
  private
122
126
 
123
- # Create package resource objects for all needed packages. These are created
124
- # directly and not added to the resource collection.
127
+ # Install the needed language packages.
125
128
  #
126
- # @return [Array<Chef::Resource::Package>]
127
- def package_resources(action)
129
+ # @api private
130
+ # @return [Array<Chef::Resource>]
131
+ def install_packages
128
132
  packages = {new_resource.package_name => new_resource.package_version}
129
133
  # If we are supposed to install the dev package, grab it using the same
130
134
  # version as the main package.
131
135
  if new_resource.dev_package
132
136
  packages[new_resource.dev_package] = new_resource.package_version
133
137
  end
134
-
135
138
  Chef::Log.debug("[#{new_resource.parent}] Building package resource using #{packages.inspect}.")
139
+
140
+ # Check for multi-package support.
136
141
  package_resource_class = Chef::Resource.resource_for_node(:package, node)
137
- @package_resource ||= if node.platform_family?('rhel', 'fedora', 'amazon', 'mac_os_x')
138
- # @todo Can't use multi-package mode with yum pending https://github.com/chef/chef/issues/3476.
139
- packages.map do |name, version|
140
- package_resource_class.new(name, run_context).tap do |r|
141
- r.version(version)
142
- r.action(action)
143
- r.declared_type = :package
144
- r.retries(5)
145
- end
142
+ package_provider_class = package_resource_class.new('multipackage_check', run_context).provider_for_action(:install)
143
+ package_resources = if package_provider_class.respond_to?(:use_multipackage_api?) && package_provider_class.use_multipackage_api?
144
+ package packages.keys do
145
+ version packages.values
146
146
  end
147
147
  else
148
- [package_resource_class.new(packages.keys, run_context).tap do |r|
149
- r.version(packages.values)
150
- r.action(action)
151
- r.declared_type = :package
152
- r.retries(5)
153
- end]
148
+ # Fallback for non-multipackage.
149
+ packages.map do |pkg_name, pkg_version|
150
+ package pkg_name do
151
+ version pkg_version
152
+ end
153
+ end
154
+ end
155
+
156
+ # Apply some settings to all of the resources.
157
+ Array(package_resources).each do |res|
158
+ res.retries(5)
159
+ res.define_singleton_method(:apply_action_hack?) { true }
160
+ end
161
+ end
162
+
163
+ # Upgrade the needed language packages.
164
+ #
165
+ # @api private
166
+ # @return [Array<Chef::Resource>]
167
+ def upgrade_packages
168
+ install_packages.each do |res|
169
+ res.action(:upgrade)
170
+ end
171
+ end
172
+
173
+ # Uninstall the needed language packages.
174
+ #
175
+ # @api private
176
+ # @return [Array<Chef::Resource>]
177
+ def uninstall_packages
178
+ install_packages.each do |res|
179
+ res.action(node.platform_family?('debian') ? :purge : :remove)
154
180
  end
155
181
  end
156
182
 
@@ -161,21 +187,34 @@ module PoiseLanguages
161
187
  #
162
188
  # @param action [Symbol] Action to run on all package resources.
163
189
  # @return [void]
164
- def run_package_action(action)
165
- package_resources(action).each do |resource|
166
- # Reset it so we have a clean baseline.
167
- resource.updated_by_last_action(false)
168
- # Grab the provider.
169
- provider = resource.provider_for_action(action)
170
- provider.action = action
171
- # Check the candidate version if needed. With a manual package_version
172
- # you get whatever you asked for.
173
- patch_load_current_resource!(provider, new_resource.version) unless new_resource.package_version
174
- # Run our action.
175
- Chef::Log.debug("[#{new_resource.parent}] Running #{provider} with #{action}")
176
- provider.run_action(action)
177
- # Check updated flag.
178
- new_resource.updated_by_last_action(true) if resource.updated_by_last_action?
190
+ def run_action_hack
191
+ # If new_resource.package_version is set, skip this madness.
192
+ return if new_resource.package_version
193
+
194
+ # Process every resource in the current collection, which is bounded
195
+ # by notifying_block.
196
+ run_context.resource_collection.each do |resource|
197
+ # Only apply to things we tagged above.
198
+ next unless resource.respond_to?(:apply_action_hack?) && resource.apply_action_hack?
199
+
200
+ Array(resource.action).each do |action|
201
+ # Reset it so we have a clean baseline.
202
+ resource.updated_by_last_action(false)
203
+ # Grab the provider.
204
+ provider = resource.provider_for_action(action)
205
+ provider.action = action
206
+ # Inject our check for the candidate version. This will actually
207
+ # get run during run_action below.
208
+ patch_load_current_resource!(provider, new_resource.version)
209
+ # Run our action.
210
+ Chef::Log.debug("[#{new_resource.parent}] Running #{provider} with #{action}")
211
+ provider.run_action(action)
212
+ # Check updated flag.
213
+ new_resource.updated_by_last_action(true) if resource.updated_by_last_action?
214
+ end
215
+
216
+ # Make sure the resource doesn't run again when notifying_block ends.
217
+ resource.action(:nothing)
179
218
  end
180
219
  end
181
220
 
@@ -16,5 +16,5 @@
16
16
 
17
17
 
18
18
  module PoiseLanguages
19
- VERSION = '2.1.0'
19
+ VERSION = '2.1.1'
20
20
  end
@@ -26,7 +26,8 @@ Gem::Specification.new do |spec|
26
26
  spec.description = "A Chef cookbook to help writing language cookbooks."
27
27
  spec.summary = spec.description
28
28
  spec.homepage = 'https://github.com/poise/poise-languages'
29
- spec.license = 'Apache 2.0'
29
+ spec.license = 'Apache-2.0'
30
+ spec.metadata['platforms'] = 'any'
30
31
 
31
32
  spec.files = `git ls-files`.split($/)
32
33
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
@@ -17,6 +17,7 @@
17
17
  eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
18
 
19
19
  gem 'chef', '~> 12.1.2'
20
- gem 'rack', '< 2'
21
- gem 'foodcritic', '< 8'
20
+ gem 'chefspec', '< 6'
22
21
  gem 'fauxhai', '<= 3.9.0'
22
+ gem 'foodcritic', '< 8'
23
+ gem 'rack', '< 2'
@@ -17,6 +17,7 @@
17
17
  eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
18
 
19
19
  gem 'chef', '~> 12.10.24'
20
- gem 'rack', '< 2'
21
- gem 'foodcritic', '< 8'
20
+ gem 'chefspec', '< 6'
22
21
  gem 'fauxhai', '<= 3.9.0'
22
+ gem 'foodcritic', '< 8'
23
+ gem 'rack', '< 2'
@@ -17,6 +17,7 @@
17
17
  eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
18
 
19
19
  gem 'chef', '~> 12.11.18'
20
- gem 'rack', '< 2'
21
- gem 'foodcritic', '< 8'
20
+ gem 'chefspec', '< 6'
22
21
  gem 'fauxhai', '<= 3.9.0'
22
+ gem 'foodcritic', '< 8'
23
+ gem 'rack', '< 2'
@@ -17,5 +17,6 @@
17
17
  eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
18
 
19
19
  gem 'chef', '~> 12.12.15'
20
- gem 'foodcritic', '< 8'
20
+ gem 'chefspec', '< 6'
21
21
  gem 'fauxhai', '<= 3.9.0'
22
+ gem 'foodcritic', '< 8'
@@ -17,5 +17,6 @@
17
17
  eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
18
 
19
19
  gem 'chef', '~> 12.13.37'
20
- gem 'foodcritic', '< 8'
20
+ gem 'chefspec', '< 6'
21
21
  gem 'fauxhai', '<= 3.9.0'
22
+ gem 'foodcritic', '< 8'
@@ -0,0 +1,19 @@
1
+ #
2
+ # Copyright 2017, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
+
19
+ gem 'chef', '~> 12.18.31'
@@ -0,0 +1,19 @@
1
+ #
2
+ # Copyright 2017, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
+
19
+ gem 'chef', '~> 12.19.36'
@@ -17,6 +17,7 @@
17
17
  eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
18
 
19
19
  gem 'chef', '~> 12.2.1'
20
- gem 'rack', '< 2'
21
- gem 'foodcritic', '< 8'
20
+ gem 'chefspec', '< 6'
22
21
  gem 'fauxhai', '<= 3.9.0'
22
+ gem 'foodcritic', '< 8'
23
+ gem 'rack', '< 2'
@@ -17,6 +17,7 @@
17
17
  eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
18
 
19
19
  gem 'chef', '~> 12.3.0'
20
- gem 'rack', '< 2'
21
- gem 'foodcritic', '< 8'
20
+ gem 'chefspec', '< 6'
22
21
  gem 'fauxhai', '<= 3.9.0'
22
+ gem 'foodcritic', '< 8'
23
+ gem 'rack', '< 2'
@@ -17,7 +17,8 @@
17
17
  eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
18
 
19
19
  gem 'chef', '~> 12.4.3'
20
- gem 'rack', '< 2'
21
- gem 'foodcritic', '< 8'
20
+ gem 'chefspec', '< 6'
22
21
  gem 'fauxhai', '<= 3.9.0'
22
+ gem 'foodcritic', '< 8'
23
23
  gem 'gh', '0.14.0'
24
+ gem 'rack', '< 2'
@@ -17,6 +17,7 @@
17
17
  eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
18
 
19
19
  gem 'chef', '~> 12.5.1'
20
- gem 'rack', '< 2'
21
- gem 'foodcritic', '< 8'
20
+ gem 'chefspec', '< 6'
22
21
  gem 'fauxhai', '<= 3.9.0'
22
+ gem 'foodcritic', '< 8'
23
+ gem 'rack', '< 2'
@@ -17,6 +17,7 @@
17
17
  eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
18
 
19
19
  gem 'chef', '~> 12.6.0'
20
- gem 'rack', '< 2'
21
- gem 'foodcritic', '< 8'
20
+ gem 'chefspec', '< 6'
22
21
  gem 'fauxhai', '<= 3.9.0'
22
+ gem 'foodcritic', '< 8'
23
+ gem 'rack', '< 2'
@@ -17,6 +17,7 @@
17
17
  eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
18
 
19
19
  gem 'chef', '~> 12.7.2'
20
- gem 'rack', '< 2'
21
- gem 'foodcritic', '< 8'
20
+ gem 'chefspec', '< 6'
22
21
  gem 'fauxhai', '<= 3.9.0'
22
+ gem 'foodcritic', '< 8'
23
+ gem 'rack', '< 2'
@@ -17,6 +17,7 @@
17
17
  eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
18
 
19
19
  gem 'chef', '~> 12.8.1'
20
- gem 'rack', '< 2'
21
- gem 'foodcritic', '< 8'
20
+ gem 'chefspec', '< 6'
22
21
  gem 'fauxhai', '<= 3.9.0'
22
+ gem 'foodcritic', '< 8'
23
+ gem 'rack', '< 2'
@@ -17,6 +17,7 @@
17
17
  eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
18
 
19
19
  gem 'chef', '~> 12.9.41'
20
- gem 'rack', '< 2'
21
- gem 'foodcritic', '< 8'
20
+ gem 'chefspec', '< 6'
22
21
  gem 'fauxhai', '<= 3.9.0'
22
+ gem 'foodcritic', '< 8'
23
+ gem 'rack', '< 2'
@@ -16,4 +16,4 @@
16
16
 
17
17
  eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
18
 
19
- gem 'chef', '~> 12.17'
19
+ gem 'chef', '~> 12.19'
@@ -0,0 +1,19 @@
1
+ #
2
+ # Copyright 2017, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
+
19
+ gem 'chef', '~> 13.0.118'
@@ -0,0 +1,19 @@
1
+ #
2
+ # Copyright 2017, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
+
19
+ gem 'chef', '~> 13.0'
@@ -16,10 +16,13 @@
16
16
 
17
17
  eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
18
 
19
- gem 'chef', github: 'chef/chef'
20
- gem 'halite', github: 'poise/halite'
21
- gem 'ohai', github: 'chef/ohai'
22
- gem 'poise', github: 'poise/poise'
23
- gem 'poise-archive', github: 'poise/poise-archive'
24
- gem 'poise-boiler', github: 'poise/poise-boiler'
25
- gem 'poise-profiler', github: 'poise/poise-profiler'
19
+ gem 'chef', git: 'https://github.com/chef/chef.git'
20
+ gem 'chefspec', git: 'https://github.com/sethvargo/chefspec.git'
21
+ gem 'fauxhai', git: 'https://github.com/customink/fauxhai.git'
22
+ gem 'foodcritic', git: 'https://github.com/foodcritic/foodcritic.git'
23
+ gem 'halite', git: 'https://github.com/poise/halite.git'
24
+ gem 'ohai', git: 'https://github.com/chef/ohai.git'
25
+ gem 'poise', git: 'https://github.com/poise/poise.git'
26
+ gem 'poise-archive', git: 'https://github.com/poise/poise-archive.git'
27
+ gem 'poise-boiler', git: 'https://github.com/poise/poise-boiler.git'
28
+ gem 'poise-profiler', git: 'https://github.com/poise/poise-profiler.git'
@@ -15,110 +15,258 @@
15
15
  #
16
16
 
17
17
  require 'spec_helper'
18
+ require 'chef/version'
19
+ require 'shellwords'
18
20
 
19
21
  describe PoiseLanguages::System::Resource do
20
- let(:chefspec_options) { {platform: 'ubuntu', version: '14.04'} }
21
22
  step_into(:poise_languages_system)
22
- step_into(:package, unwrap_notifying_block: false)
23
- provider(:package_hack, parent: Chef::Provider::Package) do
24
- def load_current_resource
25
- @current_resource = new_resource.class.new(new_resource.name, run_context)
26
- current_resource.package_name(new_resource.package_name)
27
- candidate = node['poise_candidate']
28
- current = node['poise_current']
29
- @candidate_version = if new_resource.package_name.is_a?(Array)
30
- current_resource.version([current] * new_resource.package_name.length)
31
- [candidate] * new_resource.package_name.length
32
- else
33
- current_resource.version(current)
34
- candidate
35
- end
36
- current_resource
37
- end
38
- def install_package(name, version)
39
- rc = defined?(Chef.run_context) ? Chef.run_context : self.run_context
40
- rc.resource_collection << new_resource unless rc.resource_collection.keys.include?(new_resource.to_s)
41
- end
42
- alias_method :upgrade_package, :install_package
43
- alias_method :remove_package, :install_package
44
- alias_method :purge_package, :install_package
45
- end
46
- recipe do
47
- r = ruby_block 'parent'
48
- poise_languages_system 'mylang' do
49
- parent r
50
- version ''
51
- end
52
- end
53
23
  before do
54
- # I can't use the provider resolver system easily because overrides like this
55
- # don't work well with the Halite patcher.
56
- allow_any_instance_of(Chef::Resource::Package).to receive(:provider).and_return(provider(:package_hack))
57
- # Set our candidate version.
58
- default_attributes[:poise_candidate] = '1.0'
24
+ # Don't actually run any installs. The package hack prevents the usual
25
+ # ChefSpec stubbing from working. This fakes it.
26
+ [Chef::Provider::Package::Apt, Chef::Provider::Package::Yum].each do |klass|
27
+ allow_any_instance_of(klass).to receive(:install_package) {|this| this.new_resource.perform_action(:install, converge_time: true) }
28
+ allow_any_instance_of(klass).to receive(:upgrade_package) {|this| this.new_resource.perform_action(:upgrade, converge_time: true) }
29
+ allow_any_instance_of(klass).to receive(:remove_package) {|this| this.new_resource.perform_action(:remove, converge_time: true) }
30
+ allow_any_instance_of(klass).to receive(:purge_package) {|this| this.new_resource.perform_action(:purge, converge_time: true) }
31
+ end
59
32
  end
60
33
 
61
34
  context 'on Ubuntu' do
62
- it { is_expected.to install_apt_package('mylang, mylang-dev') }
35
+ let(:chefspec_options) { {platform: 'ubuntu', version: '16.04'} }
36
+ before do
37
+ # Stubs load load_current_resource for apt_package.
38
+ allow_any_instance_of(Chef::Provider::Package::Apt).to receive(:shell_out) do |this, *args|
39
+ args.pop if args.last.is_a?(Hash)
40
+ args = Shellwords.split(args.first) if args.size == 1 && args.first.is_a?(String)
41
+ if args[0..1] == %w{apt-cache policy}
42
+ double(stdout: <<-EOH, error!: nil)
43
+ #{args[2]}:
44
+ Installed: (none)
45
+ Candidate: 1.2.3-1
46
+ Version table:
47
+ 1.2.3-1 500
48
+ 500 http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages
49
+ EOH
50
+ else
51
+ raise "unstubbed command #{args.inspect}"
52
+ end
53
+ end
54
+ end
55
+
56
+ context 'action :install' do
57
+ recipe do
58
+ r = ruby_block 'parent'
59
+ poise_languages_system 'mylang' do
60
+ parent r
61
+ version ''
62
+ end
63
+ end
64
+
65
+ if Gem::Requirement.create('>= 12.11').satisfied_by?(Gem::Version.create(Chef::VERSION))
66
+ it { is_expected.to install_package('mylang, mylang-dev') }
67
+ else
68
+ it { is_expected.to install_package('mylang') }
69
+ it { is_expected.to install_package('mylang-dev') }
70
+ end
71
+ end # /context action :upgrade
72
+
73
+ context 'action :upgrade' do
74
+ recipe do
75
+ r = ruby_block 'parent'
76
+ poise_languages_system 'mylang' do
77
+ action :upgrade
78
+ parent r
79
+ version ''
80
+ end
81
+ end
82
+
83
+ if Gem::Requirement.create('>= 12.11').satisfied_by?(Gem::Version.create(Chef::VERSION))
84
+ it { is_expected.to upgrade_package('mylang, mylang-dev') }
85
+ else
86
+ it { is_expected.to upgrade_package('mylang') }
87
+ it { is_expected.to upgrade_package('mylang-dev') }
88
+ end
89
+ end # /context action :upgrade
90
+
91
+ context 'action :uninstall' do
92
+ recipe do
93
+ r = ruby_block 'parent'
94
+ poise_languages_system 'mylang' do
95
+ action :uninstall
96
+ parent r
97
+ version ''
98
+ end
99
+ end
100
+
101
+ if Gem::Requirement.create('>= 12.11').satisfied_by?(Gem::Version.create(Chef::VERSION))
102
+ it { is_expected.to purge_package('mylang, mylang-dev') }
103
+ else
104
+ it { is_expected.to purge_package('mylang') }
105
+ it { is_expected.to purge_package('mylang-dev') }
106
+ end
107
+ end # /context action :uninstall
108
+
109
+ context 'with a matching version' do
110
+ recipe do
111
+ r = ruby_block 'parent'
112
+ poise_languages_system 'mylang' do
113
+ parent r
114
+ version '1'
115
+ end
116
+ end
117
+
118
+ it { expect { subject }.to_not raise_error }
119
+ end # /context with a matching version
120
+
121
+ context 'with an exact matching version' do
122
+ recipe do
123
+ r = ruby_block 'parent'
124
+ poise_languages_system 'mylang' do
125
+ parent r
126
+ version '1.2.3'
127
+ end
128
+ end
129
+
130
+ it { expect { subject }.to_not raise_error }
131
+ end # /context with an exact matching version
132
+
133
+ context 'with a non-matching version' do
134
+ recipe do
135
+ r = ruby_block 'parent'
136
+ poise_languages_system 'mylang' do
137
+ parent r
138
+ version '2'
139
+ end
140
+ end
141
+
142
+ it { expect { subject }.to raise_error PoiseLanguages::Error }
143
+ end # /context with a non-matching version
144
+
145
+ context 'with a nearby non-matching version' do
146
+ recipe do
147
+ r = ruby_block 'parent'
148
+ poise_languages_system 'mylang' do
149
+ parent r
150
+ version '1.2.4'
151
+ end
152
+ end
153
+
154
+ it { expect { subject }.to raise_error PoiseLanguages::Error }
155
+ end # /context with a nearby non-matching version
63
156
  end # /context on Ubuntu
64
157
 
65
158
  context 'on CentOS' do
66
159
  let(:chefspec_options) { {platform: 'centos', version: '7.0'} }
160
+ before do
161
+ yum_cache = double('YumCache')
162
+ allow(yum_cache).to receive(:yum_binary=)
163
+ allow(yum_cache).to receive(:disable_extra_repo_control)
164
+ allow(yum_cache).to receive(:package_available?).and_return(false)
165
+ allow(yum_cache).to receive(:package_available?).with(/^mylang(-devel)?$/).and_return(true)
166
+ allow(yum_cache).to receive(:installed_version).with(/^mylang(-devel)?$/, nil).and_return(nil)
167
+ allow(yum_cache).to receive(:candidate_version).with(/^mylang(-devel)?$/, nil).and_return('1.2.3')
168
+ allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(yum_cache)
169
+ end
67
170
 
68
- it { is_expected.to install_yum_package('mylang') }
69
- it { is_expected.to install_yum_package('mylang-devel') }
70
- end # /context on Ubuntu
171
+ context 'action :install' do
172
+ recipe do
173
+ r = ruby_block 'parent'
174
+ poise_languages_system 'mylang' do
175
+ parent r
176
+ version ''
177
+ end
178
+ end
71
179
 
72
- context 'action :upgrade' do
73
- recipe do
74
- r = ruby_block 'parent'
75
- poise_languages_system 'mylang' do
76
- action :upgrade
77
- parent r
78
- version ''
180
+ if Gem::Requirement.create('>= 12.19').satisfied_by?(Gem::Version.create(Chef::VERSION))
181
+ it { is_expected.to install_package('mylang, mylang-devel') }
182
+ else
183
+ it { is_expected.to install_package('mylang') }
184
+ it { is_expected.to install_package('mylang-devel') }
185
+ end
186
+ end # /context action :upgrade
187
+
188
+ context 'action :upgrade' do
189
+ recipe do
190
+ r = ruby_block 'parent'
191
+ poise_languages_system 'mylang' do
192
+ action :upgrade
193
+ parent r
194
+ version ''
195
+ end
79
196
  end
80
- end
81
197
 
82
- it { is_expected.to upgrade_apt_package('mylang, mylang-dev') }
83
- end # /context action :upgrade
198
+ if Gem::Requirement.create('>= 12.19').satisfied_by?(Gem::Version.create(Chef::VERSION))
199
+ it { is_expected.to upgrade_package('mylang, mylang-devel') }
200
+ else
201
+ it { is_expected.to upgrade_package('mylang') }
202
+ it { is_expected.to upgrade_package('mylang-devel') }
203
+ end
204
+ end # /context action :upgrade
84
205
 
85
- context 'action :uninstall' do
86
- recipe do
87
- r = ruby_block 'parent'
88
- poise_languages_system 'mylang' do
89
- action :uninstall
90
- parent r
91
- version ''
206
+ context 'action :uninstall' do
207
+ recipe do
208
+ r = ruby_block 'parent'
209
+ poise_languages_system 'mylang' do
210
+ action :uninstall
211
+ parent r
212
+ version ''
213
+ end
92
214
  end
93
- end
94
- before do
95
- default_attributes[:poise_current] = '2.0'
96
- end
97
215
 
98
- it { is_expected.to purge_apt_package('mylang, mylang-dev') }
99
- end # /context action :uninstall
216
+ if Gem::Requirement.create('>= 12.19').satisfied_by?(Gem::Version.create(Chef::VERSION))
217
+ it { is_expected.to remove_package('mylang, mylang-devel') }
218
+ else
219
+ it { is_expected.to remove_package('mylang') }
220
+ it { is_expected.to remove_package('mylang-devel') }
221
+ end
222
+ end # /context action :uninstall
100
223
 
101
- context 'with a matching version' do
102
- recipe do
103
- r = ruby_block 'parent'
104
- poise_languages_system 'mylang' do
105
- parent r
106
- version '1'
224
+ context 'with a matching version' do
225
+ recipe do
226
+ r = ruby_block 'parent'
227
+ poise_languages_system 'mylang' do
228
+ parent r
229
+ version '1'
230
+ end
107
231
  end
108
- end
109
232
 
110
- it { is_expected.to install_apt_package('mylang, mylang-dev') }
111
- end # /context with a matching version
233
+ it { expect { subject }.to_not raise_error }
234
+ end # /context with a matching version
112
235
 
113
- context 'with a non-matching version' do
114
- recipe do
115
- r = ruby_block 'parent'
116
- poise_languages_system 'mylang' do
117
- parent r
118
- version '2'
236
+ context 'with an exact matching version' do
237
+ recipe do
238
+ r = ruby_block 'parent'
239
+ poise_languages_system 'mylang' do
240
+ parent r
241
+ version '1.2.3'
242
+ end
243
+ end
244
+
245
+ it { expect { subject }.to_not raise_error }
246
+ end # /context with an exact matching version
247
+
248
+ context 'with a non-matching version' do
249
+ recipe do
250
+ r = ruby_block 'parent'
251
+ poise_languages_system 'mylang' do
252
+ parent r
253
+ version '2'
254
+ end
255
+ end
256
+
257
+ it { expect { subject }.to raise_error PoiseLanguages::Error }
258
+ end # /context with a non-matching version
259
+
260
+ context 'with a nearby non-matching version' do
261
+ recipe do
262
+ r = ruby_block 'parent'
263
+ poise_languages_system 'mylang' do
264
+ parent r
265
+ version '1.2.4'
266
+ end
119
267
  end
120
- end
121
268
 
122
- it { expect { subject }.to raise_error PoiseLanguages::Error }
123
- end # /context with a non-matching version
269
+ it { expect { subject }.to raise_error PoiseLanguages::Error }
270
+ end # /context with a nearby non-matching version
271
+ end # /context on CentOS
124
272
  end