chef 12.5.1 → 12.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (221) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +6 -1
  3. data/README.md +6 -4
  4. data/Rakefile +1 -4
  5. data/chef-windows.gemspec +21 -0
  6. data/chef.gemspec +58 -0
  7. data/lib/chef/api_client/registration.rb +9 -4
  8. data/lib/chef/application.rb +3 -84
  9. data/lib/chef/application/apply.rb +9 -2
  10. data/lib/chef/application/client.rb +8 -3
  11. data/lib/chef/application/solo.rb +7 -1
  12. data/lib/chef/application/windows_service.rb +21 -6
  13. data/lib/chef/application/windows_service_manager.rb +2 -3
  14. data/lib/chef/audit/runner.rb +1 -0
  15. data/lib/chef/chef_class.rb +1 -11
  16. data/lib/chef/chef_fs/chef_fs_data_store.rb +181 -2
  17. data/lib/chef/chef_fs/file_system/cookbook_subdir.rb +5 -0
  18. data/lib/chef/chef_fs/file_system/file_system_entry.rb +11 -7
  19. data/lib/chef/client.rb +28 -1
  20. data/lib/chef/cookbook/cookbook_collection.rb +14 -1
  21. data/lib/chef/cookbook/cookbook_version_loader.rb +1 -1
  22. data/lib/chef/cookbook/metadata.rb +115 -9
  23. data/lib/chef/cookbook/remote_file_vendor.rb +1 -1
  24. data/lib/chef/cookbook_version.rb +6 -2
  25. data/lib/chef/data_bag.rb +1 -1
  26. data/lib/chef/data_bag_item.rb +1 -1
  27. data/lib/chef/digester.rb +5 -1
  28. data/lib/chef/dsl/chef_provisioning.rb +57 -0
  29. data/lib/chef/dsl/cheffish.rb +64 -0
  30. data/lib/chef/dsl/declare_resource.rb +108 -0
  31. data/lib/chef/dsl/platform_introspection.rb +3 -3
  32. data/lib/chef/dsl/recipe.rb +3 -73
  33. data/lib/chef/dsl/resources.rb +27 -1
  34. data/lib/chef/event_dispatch/base.rb +3 -0
  35. data/lib/chef/event_dispatch/dispatcher.rb +5 -0
  36. data/lib/chef/event_dispatch/events_output_stream.rb +8 -0
  37. data/lib/chef/exceptions.rb +21 -1
  38. data/lib/chef/file_access_control/unix.rb +12 -12
  39. data/lib/chef/file_content_management/deploy/cp.rb +2 -2
  40. data/lib/chef/file_content_management/deploy/mv_unix.rb +4 -4
  41. data/lib/chef/file_content_management/deploy/mv_windows.rb +1 -1
  42. data/lib/chef/formatters/base.rb +7 -0
  43. data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +2 -2
  44. data/lib/chef/formatters/indentable_output_stream.rb +5 -0
  45. data/lib/chef/http.rb +19 -3
  46. data/lib/chef/http/decompressor.rb +2 -2
  47. data/lib/chef/json_compat.rb +1 -0
  48. data/lib/chef/knife.rb +16 -2
  49. data/lib/chef/knife/bootstrap.rb +55 -10
  50. data/lib/chef/knife/cookbook_site_install.rb +5 -1
  51. data/lib/chef/knife/core/bootstrap_context.rb +2 -1
  52. data/lib/chef/knife/core/node_presenter.rb +1 -1
  53. data/lib/chef/knife/ssh.rb +30 -16
  54. data/lib/chef/knife/ssl_check.rb +4 -2
  55. data/lib/chef/knife/ssl_fetch.rb +3 -2
  56. data/lib/chef/knife/status.rb +14 -1
  57. data/lib/chef/log.rb +14 -0
  58. data/lib/chef/mixin/get_source_from_package.rb +7 -2
  59. data/lib/chef/mixin/properties.rb +302 -0
  60. data/lib/chef/mixin/proxified_socket.rb +38 -0
  61. data/lib/chef/mixin/subclass_directive.rb +37 -0
  62. data/lib/chef/node.rb +13 -5
  63. data/lib/chef/platform/query_helpers.rb +14 -3
  64. data/lib/chef/platform/service_helpers.rb +20 -38
  65. data/lib/chef/policy_builder/expand_node_object.rb +3 -0
  66. data/lib/chef/policy_builder/policyfile.rb +1 -0
  67. data/lib/chef/property.rb +51 -12
  68. data/lib/chef/provider.rb +40 -35
  69. data/lib/chef/provider/deploy.rb +1 -1
  70. data/lib/chef/provider/dsc_resource.rb +54 -20
  71. data/lib/chef/provider/execute.rb +25 -4
  72. data/lib/chef/provider/group.rb +1 -1
  73. data/lib/chef/provider/lwrp_base.rb +1 -0
  74. data/lib/chef/provider/package.rb +76 -30
  75. data/lib/chef/provider/package/dpkg.rb +152 -69
  76. data/lib/chef/provider/package/openbsd.rb +6 -8
  77. data/lib/chef/provider/package/solaris.rb +2 -0
  78. data/lib/chef/provider/package/windows.rb +95 -14
  79. data/lib/chef/provider/package/windows/exe.rb +129 -0
  80. data/lib/chef/provider/package/windows/msi.rb +37 -13
  81. data/lib/chef/provider/package/windows/registry_uninstall_entry.rb +89 -0
  82. data/lib/chef/provider/package/yum.rb +13 -3
  83. data/lib/chef/provider/powershell_script.rb +3 -0
  84. data/lib/chef/provider/remote_file/cache_control_data.rb +37 -4
  85. data/lib/chef/provider/remote_file/http.rb +1 -1
  86. data/lib/chef/provider/script.rb +1 -0
  87. data/lib/chef/provider/service.rb +13 -10
  88. data/lib/chef/provider/service/solaris.rb +43 -17
  89. data/lib/chef/provider/service/upstart.rb +3 -3
  90. data/lib/chef/provider/user.rb +1 -1
  91. data/lib/chef/provider/user/dscl.rb +111 -100
  92. data/lib/chef/provider/user/windows.rb +5 -3
  93. data/lib/chef/recipe.rb +3 -5
  94. data/lib/chef/resource.rb +77 -320
  95. data/lib/chef/resource/action_class.rb +4 -0
  96. data/lib/chef/resource/dpkg_package.rb +4 -3
  97. data/lib/chef/resource/dsc_resource.rb +40 -2
  98. data/lib/chef/resource/execute.rb +9 -1
  99. data/lib/chef/resource/ksh.rb +32 -0
  100. data/lib/chef/resource/lwrp_base.rb +6 -10
  101. data/lib/chef/resource/package.rb +8 -9
  102. data/lib/chef/resource/registry_key.rb +1 -1
  103. data/lib/chef/resource/resource_notification.rb +14 -1
  104. data/lib/chef/resource/script.rb +1 -1
  105. data/lib/chef/resource/windows_package.rb +1 -1
  106. data/lib/chef/resource_builder.rb +14 -7
  107. data/lib/chef/resource_reporter.rb +6 -0
  108. data/lib/chef/resources.rb +1 -7
  109. data/lib/chef/rest.rb +1 -1
  110. data/lib/chef/run_context.rb +45 -2
  111. data/lib/chef/run_list/run_list_expansion.rb +47 -0
  112. data/lib/chef/runner.rb +25 -0
  113. data/lib/chef/search/query.rb +16 -2
  114. data/lib/chef/util/diff.rb +2 -2
  115. data/lib/chef/util/powershell/ps_credential.rb +2 -3
  116. data/lib/chef/version.rb +1 -1
  117. data/lib/chef/win32/api/file.rb +51 -1
  118. data/lib/chef/win32/file.rb +5 -0
  119. data/lib/chef/win32/file/version_info.rb +93 -0
  120. data/lib/chef/win32/mutex.rb +1 -1
  121. data/spec/data/apt/chef-integration-test2-1.0/debian/changelog +5 -0
  122. data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2.debhelper.log +45 -0
  123. data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2.substvars +1 -0
  124. data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2/DEBIAN/conffiles +1 -0
  125. data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2/DEBIAN/control +10 -0
  126. data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2/DEBIAN/md5sums +1 -0
  127. data/spec/data/apt/chef-integration-test2-1.0/debian/compat +1 -0
  128. data/spec/data/apt/chef-integration-test2-1.0/debian/conffiles +1 -0
  129. data/spec/data/apt/chef-integration-test2-1.0/debian/control +13 -0
  130. data/spec/data/apt/chef-integration-test2-1.0/debian/copyright +34 -0
  131. data/spec/data/apt/chef-integration-test2-1.0/debian/files +1 -0
  132. data/spec/data/apt/chef-integration-test2-1.0/debian/rules +13 -0
  133. data/spec/data/apt/chef-integration-test2-1.0/debian/source/format +1 -0
  134. data/spec/data/apt/chef-integration-test2_1.0-1.debian.tar.gz +0 -0
  135. data/spec/data/apt/chef-integration-test2_1.0-1.dsc +18 -0
  136. data/spec/data/apt/chef-integration-test2_1.0-1_amd64.build +91 -0
  137. data/spec/data/apt/chef-integration-test2_1.0-1_amd64.changes +31 -0
  138. data/spec/data/apt/chef-integration-test2_1.0-1_amd64.deb +0 -0
  139. data/spec/data/apt/chef-integration-test2_1.0.orig.tar.gz +0 -0
  140. data/spec/functional/application_spec.rb +1 -1
  141. data/spec/functional/audit/runner_spec.rb +4 -0
  142. data/spec/functional/knife/ssh_spec.rb +5 -5
  143. data/spec/functional/notifications_spec.rb +74 -4
  144. data/spec/functional/resource/aix_service_spec.rb +2 -2
  145. data/spec/functional/resource/dpkg_package_spec.rb +339 -0
  146. data/spec/functional/resource/ifconfig_spec.rb +3 -1
  147. data/spec/functional/resource/mount_spec.rb +5 -2
  148. data/spec/functional/resource/package_spec.rb +1 -1
  149. data/spec/functional/resource/user/windows_spec.rb +8 -0
  150. data/spec/functional/resource/windows_package_spec.rb +177 -0
  151. data/spec/functional/win32/version_info_spec.rb +50 -0
  152. data/spec/integration/client/client_spec.rb +80 -0
  153. data/spec/integration/knife/download_spec.rb +9 -0
  154. data/spec/integration/knife/upload_spec.rb +28 -1
  155. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +93 -23
  156. data/spec/integration/recipes/resource_action_spec.rb +211 -116
  157. data/spec/integration/recipes/resource_converge_if_changed_spec.rb +72 -0
  158. data/spec/integration/solo/solo_spec.rb +34 -0
  159. data/spec/spec_helper.rb +11 -1
  160. data/spec/support/platform_helpers.rb +8 -0
  161. data/spec/support/shared/integration/integration_helper.rb +6 -0
  162. data/spec/support/shared/unit/execute_resource.rb +5 -0
  163. data/spec/support/shared/unit/platform_introspector.rb +7 -0
  164. data/spec/tiny_server.rb +6 -2
  165. data/spec/unit/api_client/registration_spec.rb +5 -4
  166. data/spec/unit/application_spec.rb +1 -181
  167. data/spec/unit/chef_fs/file_system/cookbook_subdir_spec.rb +34 -0
  168. data/spec/unit/cookbook/metadata_spec.rb +122 -2
  169. data/spec/unit/http_spec.rb +102 -0
  170. data/spec/unit/knife/bootstrap_spec.rb +55 -13
  171. data/spec/unit/knife/core/bootstrap_context_spec.rb +10 -3
  172. data/spec/unit/knife/ssl_check_spec.rb +7 -3
  173. data/spec/unit/knife/ssl_fetch_spec.rb +2 -2
  174. data/spec/unit/knife/status_spec.rb +13 -13
  175. data/spec/unit/knife_spec.rb +26 -2
  176. data/spec/unit/lwrp_spec.rb +1 -1
  177. data/spec/unit/mixin/properties_spec.rb +97 -0
  178. data/spec/unit/mixin/proxified_socket_spec.rb +94 -0
  179. data/spec/unit/mixin/subclass_directive_spec.rb +45 -0
  180. data/spec/unit/node_spec.rb +9 -1
  181. data/spec/unit/policy_builder/policyfile_spec.rb +2 -0
  182. data/spec/unit/property/validation_spec.rb +14 -12
  183. data/spec/unit/property_spec.rb +56 -0
  184. data/spec/unit/provider/deploy_spec.rb +1 -1
  185. data/spec/unit/provider/dsc_resource_spec.rb +63 -24
  186. data/spec/unit/provider/execute_spec.rb +95 -28
  187. data/spec/unit/provider/package/dpkg_spec.rb +185 -96
  188. data/spec/unit/provider/package/windows/exe_spec.rb +251 -0
  189. data/spec/unit/provider/package/windows/msi_spec.rb +94 -10
  190. data/spec/unit/provider/package/windows_spec.rb +227 -26
  191. data/spec/unit/provider/package/yum_spec.rb +6 -0
  192. data/spec/unit/provider/package_spec.rb +495 -366
  193. data/spec/unit/provider/remote_file/cache_control_data_spec.rb +62 -36
  194. data/spec/unit/provider/script_spec.rb +2 -2
  195. data/spec/unit/provider/service/solaris_smf_service_spec.rb +110 -39
  196. data/spec/unit/provider/service/upstart_service_spec.rb +19 -0
  197. data/spec/unit/provider/user/dscl_spec.rb +14 -0
  198. data/spec/unit/provider/user/windows_spec.rb +2 -2
  199. data/spec/unit/provider/user_spec.rb +9 -0
  200. data/spec/unit/provider_resolver_spec.rb +6 -30
  201. data/spec/unit/recipe_spec.rb +46 -20
  202. data/spec/unit/resource/chef_gem_spec.rb +1 -1
  203. data/spec/unit/resource/dsc_resource_spec.rb +14 -3
  204. data/spec/unit/resource/ksh_spec.rb +40 -0
  205. data/spec/unit/resource/registry_key_spec.rb +2 -2
  206. data/spec/unit/resource/resource_notification_spec.rb +44 -45
  207. data/spec/unit/resource_reporter_spec.rb +7 -0
  208. data/spec/unit/resource_spec.rb +268 -253
  209. data/spec/unit/rest_spec.rb +2 -2
  210. data/spec/unit/run_list/run_list_expansion_spec.rb +18 -3
  211. data/spec/unit/search/query_spec.rb +19 -1
  212. data/spec/unit/util/powershell/ps_credential_spec.rb +8 -1
  213. data/spec/unit/windows_service_spec.rb +83 -38
  214. data/tasks/external_tests.rb +19 -9
  215. data/tasks/rspec.rb +1 -1
  216. metadata +64 -15
  217. data/spec/support/pedant/Gemfile +0 -3
  218. data/spec/support/pedant/pedant_config.rb +0 -129
  219. data/spec/support/pedant/run_pedant.rb +0 -63
  220. data/spec/support/pedant/stickywicket.pem +0 -27
  221. data/spec/unit/provider/package_spec.rbe +0 -0
@@ -50,6 +50,9 @@ describe Chef::ResourceReporter do
50
50
  @events = Chef::EventDispatch::Dispatcher.new
51
51
  @run_context = Chef::RunContext.new(@node, {}, @events)
52
52
  @run_status = Chef::RunStatus.new(@node, @events)
53
+ @run_list = Chef::RunList.new
54
+ @run_list << 'recipe[lobster]' << 'role[rage]' << 'recipe[fist]'
55
+ @expansion = Chef::RunList::RunListExpansion.new("_default", @run_list.run_list_items)
53
56
  @run_id = @run_status.run_id
54
57
  allow(Time).to receive(:now).and_return(@start_time, @end_time)
55
58
  end
@@ -424,6 +427,10 @@ describe Chef::ResourceReporter do
424
427
  expect(@report["run_list"]).to eq(Chef::JSONCompat.to_json(@run_status.node.run_list))
425
428
  end
426
429
 
430
+ it "includes the expanded_run_list" do
431
+ expect(@report).to have_key("expanded_run_list")
432
+ end
433
+
427
434
  it "includes the end_time" do
428
435
  expect(@report).to have_key("end_time")
429
436
  expect(@report["end_time"]).to eq(@run_status.end_time.to_s)
@@ -22,25 +22,24 @@
22
22
  require 'spec_helper'
23
23
 
24
24
  describe Chef::Resource do
25
- before(:each) do
26
- @cookbook_repo_path = File.join(CHEF_SPEC_DATA, 'cookbooks')
27
- @cookbook_collection = Chef::CookbookCollection.new(Chef::CookbookLoader.new(@cookbook_repo_path))
28
- @node = Chef::Node.new
29
- @events = Chef::EventDispatch::Dispatcher.new
30
- @run_context = Chef::RunContext.new(@node, @cookbook_collection, @events)
31
- @resource = Chef::Resource.new("funk", @run_context)
32
- end
25
+ let(:cookbook_repo_path) { File.join(CHEF_SPEC_DATA, 'cookbooks') }
26
+ let(:cookbook_collection) { Chef::CookbookCollection.new(Chef::CookbookLoader.new(cookbook_repo_path)) }
27
+ let(:node) { Chef::Node.new }
28
+ let(:events) { Chef::EventDispatch::Dispatcher.new }
29
+ let(:run_context) { Chef::RunContext.new(node, cookbook_collection, events) }
30
+ let(:resource) { resource_class.new("funk", run_context) }
31
+ let(:resource_class) { Chef::Resource }
33
32
 
34
33
  it "should mixin shell_out" do
35
- expect(@resource.respond_to?(:shell_out)).to be true
34
+ expect(resource.respond_to?(:shell_out)).to be true
36
35
  end
37
36
 
38
37
  it "should mixin shell_out!" do
39
- expect(@resource.respond_to?(:shell_out!)).to be true
38
+ expect(resource.respond_to?(:shell_out!)).to be true
40
39
  end
41
40
 
42
41
  it "should mixin shell_out_with_systems_locale" do
43
- expect(@resource.respond_to?(:shell_out_with_systems_locale)).to be true
42
+ expect(resource.respond_to?(:shell_out_with_systems_locale)).to be true
44
43
  end
45
44
 
46
45
  describe "when inherited" do
@@ -86,30 +85,29 @@ describe Chef::Resource do
86
85
  end
87
86
 
88
87
  describe "when no identity attribute has been declared" do
89
- before do
90
- @resource_sans_id = Chef::Resource.new("my-name")
91
- end
88
+ let(:resource_sans_id) { Chef::Resource.new("my-name") }
92
89
 
93
90
  # Would rather force identity attributes to be set for everything,
94
91
  # but that's not plausible for back compat reasons.
95
92
  it "uses the name as the identity" do
96
- expect(@resource_sans_id.identity).to eq("my-name")
93
+ expect(resource_sans_id.identity).to eq("my-name")
97
94
  end
98
95
  end
99
96
 
100
97
  describe "when an identity attribute has been declared" do
101
- before do
102
- @file_resource_class = Class.new(Chef::Resource) do
98
+ let(:file_resource) {
99
+ file_resource_class = Class.new(Chef::Resource) do
103
100
  identity_attr :path
104
101
  attr_accessor :path
105
102
  end
106
103
 
107
- @file_resource = @file_resource_class.new("identity-attr-test")
108
- @file_resource.path = "/tmp/foo.txt"
109
- end
104
+ file_resource = file_resource_class.new("identity-attr-test")
105
+ file_resource.path = "/tmp/foo.txt"
106
+ file_resource
107
+ }
110
108
 
111
109
  it "gives the value of its identity attribute" do
112
- expect(@file_resource.identity).to eq("/tmp/foo.txt")
110
+ expect(file_resource.identity).to eq("/tmp/foo.txt")
113
111
  end
114
112
  end
115
113
 
@@ -142,8 +140,8 @@ describe Chef::Resource do
142
140
  end
143
141
 
144
142
  describe "when a set of state attributes has been declared" do
145
- before do
146
- @file_resource_class = Class.new(Chef::Resource) do
143
+ let(:file_resource) {
144
+ file_resource_class = Class.new(Chef::Resource) do
147
145
 
148
146
  state_attrs :checksum, :owner, :group, :mode
149
147
 
@@ -153,15 +151,16 @@ describe Chef::Resource do
153
151
  attr_accessor :mode
154
152
  end
155
153
 
156
- @file_resource = @file_resource_class.new("describe-state-test")
157
- @file_resource.checksum = "abc123"
158
- @file_resource.owner = "root"
159
- @file_resource.group = "wheel"
160
- @file_resource.mode = "0644"
161
- end
154
+ file_resource = file_resource_class.new("describe-state-test")
155
+ file_resource.checksum = "abc123"
156
+ file_resource.owner = "root"
157
+ file_resource.group = "wheel"
158
+ file_resource.mode = "0644"
159
+ file_resource
160
+ }
162
161
 
163
162
  it "describes its state" do
164
- resource_state = @file_resource.state
163
+ resource_state = file_resource.state
165
164
  expect(resource_state.keys).to match_array([:checksum, :owner, :group, :mode])
166
165
  expect(resource_state[:checksum]).to eq("abc123")
167
166
  expect(resource_state[:owner]).to eq("root")
@@ -171,157 +170,160 @@ describe Chef::Resource do
171
170
  end
172
171
 
173
172
  describe "load_from" do
173
+ let(:prior_resource) {
174
+ prior_resource = Chef::Resource.new("funk")
175
+ prior_resource.supports(:funky => true)
176
+ prior_resource.source_line
177
+ prior_resource.allowed_actions << :funkytown
178
+ prior_resource.action(:funkytown)
179
+ prior_resource
180
+ }
174
181
  before(:each) do
175
- @prior_resource = Chef::Resource.new("funk")
176
- @prior_resource.supports(:funky => true)
177
- @prior_resource.source_line
178
- @prior_resource.allowed_actions << :funkytown
179
- @prior_resource.action(:funkytown)
180
- @resource.allowed_actions << :funkytown
181
- @run_context.resource_collection << @prior_resource
182
+ resource.allowed_actions << :funkytown
183
+ run_context.resource_collection << prior_resource
182
184
  end
183
185
 
184
186
  it "should load the attributes of a prior resource" do
185
- @resource.load_from(@prior_resource)
186
- expect(@resource.supports).to eq({ :funky => true })
187
+ resource.load_from(prior_resource)
188
+ expect(resource.supports).to eq({ :funky => true })
187
189
  end
188
190
 
189
191
  it "should not inherit the action from the prior resource" do
190
- @resource.load_from(@prior_resource)
191
- expect(@resource.action).not_to eq(@prior_resource.action)
192
+ resource.load_from(prior_resource)
193
+ expect(resource.action).not_to eq(prior_resource.action)
192
194
  end
193
195
  end
194
196
 
195
197
  describe "name" do
196
198
  it "should have a name" do
197
- expect(@resource.name).to eql("funk")
199
+ expect(resource.name).to eql("funk")
198
200
  end
199
201
 
200
202
  it "should let you set a new name" do
201
- @resource.name "monkey"
202
- expect(@resource.name).to eql("monkey")
203
+ resource.name "monkey"
204
+ expect(resource.name).to eql("monkey")
203
205
  end
204
206
 
205
207
  it "coerces arrays to names" do
206
- expect(@resource.name ['a', 'b']).to eql('a, b')
208
+ expect(resource.name ['a', 'b']).to eql('a, b')
207
209
  end
208
210
 
209
211
  it "should coerce objects to a string" do
210
- expect(@resource.name Object.new).to be_a(String)
212
+ expect(resource.name Object.new).to be_a(String)
211
213
  end
212
214
  end
213
215
 
214
216
  describe "noop" do
215
217
  it "should accept true or false for noop" do
216
- expect { @resource.noop true }.not_to raise_error
217
- expect { @resource.noop false }.not_to raise_error
218
- expect { @resource.noop "eat it" }.to raise_error(ArgumentError)
218
+ expect { resource.noop true }.not_to raise_error
219
+ expect { resource.noop false }.not_to raise_error
220
+ expect { resource.noop "eat it" }.to raise_error(ArgumentError)
219
221
  end
220
222
  end
221
223
 
222
224
  describe "notifies" do
223
225
  it "should make notified resources appear in the actions hash" do
224
- @run_context.resource_collection << Chef::Resource::ZenMaster.new("coffee")
225
- @resource.notifies :reload, @run_context.resource_collection.find(:zen_master => "coffee")
226
- expect(@resource.delayed_notifications.detect{|e| e.resource.name == "coffee" && e.action == :reload}).not_to be_nil
226
+ run_context.resource_collection << Chef::Resource::ZenMaster.new("coffee")
227
+ resource.notifies :reload, run_context.resource_collection.find(:zen_master => "coffee")
228
+ expect(resource.delayed_notifications.detect{|e| e.resource.name == "coffee" && e.action == :reload}).not_to be_nil
227
229
  end
228
230
 
229
231
  it "should make notified resources be capable of acting immediately" do
230
- @run_context.resource_collection << Chef::Resource::ZenMaster.new("coffee")
231
- @resource.notifies :reload, @run_context.resource_collection.find(:zen_master => "coffee"), :immediate
232
- expect(@resource.immediate_notifications.detect{|e| e.resource.name == "coffee" && e.action == :reload}).not_to be_nil
232
+ run_context.resource_collection << Chef::Resource::ZenMaster.new("coffee")
233
+ resource.notifies :reload, run_context.resource_collection.find(:zen_master => "coffee"), :immediate
234
+ expect(resource.immediate_notifications.detect{|e| e.resource.name == "coffee" && e.action == :reload}).not_to be_nil
233
235
  end
234
236
 
235
237
  it "should raise an exception if told to act in other than :delay or :immediate(ly)" do
236
- @run_context.resource_collection << Chef::Resource::ZenMaster.new("coffee")
238
+ run_context.resource_collection << Chef::Resource::ZenMaster.new("coffee")
237
239
  expect {
238
- @resource.notifies :reload, @run_context.resource_collection.find(:zen_master => "coffee"), :someday
240
+ resource.notifies :reload, run_context.resource_collection.find(:zen_master => "coffee"), :someday
239
241
  }.to raise_error(ArgumentError)
240
242
  end
241
243
 
242
244
  it "should allow multiple notified resources appear in the actions hash" do
243
- @run_context.resource_collection << Chef::Resource::ZenMaster.new("coffee")
244
- @resource.notifies :reload, @run_context.resource_collection.find(:zen_master => "coffee")
245
- expect(@resource.delayed_notifications.detect{|e| e.resource.name == "coffee" && e.action == :reload}).not_to be_nil
245
+ run_context.resource_collection << Chef::Resource::ZenMaster.new("coffee")
246
+ resource.notifies :reload, run_context.resource_collection.find(:zen_master => "coffee")
247
+ expect(resource.delayed_notifications.detect{|e| e.resource.name == "coffee" && e.action == :reload}).not_to be_nil
246
248
 
247
- @run_context.resource_collection << Chef::Resource::ZenMaster.new("beans")
248
- @resource.notifies :reload, @run_context.resource_collection.find(:zen_master => "beans")
249
- expect(@resource.delayed_notifications.detect{|e| e.resource.name == "beans" && e.action == :reload}).not_to be_nil
249
+ run_context.resource_collection << Chef::Resource::ZenMaster.new("beans")
250
+ resource.notifies :reload, run_context.resource_collection.find(:zen_master => "beans")
251
+ expect(resource.delayed_notifications.detect{|e| e.resource.name == "beans" && e.action == :reload}).not_to be_nil
250
252
  end
251
253
 
252
254
  it "creates a notification for a resource that is not yet in the resource collection" do
253
- @resource.notifies(:restart, :service => 'apache')
254
- expected_notification = Chef::Resource::Notification.new({:service => "apache"}, :restart, @resource)
255
- expect(@resource.delayed_notifications).to include(expected_notification)
255
+ resource.notifies(:restart, :service => 'apache')
256
+ expected_notification = Chef::Resource::Notification.new({:service => "apache"}, :restart, resource)
257
+ expect(resource.delayed_notifications).to include(expected_notification)
256
258
  end
257
259
 
258
260
  it "notifies another resource immediately" do
259
- @resource.notifies_immediately(:restart, :service => 'apache')
260
- expected_notification = Chef::Resource::Notification.new({:service => "apache"}, :restart, @resource)
261
- expect(@resource.immediate_notifications).to include(expected_notification)
261
+ resource.notifies_immediately(:restart, :service => 'apache')
262
+ expected_notification = Chef::Resource::Notification.new({:service => "apache"}, :restart, resource)
263
+ expect(resource.immediate_notifications).to include(expected_notification)
262
264
  end
263
265
 
264
266
  it "notifies a resource to take action at the end of the chef run" do
265
- @resource.notifies_delayed(:restart, :service => "apache")
266
- expected_notification = Chef::Resource::Notification.new({:service => "apache"}, :restart, @resource)
267
- expect(@resource.delayed_notifications).to include(expected_notification)
267
+ resource.notifies_delayed(:restart, :service => "apache")
268
+ expected_notification = Chef::Resource::Notification.new({:service => "apache"}, :restart, resource)
269
+ expect(resource.delayed_notifications).to include(expected_notification)
268
270
  end
269
271
 
270
272
  it "notifies a resource with an array for its name via its prettified string name" do
271
- @run_context.resource_collection << Chef::Resource::ZenMaster.new(["coffee", "tea"])
272
- @resource.notifies :reload, @run_context.resource_collection.find(:zen_master => "coffee, tea")
273
- expect(@resource.delayed_notifications.detect{|e| e.resource.name == "coffee, tea" && e.action == :reload}).not_to be_nil
273
+ run_context.resource_collection << Chef::Resource::ZenMaster.new(["coffee", "tea"])
274
+ resource.notifies :reload, run_context.resource_collection.find(:zen_master => "coffee, tea")
275
+ expect(resource.delayed_notifications.detect{|e| e.resource.name == "coffee, tea" && e.action == :reload}).not_to be_nil
274
276
  end
275
277
  end
276
278
 
277
279
  describe "subscribes" do
278
280
  it "should make resources appear in the actions hash of subscribed nodes" do
279
- @run_context.resource_collection << Chef::Resource::ZenMaster.new("coffee")
280
- zr = @run_context.resource_collection.find(:zen_master => "coffee")
281
- @resource.subscribes :reload, zr
281
+ run_context.resource_collection << Chef::Resource::ZenMaster.new("coffee")
282
+ zr = run_context.resource_collection.find(:zen_master => "coffee")
283
+ resource.subscribes :reload, zr
282
284
  expect(zr.delayed_notifications.detect{|e| e.resource.name == "funk" && e.action == :reload}).not_to be_nil
283
285
  end
284
286
 
285
287
  it "should make resources appear in the actions hash of subscribed nodes" do
286
- @run_context.resource_collection << Chef::Resource::ZenMaster.new("coffee")
287
- zr = @run_context.resource_collection.find(:zen_master => "coffee")
288
- @resource.subscribes :reload, zr
289
- expect(zr.delayed_notifications.detect{|e| e.resource.name == @resource.name && e.action == :reload}).not_to be_nil
288
+ run_context.resource_collection << Chef::Resource::ZenMaster.new("coffee")
289
+ zr = run_context.resource_collection.find(:zen_master => "coffee")
290
+ resource.subscribes :reload, zr
291
+ expect(zr.delayed_notifications.detect{|e| e.resource.name == resource.name && e.action == :reload}).not_to be_nil
290
292
 
291
- @run_context.resource_collection << Chef::Resource::ZenMaster.new("bean")
292
- zrb = @run_context.resource_collection.find(:zen_master => "bean")
293
+ run_context.resource_collection << Chef::Resource::ZenMaster.new("bean")
294
+ zrb = run_context.resource_collection.find(:zen_master => "bean")
293
295
  zrb.subscribes :reload, zr
294
- expect(zr.delayed_notifications.detect{|e| e.resource.name == @resource.name && e.action == :reload}).not_to be_nil
296
+ expect(zr.delayed_notifications.detect{|e| e.resource.name == resource.name && e.action == :reload}).not_to be_nil
295
297
  end
296
298
 
297
299
  it "should make subscribed resources be capable of acting immediately" do
298
- @run_context.resource_collection << Chef::Resource::ZenMaster.new("coffee")
299
- zr = @run_context.resource_collection.find(:zen_master => "coffee")
300
- @resource.subscribes :reload, zr, :immediately
301
- expect(zr.immediate_notifications.detect{|e| e.resource.name == @resource.name && e.action == :reload}).not_to be_nil
300
+ run_context.resource_collection << Chef::Resource::ZenMaster.new("coffee")
301
+ zr = run_context.resource_collection.find(:zen_master => "coffee")
302
+ resource.subscribes :reload, zr, :immediately
303
+ expect(zr.immediate_notifications.detect{|e| e.resource.name == resource.name && e.action == :reload}).not_to be_nil
302
304
  end
303
305
  end
304
306
 
305
307
  describe "defined_at" do
306
308
  it "should correctly parse source_line on unix-like operating systems" do
307
- @resource.source_line = "/some/path/to/file.rb:80:in `wombat_tears'"
308
- expect(@resource.defined_at).to eq("/some/path/to/file.rb line 80")
309
+ resource.source_line = "/some/path/to/file.rb:80:in `wombat_tears'"
310
+ expect(resource.defined_at).to eq("/some/path/to/file.rb line 80")
309
311
  end
310
312
 
311
313
  it "should correctly parse source_line on Windows" do
312
- @resource.source_line = "C:/some/path/to/file.rb:80 in 1`wombat_tears'"
313
- expect(@resource.defined_at).to eq("C:/some/path/to/file.rb line 80")
314
+ resource.source_line = "C:/some/path/to/file.rb:80 in 1`wombat_tears'"
315
+ expect(resource.defined_at).to eq("C:/some/path/to/file.rb line 80")
314
316
  end
315
317
 
316
318
  it "should include the cookbook and recipe when it knows it" do
317
- @resource.source_line = "/some/path/to/file.rb:80:in `wombat_tears'"
318
- @resource.recipe_name = "wombats"
319
- @resource.cookbook_name = "animals"
320
- expect(@resource.defined_at).to eq("animals::wombats line 80")
319
+ resource.source_line = "/some/path/to/file.rb:80:in `wombat_tears'"
320
+ resource.recipe_name = "wombats"
321
+ resource.cookbook_name = "animals"
322
+ expect(resource.defined_at).to eq("animals::wombats line 80")
321
323
  end
322
324
 
323
325
  it "should recognize dynamically defined resources" do
324
- expect(@resource.defined_at).to eq("dynamically defined")
326
+ expect(resource.defined_at).to eq("dynamically defined")
325
327
  end
326
328
  end
327
329
 
@@ -345,7 +347,7 @@ describe Chef::Resource do
345
347
  expect(r.declared_type).to eq :d
346
348
  end
347
349
 
348
- it "and there are no provides lines, @resource_name is used" do
350
+ it "and there are no provides lines, resource_name is used" do
349
351
  c = Class.new(Chef::Resource) do
350
352
  def initialize(*args, &block)
351
353
  @resource_name = :blah
@@ -419,26 +421,39 @@ describe Chef::Resource do
419
421
  end
420
422
 
421
423
  it "should allow arguments preceded by is to methods" do
422
- @resource.noop(@resource.is(true))
423
- expect(@resource.noop).to eql(true)
424
+ resource.noop(resource.is(true))
425
+ expect(resource.noop).to eql(true)
424
426
  end
425
427
  end
426
428
 
427
429
  describe "to_json" do
428
430
  it "should serialize to json" do
429
- json = @resource.to_json
431
+ json = resource.to_json
430
432
  expect(json).to match(/json_class/)
431
433
  expect(json).to match(/instance_vars/)
432
434
  end
433
435
 
434
436
  include_examples "to_json equivalent to Chef::JSONCompat.to_json" do
435
- let(:jsonable) { @resource }
437
+ let(:jsonable) { resource }
436
438
  end
437
439
  end
438
440
 
439
441
  describe "to_hash" do
442
+ context "when the resource has a property with a default" do
443
+ let(:resource_class) { Class.new(Chef::Resource) { property :a, default: 1 } }
444
+ it "should include the default in the hash" do
445
+ expect(resource.to_hash.keys.sort).to eq([:a, :allowed_actions, :params, :provider, :updated,
446
+ :updated_by_last_action, :before, :supports,
447
+ :noop, :ignore_failure, :name, :source_line,
448
+ :action, :retries, :retry_delay, :elapsed_time,
449
+ :default_guard_interpreter, :guard_interpreter, :sensitive].sort)
450
+ expect(resource.to_hash[:name]).to eq "funk"
451
+ expect(resource.to_hash[:a]).to eq 1
452
+ end
453
+ end
454
+
440
455
  it "should convert to a hash" do
441
- hash = @resource.to_hash
456
+ hash = resource.to_hash
442
457
  expected_keys = [ :allowed_actions, :params, :provider, :updated,
443
458
  :updated_by_last_action, :before, :supports,
444
459
  :noop, :ignore_failure, :name, :source_line,
@@ -452,80 +467,83 @@ describe Chef::Resource do
452
467
 
453
468
  describe "self.json_create" do
454
469
  it "should deserialize itself from json" do
455
- json = Chef::JSONCompat.to_json(@resource)
470
+ json = Chef::JSONCompat.to_json(resource)
456
471
  serialized_node = Chef::JSONCompat.from_json(json)
457
472
  expect(serialized_node).to be_a_kind_of(Chef::Resource)
458
- expect(serialized_node.name).to eql(@resource.name)
473
+ expect(serialized_node.name).to eql(resource.name)
459
474
  end
460
475
  end
461
476
 
462
477
  describe "supports" do
463
478
  it "should allow you to set what features this resource supports" do
464
479
  support_hash = { :one => :two }
465
- @resource.supports(support_hash)
466
- expect(@resource.supports).to eql(support_hash)
480
+ resource.supports(support_hash)
481
+ expect(resource.supports).to eql(support_hash)
467
482
  end
468
483
 
469
484
  it "should return the current value of supports" do
470
- expect(@resource.supports).to eq({})
485
+ expect(resource.supports).to eq({})
471
486
  end
472
487
  end
473
488
 
474
489
  describe "ignore_failure" do
475
490
  it "should default to throwing an error if a provider fails for a resource" do
476
- expect(@resource.ignore_failure).to eq(false)
491
+ expect(resource.ignore_failure).to eq(false)
477
492
  end
478
493
 
479
494
  it "should allow you to set whether a provider should throw exceptions with ignore_failure" do
480
- @resource.ignore_failure(true)
481
- expect(@resource.ignore_failure).to eq(true)
495
+ resource.ignore_failure(true)
496
+ expect(resource.ignore_failure).to eq(true)
482
497
  end
483
498
 
484
499
  it "should allow you to epic_fail" do
485
- @resource.epic_fail(true)
486
- expect(@resource.epic_fail).to eq(true)
500
+ resource.epic_fail(true)
501
+ expect(resource.epic_fail).to eq(true)
487
502
  end
488
503
  end
489
504
 
490
505
  describe "retries" do
491
- before do
492
- @retriable_resource = Chef::Resource::Cat.new("precious", @run_context)
493
- @retriable_resource.provider = Chef::Provider::SnakeOil
494
- @retriable_resource.action = :purr
506
+ let(:retriable_resource) {
507
+ retriable_resource = Chef::Resource::Cat.new("precious", run_context)
508
+ retriable_resource.provider = Chef::Provider::SnakeOil
509
+ retriable_resource.action = :purr
510
+ retriable_resource
511
+ }
495
512
 
496
- @node.automatic_attrs[:platform] = "fubuntu"
497
- @node.automatic_attrs[:platform_version] = '10.04'
513
+ before do
514
+ node.automatic_attrs[:platform] = "fubuntu"
515
+ node.automatic_attrs[:platform_version] = '10.04'
498
516
  end
499
517
 
500
518
  it "should default to not retrying if a provider fails for a resource" do
501
- expect(@retriable_resource.retries).to eq(0)
519
+ expect(retriable_resource.retries).to eq(0)
502
520
  end
503
521
 
504
522
  it "should allow you to set how many retries a provider should attempt after a failure" do
505
- @retriable_resource.retries(2)
506
- expect(@retriable_resource.retries).to eq(2)
523
+ retriable_resource.retries(2)
524
+ expect(retriable_resource.retries).to eq(2)
507
525
  end
508
526
 
509
527
  it "should default to a retry delay of 2 seconds" do
510
- expect(@retriable_resource.retry_delay).to eq(2)
528
+ expect(retriable_resource.retry_delay).to eq(2)
511
529
  end
512
530
 
513
531
  it "should allow you to set the retry delay" do
514
- @retriable_resource.retry_delay(10)
515
- expect(@retriable_resource.retry_delay).to eq(10)
532
+ retriable_resource.retry_delay(10)
533
+ expect(retriable_resource.retry_delay).to eq(10)
516
534
  end
517
535
 
518
536
  it "should keep given value of retries intact after the provider fails for a resource" do
519
- @retriable_resource.retries(3)
520
- @retriable_resource.retry_delay(0) # No need to wait.
537
+ retriable_resource.retries(3)
538
+ retriable_resource.retry_delay(0) # No need to wait.
521
539
 
522
- provider = Chef::Provider::SnakeOil.new(@retriable_resource, @run_context)
540
+ provider = Chef::Provider::SnakeOil.new(retriable_resource, run_context)
523
541
  allow(Chef::Provider::SnakeOil).to receive(:new).and_return(provider)
524
542
  allow(provider).to receive(:action_purr).and_raise
525
543
 
526
- expect(@retriable_resource).to receive(:sleep).exactly(3).times
527
- expect { @retriable_resource.run_action(:purr) }.to raise_error
528
- expect(@retriable_resource.retries).to eq(3)
544
+ expect(retriable_resource).to receive(:sleep).exactly(3).times
545
+ expect { retriable_resource.run_action(:purr) }.to raise_error
546
+ expect(retriable_resource.retries).to eq(3)
529
547
  end
530
548
  end
531
549
 
@@ -560,28 +578,28 @@ describe Chef::Resource do
560
578
 
561
579
  describe "when updated by a provider" do
562
580
  before do
563
- @resource.updated_by_last_action(true)
581
+ resource.updated_by_last_action(true)
564
582
  end
565
583
 
566
584
  it "records that it was updated" do
567
- expect(@resource).to be_updated
585
+ expect(resource).to be_updated
568
586
  end
569
587
 
570
588
  it "records that the last action updated the resource" do
571
- expect(@resource).to be_updated_by_last_action
589
+ expect(resource).to be_updated_by_last_action
572
590
  end
573
591
 
574
592
  describe "and then run again without being updated" do
575
593
  before do
576
- @resource.updated_by_last_action(false)
594
+ resource.updated_by_last_action(false)
577
595
  end
578
596
 
579
597
  it "reports that it is updated" do
580
- expect(@resource).to be_updated
598
+ expect(resource).to be_updated
581
599
  end
582
600
 
583
601
  it "reports that it was not updated by the last action" do
584
- expect(@resource).not_to be_updated_by_last_action
602
+ expect(resource).not_to be_updated_by_last_action
585
603
  end
586
604
 
587
605
  end
@@ -589,72 +607,75 @@ describe Chef::Resource do
589
607
  end
590
608
 
591
609
  describe "when invoking its action" do
610
+ let(:resource) {
611
+ resource = Chef::Resource.new("provided", run_context)
612
+ resource.provider = Chef::Provider::SnakeOil
613
+ resource
614
+ }
592
615
  before do
593
- @resource = Chef::Resource.new("provided", @run_context)
594
- @resource.provider = Chef::Provider::SnakeOil
595
- @node.automatic_attrs[:platform] = "fubuntu"
596
- @node.automatic_attrs[:platform_version] = '10.04'
616
+ node.automatic_attrs[:platform] = "fubuntu"
617
+ node.automatic_attrs[:platform_version] = '10.04'
597
618
  end
598
619
 
599
620
  it "does not run only_if if no only_if command is given" do
600
621
  expect_any_instance_of(Chef::Resource::Conditional).not_to receive(:evaluate)
601
- @resource.only_if.clear
602
- @resource.run_action(:purr)
622
+ resource.only_if.clear
623
+ resource.run_action(:purr)
603
624
  end
604
625
 
605
626
  it "runs runs an only_if when one is given" do
606
627
  snitch_variable = nil
607
- @resource.only_if { snitch_variable = true }
608
- expect(@resource.only_if.first.positivity).to eq(:only_if)
628
+ resource.only_if { snitch_variable = true }
629
+ expect(resource.only_if.first.positivity).to eq(:only_if)
609
630
  #Chef::Mixin::Command.should_receive(:only_if).with(true, {}).and_return(false)
610
- @resource.run_action(:purr)
631
+ resource.run_action(:purr)
611
632
  expect(snitch_variable).to be_truthy
612
633
  end
613
634
 
614
635
  it "runs multiple only_if conditionals" do
615
636
  snitch_var1, snitch_var2 = nil, nil
616
- @resource.only_if { snitch_var1 = 1 }
617
- @resource.only_if { snitch_var2 = 2 }
618
- @resource.run_action(:purr)
637
+ resource.only_if { snitch_var1 = 1 }
638
+ resource.only_if { snitch_var2 = 2 }
639
+ resource.run_action(:purr)
619
640
  expect(snitch_var1).to eq(1)
620
641
  expect(snitch_var2).to eq(2)
621
642
  end
622
643
 
623
644
  it "accepts command options for only_if conditionals" do
624
645
  expect_any_instance_of(Chef::Resource::Conditional).to receive(:evaluate_command).at_least(1).times
625
- @resource.only_if("true", :cwd => '/tmp')
626
- expect(@resource.only_if.first.command_opts).to eq({:cwd => '/tmp'})
627
- @resource.run_action(:purr)
646
+ resource.only_if("true", :cwd => '/tmp')
647
+ expect(resource.only_if.first.command_opts).to eq({:cwd => '/tmp'})
648
+ resource.run_action(:purr)
628
649
  end
629
650
 
630
651
  it "runs not_if as a command when it is a string" do
631
652
  expect_any_instance_of(Chef::Resource::Conditional).to receive(:evaluate_command).at_least(1).times
632
- @resource.not_if "pwd"
633
- @resource.run_action(:purr)
653
+ resource.not_if "pwd"
654
+ resource.run_action(:purr)
634
655
  end
635
656
 
636
657
  it "runs not_if as a block when it is a ruby block" do
637
658
  expect_any_instance_of(Chef::Resource::Conditional).to receive(:evaluate_block).at_least(1).times
638
- @resource.not_if { puts 'foo' }
639
- @resource.run_action(:purr)
659
+ resource.not_if { puts 'foo' }
660
+ resource.run_action(:purr)
640
661
  end
641
662
 
642
663
  it "does not run not_if if no not_if command is given" do
643
664
  expect_any_instance_of(Chef::Resource::Conditional).not_to receive(:evaluate)
644
- @resource.not_if.clear
645
- @resource.run_action(:purr)
665
+ resource.not_if.clear
666
+ resource.run_action(:purr)
646
667
  end
647
668
 
648
669
  it "accepts command options for not_if conditionals" do
649
- @resource.not_if("pwd" , :cwd => '/tmp')
650
- expect(@resource.not_if.first.command_opts).to eq({:cwd => '/tmp'})
670
+ resource.not_if("pwd" , :cwd => '/tmp')
671
+ expect(resource.not_if.first.command_opts).to eq({:cwd => '/tmp'})
651
672
  end
652
673
 
653
674
  it "accepts multiple not_if conditionals" do
654
675
  snitch_var1, snitch_var2 = true, true
655
- @resource.not_if {snitch_var1 = nil}
656
- @resource.not_if {snitch_var2 = false}
657
- @resource.run_action(:purr)
676
+ resource.not_if {snitch_var1 = nil}
677
+ resource.not_if {snitch_var2 = false}
678
+ resource.run_action(:purr)
658
679
  expect(snitch_var1).to be_nil
659
680
  expect(snitch_var2).to be_falsey
660
681
  end
@@ -662,13 +683,11 @@ describe Chef::Resource do
662
683
  it "reports 0 elapsed time if actual elapsed time is < 0" do
663
684
  expected = Time.now
664
685
  allow(Time).to receive(:now).and_return(expected, expected - 1)
665
- @resource.run_action(:purr)
666
- expect(@resource.elapsed_time).to eq(0)
686
+ resource.run_action(:purr)
687
+ expect(resource.elapsed_time).to eq(0)
667
688
  end
668
689
 
669
690
  describe "guard_interpreter attribute" do
670
- let(:resource) { @resource }
671
-
672
691
  it "should be set to :default by default" do
673
692
  expect(resource.guard_interpreter).to eq(:default)
674
693
  end
@@ -691,106 +710,108 @@ describe Chef::Resource do
691
710
 
692
711
  describe "should_skip?" do
693
712
  before do
694
- @resource = Chef::Resource::Cat.new("sugar", @run_context)
713
+ resource = Chef::Resource::Cat.new("sugar", run_context)
695
714
  end
696
715
 
697
716
  it "should return false by default" do
698
- expect(@resource.should_skip?(:purr)).to be_falsey
717
+ expect(resource.should_skip?(:purr)).to be_falsey
699
718
  end
700
719
 
701
720
  it "should return false when only_if is met" do
702
- @resource.only_if { true }
703
- expect(@resource.should_skip?(:purr)).to be_falsey
721
+ resource.only_if { true }
722
+ expect(resource.should_skip?(:purr)).to be_falsey
704
723
  end
705
724
 
706
725
  it "should return true when only_if is not met" do
707
- @resource.only_if { false }
708
- expect(@resource.should_skip?(:purr)).to be_truthy
726
+ resource.only_if { false }
727
+ expect(resource.should_skip?(:purr)).to be_truthy
709
728
  end
710
729
 
711
730
  it "should return true when not_if is met" do
712
- @resource.not_if { true }
713
- expect(@resource.should_skip?(:purr)).to be_truthy
731
+ resource.not_if { true }
732
+ expect(resource.should_skip?(:purr)).to be_truthy
714
733
  end
715
734
 
716
735
  it "should return false when not_if is not met" do
717
- @resource.not_if { false }
718
- expect(@resource.should_skip?(:purr)).to be_falsey
736
+ resource.not_if { false }
737
+ expect(resource.should_skip?(:purr)).to be_falsey
719
738
  end
720
739
 
721
740
  it "should return true when only_if is met but also not_if is met" do
722
- @resource.only_if { true }
723
- @resource.not_if { true }
724
- expect(@resource.should_skip?(:purr)).to be_truthy
741
+ resource.only_if { true }
742
+ resource.not_if { true }
743
+ expect(resource.should_skip?(:purr)).to be_truthy
725
744
  end
726
745
 
727
746
  it "should return true when one of multiple only_if's is not met" do
728
- @resource.only_if { true }
729
- @resource.only_if { false }
730
- @resource.only_if { true }
731
- expect(@resource.should_skip?(:purr)).to be_truthy
747
+ resource.only_if { true }
748
+ resource.only_if { false }
749
+ resource.only_if { true }
750
+ expect(resource.should_skip?(:purr)).to be_truthy
732
751
  end
733
752
 
734
753
  it "should return true when one of multiple not_if's is met" do
735
- @resource.not_if { false }
736
- @resource.not_if { true }
737
- @resource.not_if { false }
738
- expect(@resource.should_skip?(:purr)).to be_truthy
754
+ resource.not_if { false }
755
+ resource.not_if { true }
756
+ resource.not_if { false }
757
+ expect(resource.should_skip?(:purr)).to be_truthy
739
758
  end
740
759
 
741
760
  it "should return true when action is :nothing" do
742
- expect(@resource.should_skip?(:nothing)).to be_truthy
761
+ expect(resource.should_skip?(:nothing)).to be_truthy
743
762
  end
744
763
 
745
764
  it "should return true when action is :nothing ignoring only_if/not_if conditionals" do
746
- @resource.only_if { true }
747
- @resource.not_if { false }
748
- expect(@resource.should_skip?(:nothing)).to be_truthy
765
+ resource.only_if { true }
766
+ resource.not_if { false }
767
+ expect(resource.should_skip?(:nothing)).to be_truthy
749
768
  end
750
769
 
751
770
  it "should print \"skipped due to action :nothing\" message for doc formatter when action is :nothing" do
752
771
  fdoc = Chef::Formatters.new(:doc, STDOUT, STDERR)
753
- allow(@run_context).to receive(:events).and_return(fdoc)
772
+ allow(run_context).to receive(:events).and_return(fdoc)
754
773
  expect(fdoc).to receive(:puts).with(" (skipped due to action :nothing)", anything())
755
- @resource.should_skip?(:nothing)
774
+ resource.should_skip?(:nothing)
756
775
  end
757
776
 
758
777
  end
759
778
 
760
779
  describe "when resource action is :nothing" do
780
+ let(:resource1) {
781
+ resource1 = Chef::Resource::Cat.new("sugar", run_context)
782
+ resource1.action = :nothing
783
+ resource1
784
+ }
761
785
  before do
762
- @resource1 = Chef::Resource::Cat.new("sugar", @run_context)
763
- @resource1.action = :nothing
764
-
765
- @node.automatic_attrs[:platform] = "fubuntu"
766
- @node.automatic_attrs[:platform_version] = '10.04'
786
+ node.automatic_attrs[:platform] = "fubuntu"
787
+ node.automatic_attrs[:platform_version] = '10.04'
767
788
  end
768
789
 
769
790
  it "should not run only_if/not_if conditionals (CHEF-972)" do
770
791
  snitch_var1 = 0
771
- @resource1.only_if { snitch_var1 = 1 }
772
- @resource1.not_if { snitch_var1 = 2 }
773
- @resource1.run_action(:nothing)
792
+ resource1.only_if { snitch_var1 = 1 }
793
+ resource1.not_if { snitch_var1 = 2 }
794
+ resource1.run_action(:nothing)
774
795
  expect(snitch_var1).to eq(0)
775
796
  end
776
797
 
777
798
  it "should run only_if/not_if conditionals when notified to run another action (CHEF-972)" do
778
799
  snitch_var1 = snitch_var2 = 0
779
- @runner = Chef::Runner.new(@run_context)
800
+ runner = Chef::Runner.new(run_context)
780
801
  Chef::Platform.set(
781
802
  :resource => :cat,
782
803
  :provider => Chef::Provider::SnakeOil
783
804
  )
784
805
 
785
- @resource1.only_if { snitch_var1 = 1 }
786
- @resource1.not_if { snitch_var2 = 2 }
787
- @resource2 = Chef::Resource::Cat.new("coffee", @run_context)
788
- @resource2.notifies :purr, @resource1
789
- @resource2.action = :purr
806
+ resource1.only_if { snitch_var1 = 1 }
807
+ resource1.not_if { snitch_var2 = 2 }
808
+ resource2 = Chef::Resource::Cat.new("coffee", run_context)
809
+ resource2.notifies :purr, resource1
810
+ resource2.action = :purr
790
811
 
791
- @run_context.resource_collection << @resource1
792
- @run_context.resource_collection << @resource2
793
- @runner.converge
812
+ run_context.resource_collection << resource1
813
+ run_context.resource_collection << resource2
814
+ runner.converge
794
815
 
795
816
  expect(snitch_var1).to eq(1)
796
817
  expect(snitch_var2).to eq(2)
@@ -838,10 +859,10 @@ describe Chef::Resource do
838
859
 
839
860
  before(:each) do
840
861
  Chef::Resource::Klz1 = klz1
841
- @node = Chef::Node.new
842
- @node.name("bumblebee")
843
- @node.automatic[:platform] = "autobots"
844
- @node.automatic[:platform_version] = "6.1"
862
+ node = Chef::Node.new
863
+ node.name("bumblebee")
864
+ node.automatic[:platform] = "autobots"
865
+ node.automatic[:platform_version] = "6.1"
845
866
  Object.const_set('Soundwave', klz1)
846
867
  klz1.provides :soundwave
847
868
  end
@@ -852,7 +873,7 @@ describe Chef::Resource do
852
873
  end
853
874
 
854
875
  it "returns a resource by short_name if nothing else matches" do
855
- expect(Chef::Resource.resource_for_node(:soundwave, @node)).to eql(klz1)
876
+ expect(Chef::Resource.resource_for_node(:soundwave, node)).to eql(klz1)
856
877
  end
857
878
  end
858
879
 
@@ -861,10 +882,9 @@ describe Chef::Resource do
861
882
 
862
883
  before(:each) do
863
884
  Chef::Resource::Klz2 = klz2
864
- @node = Chef::Node.new
865
- @node.name("bumblebee")
866
- @node.automatic[:platform] = "autobots"
867
- @node.automatic[:platform_version] = "6.1"
885
+ node.name("bumblebee")
886
+ node.automatic[:platform] = "autobots"
887
+ node.automatic[:platform_version] = "6.1"
868
888
  klz2.provides :dinobot, :platform => ['autobots']
869
889
  Object.const_set('Grimlock', klz2)
870
890
  klz2.provides :grimlock
@@ -876,7 +896,7 @@ describe Chef::Resource do
876
896
  end
877
897
 
878
898
  it "returns a resource by short_name and node" do
879
- expect(Chef::Resource.resource_for_node(:dinobot, @node)).to eql(klz2)
899
+ expect(Chef::Resource.resource_for_node(:dinobot, node)).to eql(klz2)
880
900
  end
881
901
  end
882
902
 
@@ -887,69 +907,64 @@ describe Chef::Resource do
887
907
  describe "with a string resource spec" do
888
908
 
889
909
  it "creates a delayed notification when timing is not specified" do
890
- @resource.notifies(:run, "execute[foo]")
891
- expect(@run_context.delayed_notification_collection.size).to eq(1)
910
+ resource.notifies(:run, "execute[foo]")
911
+ expect(run_context.delayed_notification_collection.size).to eq(1)
892
912
  end
893
913
 
894
914
  it "creates a delayed notification when :delayed is not specified" do
895
- @resource.notifies(:run, "execute[foo]", :delayed)
896
- expect(@run_context.delayed_notification_collection.size).to eq(1)
915
+ resource.notifies(:run, "execute[foo]", :delayed)
916
+ expect(run_context.delayed_notification_collection.size).to eq(1)
897
917
  end
898
918
 
899
919
  it "creates an immediate notification when :immediate is specified" do
900
- @resource.notifies(:run, "execute[foo]", :immediate)
901
- expect(@run_context.immediate_notification_collection.size).to eq(1)
920
+ resource.notifies(:run, "execute[foo]", :immediate)
921
+ expect(run_context.immediate_notification_collection.size).to eq(1)
902
922
  end
903
923
 
904
924
  it "creates an immediate notification when :immediately is specified" do
905
- @resource.notifies(:run, "execute[foo]", :immediately)
906
- expect(@run_context.immediate_notification_collection.size).to eq(1)
925
+ resource.notifies(:run, "execute[foo]", :immediately)
926
+ expect(run_context.immediate_notification_collection.size).to eq(1)
907
927
  end
908
928
 
909
929
  describe "with a syntax error in the resource spec" do
910
930
 
911
931
  it "raises an exception immmediately" do
912
932
  expect do
913
- @resource.notifies(:run, "typo[missing-closing-bracket")
933
+ resource.notifies(:run, "typo[missing-closing-bracket")
914
934
  end.to raise_error(Chef::Exceptions::InvalidResourceSpecification)
915
935
  end
916
936
  end
917
937
  end
918
938
 
919
939
  describe "with a resource reference" do
920
- before do
921
- @notified_resource = Chef::Resource.new("punk", @run_context)
922
- end
940
+ let(:notified_resource) { Chef::Resource.new("punk", run_context) }
923
941
 
924
942
  it "creates a delayed notification when timing is not specified" do
925
- @resource.notifies(:run, @notified_resource)
926
- expect(@run_context.delayed_notification_collection.size).to eq(1)
943
+ resource.notifies(:run, notified_resource)
944
+ expect(run_context.delayed_notification_collection.size).to eq(1)
927
945
  end
928
946
 
929
947
  it "creates a delayed notification when :delayed is not specified" do
930
- @resource.notifies(:run, @notified_resource, :delayed)
931
- expect(@run_context.delayed_notification_collection.size).to eq(1)
948
+ resource.notifies(:run, notified_resource, :delayed)
949
+ expect(run_context.delayed_notification_collection.size).to eq(1)
932
950
  end
933
951
 
934
952
  it "creates an immediate notification when :immediate is specified" do
935
- @resource.notifies(:run, @notified_resource, :immediate)
936
- expect(@run_context.immediate_notification_collection.size).to eq(1)
953
+ resource.notifies(:run, notified_resource, :immediate)
954
+ expect(run_context.immediate_notification_collection.size).to eq(1)
937
955
  end
938
956
 
939
957
  it "creates an immediate notification when :immediately is specified" do
940
- @resource.notifies(:run, @notified_resource, :immediately)
941
- expect(@run_context.immediate_notification_collection.size).to eq(1)
958
+ resource.notifies(:run, notified_resource, :immediately)
959
+ expect(run_context.immediate_notification_collection.size).to eq(1)
942
960
  end
943
961
  end
944
962
 
945
963
  end
946
964
 
947
965
  describe "resource sensitive attribute" do
948
-
949
- before(:each) do
950
- @resource_file = Chef::Resource::File.new("/nonexistent/CHEF-5098/file", @run_context)
951
- @action = :create
952
- end
966
+ let(:resource_file) { Chef::Resource::File.new("/nonexistent/CHEF-5098/file", run_context) }
967
+ let(:action) { :create }
953
968
 
954
969
  def compiled_resource_data(resource, action, err)
955
970
  error_inspector = Chef::Formatters::ErrorInspectors::ResourceFailureInspector.new(resource, action, err)
@@ -960,19 +975,19 @@ describe Chef::Resource do
960
975
  end
961
976
 
962
977
  it "set to false by default" do
963
- expect(@resource.sensitive).to be_falsey
978
+ expect(resource.sensitive).to be_falsey
964
979
  end
965
980
 
966
981
  it "when set to false should show compiled resource for failed resource" do
967
- expect { @resource_file.run_action(@action) }.to raise_error { |err|
968
- expect(compiled_resource_data(@resource_file, @action, err)).to match 'path "/nonexistent/CHEF-5098/file"'
982
+ expect { resource_file.run_action(action) }.to raise_error { |err|
983
+ expect(compiled_resource_data(resource_file, action, err)).to match 'path "/nonexistent/CHEF-5098/file"'
969
984
  }
970
985
  end
971
986
 
972
987
  it "when set to true should show compiled resource for failed resource" do
973
- @resource_file.sensitive true
974
- expect { @resource_file.run_action(@action) }.to raise_error { |err|
975
- expect(compiled_resource_data(@resource_file, @action, err)).to eql("suppressed sensitive resource output")
988
+ resource_file.sensitive true
989
+ expect { resource_file.run_action(action) }.to raise_error { |err|
990
+ expect(compiled_resource_data(resource_file, action, err)).to eql("suppressed sensitive resource output")
976
991
  }
977
992
  end
978
993