chef 13.6.4-universal-mingw32 → 13.7.16-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (269) hide show
  1. checksums.yaml +5 -5
  2. data/VERSION +1 -1
  3. data/acceptance/Gemfile +2 -2
  4. data/acceptance/top-cookbooks/.acceptance/acceptance-cookbook/libraries/top_cookbooks.rb +1 -6
  5. data/distro/powershell/chef/chef.psm1 +1 -5
  6. data/lib/chef/api_client.rb +5 -5
  7. data/lib/chef/api_client_v1.rb +6 -6
  8. data/lib/chef/application.rb +3 -2
  9. data/lib/chef/application/knife.rb +4 -0
  10. data/lib/chef/chef_class.rb +2 -2
  11. data/lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb +1 -1
  12. data/lib/chef/chef_fs/data_handler/data_handler_base.rb +2 -4
  13. data/lib/chef/client.rb +3 -3
  14. data/lib/chef/cookbook/chefignore.rb +4 -0
  15. data/lib/chef/cookbook/cookbook_collection.rb +2 -2
  16. data/lib/chef/cookbook/metadata.rb +2 -2
  17. data/lib/chef/data_bag.rb +1 -1
  18. data/lib/chef/deprecated.rb +10 -0
  19. data/lib/chef/event_dispatch/base.rb +2 -2
  20. data/lib/chef/http.rb +10 -10
  21. data/lib/chef/knife.rb +16 -15
  22. data/lib/chef/knife/configure.rb +12 -36
  23. data/lib/chef/knife/cookbook_upload.rb +4 -4
  24. data/lib/chef/knife/core/bootstrap_context.rb +1 -1
  25. data/lib/chef/knife/core/status_presenter.rb +6 -2
  26. data/lib/chef/knife/core/ui.rb +1 -1
  27. data/lib/chef/knife/data_bag_secret_options.rb +1 -1
  28. data/lib/chef/knife/data_bag_show.rb +1 -1
  29. data/lib/chef/knife/edit.rb +1 -1
  30. data/lib/chef/knife/ssh.rb +47 -35
  31. data/lib/chef/knife/user_create.rb +2 -0
  32. data/lib/chef/knife/user_delete.rb +2 -0
  33. data/lib/chef/knife/user_edit.rb +2 -0
  34. data/lib/chef/knife/user_reregister.rb +2 -0
  35. data/lib/chef/knife/user_show.rb +2 -0
  36. data/lib/chef/mixin/powershell_out.rb +1 -1
  37. data/lib/chef/node/attribute.rb +46 -70
  38. data/lib/chef/node/attribute_collections.rb +5 -5
  39. data/lib/chef/node/common_api.rb +1 -1
  40. data/lib/chef/node/immutable_collections.rb +180 -23
  41. data/lib/chef/node/mixin/state_tracking.rb +6 -6
  42. data/lib/chef/node_map.rb +63 -45
  43. data/lib/chef/property.rb +8 -8
  44. data/lib/chef/provider.rb +9 -3
  45. data/lib/chef/provider/apt_preference.rb +1 -1
  46. data/lib/chef/provider/apt_repository.rb +1 -1
  47. data/lib/chef/provider/apt_update.rb +1 -1
  48. data/lib/chef/provider/file.rb +1 -1
  49. data/lib/chef/provider/group/dscl.rb +6 -2
  50. data/lib/chef/provider/ifconfig.rb +96 -34
  51. data/lib/chef/provider/launchd.rb +0 -1
  52. data/lib/chef/provider/log.rb +3 -13
  53. data/lib/chef/provider/package/dnf.rb +1 -1
  54. data/lib/chef/provider/package/smartos.rb +2 -2
  55. data/lib/chef/provider/reboot.rb +12 -0
  56. data/lib/chef/provider/remote_directory.rb +1 -1
  57. data/lib/chef/provider/remote_file/http.rb +3 -2
  58. data/lib/chef/provider/service/solaris.rb +6 -2
  59. data/lib/chef/provider/systemd_unit.rb +34 -33
  60. data/lib/chef/provider/user/dscl.rb +1 -1
  61. data/lib/chef/provider/windows_path.rb +6 -7
  62. data/lib/chef/provider/windows_task.rb +89 -33
  63. data/lib/chef/provider/yum_repository.rb +24 -9
  64. data/lib/chef/resource/apt_package.rb +1 -0
  65. data/lib/chef/resource/apt_preference.rb +4 -0
  66. data/lib/chef/resource/apt_repository.rb +4 -0
  67. data/lib/chef/resource/apt_update.rb +3 -0
  68. data/lib/chef/resource/bash.rb +4 -0
  69. data/lib/chef/resource/batch.rb +5 -0
  70. data/lib/chef/resource/bff_package.rb +4 -0
  71. data/lib/chef/resource/breakpoint.rb +6 -0
  72. data/lib/chef/resource/cab_package.rb +6 -6
  73. data/lib/chef/resource/chef_gem.rb +13 -0
  74. data/lib/chef/resource/chocolatey_package.rb +4 -6
  75. data/lib/chef/resource/cookbook_file.rb +13 -15
  76. data/lib/chef/resource/cron.rb +2 -0
  77. data/lib/chef/resource/csh.rb +4 -0
  78. data/lib/chef/resource/directory.rb +8 -26
  79. data/lib/chef/resource/dnf_package.rb +5 -0
  80. data/lib/chef/resource/dpkg_package.rb +2 -0
  81. data/lib/chef/resource/dsc_resource.rb +5 -0
  82. data/lib/chef/resource/dsc_script.rb +6 -0
  83. data/lib/chef/resource/env.rb +3 -0
  84. data/lib/chef/resource/erl_call.rb +5 -0
  85. data/lib/chef/resource/execute.rb +5 -1
  86. data/lib/chef/resource/file.rb +2 -1
  87. data/lib/chef/resource/file/verification.rb +10 -0
  88. data/lib/chef/resource/freebsd_package.rb +10 -2
  89. data/lib/chef/resource/gem_package.rb +2 -0
  90. data/lib/chef/resource/git.rb +2 -0
  91. data/lib/chef/resource/group.rb +1 -0
  92. data/lib/chef/resource/homebrew_package.rb +3 -0
  93. data/lib/chef/resource/http_request.rb +2 -0
  94. data/lib/chef/resource/ifconfig.rb +23 -150
  95. data/lib/chef/resource/ips_package.rb +1 -0
  96. data/lib/chef/resource/ksh.rb +6 -0
  97. data/lib/chef/resource/launchd.rb +5 -4
  98. data/lib/chef/resource/link.rb +10 -0
  99. data/lib/chef/resource/log.rb +19 -46
  100. data/lib/chef/resource/macports_package.rb +1 -0
  101. data/lib/chef/resource/mdadm.rb +4 -0
  102. data/lib/chef/resource/mount.rb +1 -0
  103. data/lib/chef/resource/msu_package.rb +7 -8
  104. data/lib/chef/resource/ohai.rb +2 -0
  105. data/lib/chef/resource/openbsd_package.rb +3 -0
  106. data/lib/chef/resource/osx_profile.rb +10 -40
  107. data/lib/chef/resource/package.rb +6 -0
  108. data/lib/chef/resource/pacman_package.rb +1 -0
  109. data/lib/chef/resource/paludis_package.rb +3 -0
  110. data/lib/chef/resource/perl.rb +4 -0
  111. data/lib/chef/resource/portage_package.rb +1 -0
  112. data/lib/chef/resource/powershell_package.rb +5 -0
  113. data/lib/chef/resource/powershell_script.rb +8 -0
  114. data/lib/chef/resource/python.rb +4 -0
  115. data/lib/chef/resource/reboot.rb +14 -20
  116. data/lib/chef/resource/registry_key.rb +1 -0
  117. data/lib/chef/resource/remote_directory.rb +3 -0
  118. data/lib/chef/resource/remote_file.rb +2 -0
  119. data/lib/chef/resource/resource_notification.rb +17 -0
  120. data/lib/chef/resource/route.rb +1 -0
  121. data/lib/chef/resource/rpm_package.rb +1 -0
  122. data/lib/chef/resource/ruby.rb +4 -0
  123. data/lib/chef/resource/ruby_block.rb +3 -0
  124. data/lib/chef/resource/script.rb +4 -0
  125. data/lib/chef/resource/service.rb +1 -0
  126. data/lib/chef/resource/smartos_package.rb +1 -0
  127. data/lib/chef/resource/solaris_package.rb +1 -0
  128. data/lib/chef/resource/subversion.rb +1 -0
  129. data/lib/chef/resource/systemd_unit.rb +6 -0
  130. data/lib/chef/resource/template.rb +9 -0
  131. data/lib/chef/resource/user.rb +1 -0
  132. data/lib/chef/resource/windows_package.rb +2 -0
  133. data/lib/chef/resource/windows_path.rb +5 -10
  134. data/lib/chef/resource/windows_service.rb +3 -0
  135. data/lib/chef/resource/windows_task.rb +66 -87
  136. data/lib/chef/resource/yum_repository.rb +26 -22
  137. data/lib/chef/resource/zypper_package.rb +2 -0
  138. data/lib/chef/resource/zypper_repository.rb +6 -1
  139. data/lib/chef/run_context.rb +8 -2
  140. data/lib/chef/server_api.rb +1 -0
  141. data/lib/chef/util/selinux.rb +5 -4
  142. data/lib/chef/version.rb +1 -1
  143. data/lib/chef/version/platform.rb +18 -0
  144. data/lib/chef/version_constraint/platform.rb +2 -0
  145. data/spec/data/client.d_00/02-strings.rb +2 -0
  146. data/spec/functional/assets/chefinittest +6 -4
  147. data/spec/functional/knife/ssh_spec.rb +54 -7
  148. data/spec/functional/resource/bff_spec.rb +3 -3
  149. data/spec/functional/resource/ifconfig_spec.rb +1 -1
  150. data/spec/functional/resource/mount_spec.rb +7 -3
  151. data/spec/functional/resource/user/useradd_spec.rb +4 -4
  152. data/spec/functional/resource/windows_task_spec.rb +6 -6
  153. data/spec/functional/win32/security_spec.rb +7 -33
  154. data/spec/integration/knife/data_bag_show_spec.rb +1 -1
  155. data/spec/integration/recipes/noop_resource_spec.rb +1 -1
  156. data/spec/integration/recipes/recipe_dsl_spec.rb +30 -30
  157. data/spec/integration/recipes/resource_action_spec.rb +2 -2
  158. data/spec/integration/recipes/resource_converge_if_changed_spec.rb +71 -15
  159. data/spec/spec_helper.rb +19 -0
  160. data/spec/support/shared/functional/execute_resource.rb +1 -1
  161. data/spec/support/shared/unit/application_dot_d.rb +2 -0
  162. data/spec/support/shared/unit/execute_resource.rb +8 -1
  163. data/spec/support/shared/unit/provider/file.rb +9 -1
  164. data/spec/unit/chef_fs/data_handler/data_bag_item_data_handler.rb +10 -7
  165. data/spec/unit/chef_fs/file_system/repository/directory_spec.rb +2 -2
  166. data/spec/unit/client_spec.rb +1 -1
  167. data/spec/unit/deprecated_spec.rb +4 -4
  168. data/spec/unit/http_spec.rb +9 -0
  169. data/spec/unit/knife/bootstrap_spec.rb +5 -0
  170. data/spec/unit/knife/configure_spec.rb +10 -60
  171. data/spec/unit/knife/data_bag_create_spec.rb +40 -2
  172. data/spec/unit/knife/data_bag_show_spec.rb +16 -2
  173. data/spec/unit/knife/ssh_spec.rb +85 -39
  174. data/spec/unit/knife_spec.rb +2 -0
  175. data/spec/unit/lwrp_spec.rb +5 -3
  176. data/spec/unit/mixin/powershell_type_coercions_spec.rb +7 -6
  177. data/spec/unit/node/attribute_spec.rb +55 -24
  178. data/spec/unit/node/immutable_collections_spec.rb +28 -14
  179. data/spec/unit/node/vivid_mash_spec.rb +27 -10
  180. data/spec/unit/node_map_spec.rb +34 -0
  181. data/spec/unit/property_spec.rb +13 -13
  182. data/spec/unit/provider/group/dscl_spec.rb +14 -5
  183. data/spec/unit/provider/ifconfig_spec.rb +10 -3
  184. data/spec/unit/provider/remote_file/http_spec.rb +23 -19
  185. data/spec/unit/provider/service/solaris_smf_service_spec.rb +6 -5
  186. data/spec/unit/provider/user/dscl_spec.rb +26 -0
  187. data/spec/unit/provider/windows_task_spec.rb +148 -4
  188. data/spec/unit/provider_spec.rb +1 -1
  189. data/spec/unit/resource/apt_package_spec.rb +1 -1
  190. data/spec/unit/resource/bash_spec.rb +8 -10
  191. data/spec/unit/resource/batch_spec.rb +1 -1
  192. data/spec/unit/resource/cab_package_spec.rb +19 -1
  193. data/spec/unit/resource/chef_gem_spec.rb +3 -3
  194. data/spec/unit/resource/chocolatey_package_spec.rb +10 -10
  195. data/spec/unit/resource/conditional_spec.rb +2 -2
  196. data/spec/unit/resource/cookbook_file_spec.rb +24 -30
  197. data/spec/unit/resource/cron_spec.rb +79 -82
  198. data/spec/unit/resource/csh_spec.rb +8 -10
  199. data/spec/unit/resource/deploy_spec.rb +1 -1
  200. data/spec/unit/resource/directory_spec.rb +28 -31
  201. data/spec/unit/resource/dnf_package_spec.rb +9 -9
  202. data/spec/unit/resource/env_spec.rb +7 -7
  203. data/spec/unit/resource/erl_call_spec.rb +9 -9
  204. data/spec/unit/resource/execute_spec.rb +6 -6
  205. data/spec/unit/resource/file/verification_spec.rb +18 -4
  206. data/spec/unit/resource/file_spec.rb +53 -56
  207. data/spec/unit/resource/freebsd_package_spec.rb +7 -7
  208. data/spec/unit/resource/gem_package_spec.rb +1 -1
  209. data/spec/unit/resource/git_spec.rb +7 -9
  210. data/spec/unit/resource/group_spec.rb +60 -70
  211. data/spec/unit/resource/http_request_spec.rb +16 -19
  212. data/spec/unit/resource/ifconfig_spec.rb +3 -3
  213. data/spec/unit/resource/ips_package_spec.rb +3 -5
  214. data/spec/unit/resource/ksh_spec.rb +8 -10
  215. data/spec/unit/resource/launchd_spec.rb +17 -10
  216. data/spec/unit/resource/link_spec.rb +53 -53
  217. data/spec/unit/resource/log_spec.rb +24 -28
  218. data/spec/unit/resource/mdadm_spec.rb +42 -44
  219. data/spec/unit/resource/mount_spec.rb +97 -99
  220. data/spec/unit/resource/msu_package_spec.rb +14 -8
  221. data/spec/unit/resource/ohai_spec.rb +15 -17
  222. data/spec/unit/resource/openbsd_package_spec.rb +3 -3
  223. data/spec/unit/resource/osx_profile_spec.rb +7 -7
  224. data/spec/unit/resource/package_spec.rb +36 -40
  225. data/spec/unit/resource/perl_spec.rb +8 -11
  226. data/spec/unit/resource/portage_package_spec.rb +8 -10
  227. data/spec/unit/resource/powershell_package_spec.rb +9 -9
  228. data/spec/unit/resource/python_spec.rb +8 -11
  229. data/spec/unit/resource/reboot_spec.rb +50 -0
  230. data/spec/unit/resource/registry_key_spec.rb +84 -98
  231. data/spec/unit/resource/remote_directory_spec.rb +40 -42
  232. data/spec/unit/resource/remote_file_spec.rb +78 -80
  233. data/spec/unit/resource/route_spec.rb +42 -44
  234. data/spec/unit/resource/rpm_package_spec.rb +5 -7
  235. data/spec/unit/resource/ruby_block_spec.rb +14 -16
  236. data/spec/unit/resource/ruby_spec.rb +8 -12
  237. data/spec/unit/resource/scm_spec.rb +66 -69
  238. data/spec/unit/resource/script_spec.rb +1 -1
  239. data/spec/unit/resource/service_spec.rb +80 -83
  240. data/spec/unit/resource/smartos_package_spec.rb +5 -0
  241. data/spec/unit/resource/solaris_package_spec.rb +3 -5
  242. data/spec/unit/resource/subversion_spec.rb +18 -16
  243. data/spec/unit/resource/systemd_unit_spec.rb +50 -54
  244. data/spec/unit/resource/template_spec.rb +56 -61
  245. data/spec/unit/resource/user_spec.rb +47 -53
  246. data/spec/unit/resource/windows_package_spec.rb +1 -1
  247. data/spec/unit/resource/windows_path_spec.rb +11 -8
  248. data/spec/unit/resource/windows_task_spec.rb +129 -33
  249. data/spec/unit/resource/yum_package_spec.rb +1 -1
  250. data/spec/unit/resource/yum_repository_spec.rb +61 -8
  251. data/spec/unit/resource/zypper_repository_spec.rb +17 -18
  252. data/spec/unit/util/selinux_spec.rb +3 -6
  253. data/tasks/dependencies.rb +0 -5
  254. data/tasks/rspec.rb +1 -1
  255. metadata +7 -19
  256. data/acceptance/.DS_Store +0 -0
  257. data/acceptance/.bundle/config +0 -2
  258. data/acceptance/top-cookbooks/.kitchen.docker.yml +0 -13
  259. data/acceptance/top-cookbooks/.kitchen.git.yml +0 -11
  260. data/distro/.DS_Store +0 -0
  261. data/lib/.DS_Store +0 -0
  262. data/lib/chef/.DS_Store +0 -0
  263. data/lib/chef/knife/.DS_Store +0 -0
  264. data/lib/chef/mixin/.DS_Store +0 -0
  265. data/spec/.DS_Store +0 -0
  266. data/spec/functional/.DS_Store +0 -0
  267. data/spec/support/.DS_Store +0 -0
  268. data/spec/unit/.DS_Store +0 -0
  269. data/tasks/.DS_Store +0 -0
@@ -19,76 +19,73 @@
19
19
  require "spec_helper"
20
20
 
21
21
  describe Chef::Resource::Template do
22
-
23
- before(:each) do
24
- @resource = Chef::Resource::Template.new("fakey_fakerton")
25
- end
22
+ let(:resource) { Chef::Resource::Template.new("fakey_fakerton") }
26
23
 
27
24
  describe "initialize" do
28
- it "should create a new Chef::Resource::Template" do
29
- expect(@resource).to be_a_kind_of(Chef::Resource)
30
- expect(@resource).to be_a_kind_of(Chef::Resource::File)
31
- expect(@resource).to be_a_kind_of(Chef::Resource::Template)
25
+ it "creates a new Chef::Resource::Template" do
26
+ expect(resource).to be_a_kind_of(Chef::Resource)
27
+ expect(resource).to be_a_kind_of(Chef::Resource::File)
28
+ expect(resource).to be_a_kind_of(Chef::Resource::Template)
32
29
  end
33
30
  end
34
31
 
35
32
  describe "source" do
36
- it "should accept a string for the template source" do
37
- @resource.source "something"
38
- expect(@resource.source).to eql("something")
33
+ it "accepts a string for the template source" do
34
+ resource.source "something"
35
+ expect(resource.source).to eql("something")
39
36
  end
40
37
 
41
- it "should have a default based on the param name with .erb appended" do
42
- expect(@resource.source).to eql("fakey_fakerton.erb")
38
+ it "has a default based on the param name with .erb appended" do
39
+ expect(resource.source).to eql("fakey_fakerton.erb")
43
40
  end
44
41
 
45
- it "should use only the basename of the file as the default" do
42
+ it "uses only the basename of the file as the default" do
46
43
  r = Chef::Resource::Template.new("/tmp/obit/fakey_fakerton")
47
44
  expect(r.source).to eql("fakey_fakerton.erb")
48
45
  end
49
46
  end
50
47
 
51
48
  describe "variables" do
52
- it "should accept a hash for the variable list" do
53
- @resource.variables({ :reluctance => :awkward })
54
- expect(@resource.variables).to eq({ :reluctance => :awkward })
49
+ it "accepts a hash for the variable list" do
50
+ resource.variables({ :reluctance => :awkward })
51
+ expect(resource.variables).to eq({ :reluctance => :awkward })
55
52
  end
56
53
  end
57
54
 
58
55
  describe "cookbook" do
59
- it "should accept a string for the cookbook name" do
60
- @resource.cookbook("foo")
61
- expect(@resource.cookbook).to eq("foo")
56
+ it "accepts a string for the cookbook name" do
57
+ resource.cookbook("foo")
58
+ expect(resource.cookbook).to eq("foo")
62
59
  end
63
60
 
64
- it "should default to nil" do
65
- expect(@resource.cookbook).to eq(nil)
61
+ it "defaults to nil" do
62
+ expect(resource.cookbook).to eq(nil)
66
63
  end
67
64
  end
68
65
 
69
66
  describe "local" do
70
- it "should accept a boolean for whether a template is local or remote" do
71
- @resource.local(true)
72
- expect(@resource.local).to eq(true)
67
+ it "accepts a boolean for whether a template is local or remote" do
68
+ resource.local(true)
69
+ expect(resource.local).to eq(true)
73
70
  end
74
71
 
75
- it "should default to false" do
76
- expect(@resource.local).to eq(false)
72
+ it "defaults to false" do
73
+ expect(resource.local).to eq(false)
77
74
  end
78
75
  end
79
76
 
80
77
  describe "when it has a path, owner, group, mode, and checksum" do
81
78
  before do
82
- @resource.path("/tmp/foo.txt")
83
- @resource.owner("root")
84
- @resource.group("wheel")
85
- @resource.mode("0644")
86
- @resource.checksum("1" * 64)
79
+ resource.path("/tmp/foo.txt")
80
+ resource.owner("root")
81
+ resource.group("wheel")
82
+ resource.mode("0644")
83
+ resource.checksum("1" * 64)
87
84
  end
88
85
 
89
86
  context "on unix", :unix_only do
90
87
  it "describes its state" do
91
- state = @resource.state_for_resource_reporter
88
+ state = resource.state_for_resource_reporter
92
89
  expect(state[:owner]).to eq("root")
93
90
  expect(state[:group]).to eq("wheel")
94
91
  expect(state[:mode]).to eq("0644")
@@ -102,7 +99,7 @@ describe Chef::Resource::Template do
102
99
  end
103
100
 
104
101
  it "returns the file path as its identity" do
105
- expect(@resource.identity).to eq("/tmp/foo.txt")
102
+ expect(resource.identity).to eq("/tmp/foo.txt")
106
103
  end
107
104
  end
108
105
 
@@ -115,16 +112,16 @@ describe Chef::Resource::Template do
115
112
  end
116
113
 
117
114
  it "collects helper method bodies as blocks" do
118
- @resource.helper(:example_1) { "example_1" }
119
- @resource.helper(:example_2) { "example_2" }
120
- expect(@resource.inline_helper_blocks[:example_1].call).to eq("example_1")
121
- expect(@resource.inline_helper_blocks[:example_2].call).to eq("example_2")
115
+ resource.helper(:example_1) { "example_1" }
116
+ resource.helper(:example_2) { "example_2" }
117
+ expect(resource.inline_helper_blocks[:example_1].call).to eq("example_1")
118
+ expect(resource.inline_helper_blocks[:example_2].call).to eq("example_2")
122
119
  end
123
120
 
124
121
  it "compiles helper methods into a module" do
125
- @resource.helper(:example_1) { "example_1" }
126
- @resource.helper(:example_2) { "example_2" }
127
- modules = @resource.helper_modules
122
+ resource.helper(:example_1) { "example_1" }
123
+ resource.helper(:example_2) { "example_2" }
124
+ modules = resource.helper_modules
128
125
  expect(modules.size).to eq(1)
129
126
  o = Object.new
130
127
  modules.each { |m| o.extend(m) }
@@ -133,38 +130,38 @@ describe Chef::Resource::Template do
133
130
  end
134
131
 
135
132
  it "compiles helper methods with arguments into a module" do
136
- @resource.helper(:shout) { |quiet| quiet.upcase }
137
- modules = @resource.helper_modules
133
+ resource.helper(:shout) { |quiet| quiet.upcase }
134
+ modules = resource.helper_modules
138
135
  o = Object.new
139
136
  modules.each { |m| o.extend(m) }
140
137
  expect(o.shout("shout")).to eq("SHOUT")
141
138
  end
142
139
 
143
140
  it "raises an error when attempting to define a helper method without a method body" do
144
- expect { @resource.helper(:example) }.to raise_error(Chef::Exceptions::ValidationFailed)
141
+ expect { resource.helper(:example) }.to raise_error(Chef::Exceptions::ValidationFailed)
145
142
  end
146
143
 
147
144
  it "raises an error when attempting to define a helper method with a non-Symbod method name" do
148
- expect { @resource.helper("example") { "fail" } }.to raise_error(Chef::Exceptions::ValidationFailed)
145
+ expect { resource.helper("example") { "fail" } }.to raise_error(Chef::Exceptions::ValidationFailed)
149
146
  end
150
147
 
151
148
  it "collects helper module bodies as blocks" do
152
- @resource.helpers do
149
+ resource.helpers do
153
150
  def example_1
154
151
  "example_1"
155
152
  end
156
153
  end
157
- module_body = @resource.inline_helper_modules.first
154
+ module_body = resource.inline_helper_modules.first
158
155
  expect(module_body).to be_a(Proc)
159
156
  end
160
157
 
161
158
  it "compiles helper module bodies into modules" do
162
- @resource.helpers do
159
+ resource.helpers do
163
160
  def example_1
164
161
  "example_1"
165
162
  end
166
163
  end
167
- modules = @resource.helper_modules
164
+ modules = resource.helper_modules
168
165
  expect(modules.size).to eq(1)
169
166
  o = Object.new
170
167
  modules.each { |m| o.extend(m) }
@@ -172,39 +169,37 @@ describe Chef::Resource::Template do
172
169
  end
173
170
 
174
171
  it "raises an error when no block or module name is given for helpers definition" do
175
- expect { @resource.helpers() }.to raise_error(Chef::Exceptions::ValidationFailed)
172
+ expect { resource.helpers() }.to raise_error(Chef::Exceptions::ValidationFailed)
176
173
  end
177
174
 
178
175
  it "raises an error when a non-module is given for helpers definition" do
179
- expect { @resource.helpers("NotAModule") }.to raise_error(Chef::Exceptions::ValidationFailed)
176
+ expect { resource.helpers("NotAModule") }.to raise_error(Chef::Exceptions::ValidationFailed)
180
177
  end
181
178
 
182
179
  it "raises an error when a module name and block are both given for helpers definition" do
183
- expect { @resource.helpers(ExampleHelpers) { module_code } }.to raise_error(Chef::Exceptions::ValidationFailed)
180
+ expect { resource.helpers(ExampleHelpers) { module_code } }.to raise_error(Chef::Exceptions::ValidationFailed)
184
181
  end
185
182
 
186
183
  it "collects helper modules" do
187
- @resource.helpers(ExampleHelpers)
188
- expect(@resource.helper_modules).to include(ExampleHelpers)
184
+ resource.helpers(ExampleHelpers)
185
+ expect(resource.helper_modules).to include(ExampleHelpers)
189
186
  end
190
187
 
191
188
  it "combines all helpers into a set of compiled modules" do
192
- @resource.helpers(ExampleHelpers)
193
- @resource.helpers do
189
+ resource.helpers(ExampleHelpers)
190
+ resource.helpers do
194
191
  def inline_module
195
192
  "inline_module"
196
193
  end
197
194
  end
198
- @resource.helper(:inline_method) { "inline_method" }
199
- expect(@resource.helper_modules.size).to eq(3)
195
+ resource.helper(:inline_method) { "inline_method" }
196
+ expect(resource.helper_modules.size).to eq(3)
200
197
 
201
198
  o = Object.new
202
- @resource.helper_modules.each { |m| o.extend(m) }
199
+ resource.helper_modules.each { |m| o.extend(m) }
203
200
  expect(o.static_example).to eq("static_example")
204
201
  expect(o.inline_module).to eq("inline_module")
205
202
  expect(o.inline_method).to eq("inline_method")
206
203
  end
207
-
208
204
  end
209
-
210
205
  end
@@ -19,115 +19,109 @@
19
19
  require "spec_helper"
20
20
 
21
21
  describe Chef::Resource::User, "initialize" do
22
- before(:each) do
23
- @resource = Chef::Resource::User.new("adam")
24
- end
22
+ let(:resource) { Chef::Resource::User.new("adam") }
25
23
 
26
- it "should create a new Chef::Resource::User" do
27
- expect(@resource).to be_a_kind_of(Chef::Resource)
28
- expect(@resource).to be_a_kind_of(Chef::Resource::User)
24
+ it "creates a new Chef::Resource::User" do
25
+ expect(resource).to be_a_kind_of(Chef::Resource)
26
+ expect(resource).to be_a_kind_of(Chef::Resource::User)
29
27
  end
30
28
 
31
- it "should set the resource_name to :user" do
32
- expect(@resource.resource_name).to eql(:user_resource_abstract_base_class)
29
+ it "sets the resource_name to :user" do
30
+ expect(resource.resource_name).to eql(:user_resource_abstract_base_class)
33
31
  end
34
32
 
35
- it "should set the username equal to the argument to initialize" do
36
- expect(@resource.username).to eql("adam")
33
+ it "sets the username equal to the argument to initialize" do
34
+ expect(resource.username).to eql("adam")
37
35
  end
38
36
 
39
37
  %w{comment uid gid home shell password}.each do |attrib|
40
- it "should set #{attrib} to nil" do
41
- expect(@resource.send(attrib)).to eql(nil)
38
+ it "sets #{attrib} to nil" do
39
+ expect(resource.send(attrib)).to eql(nil)
42
40
  end
43
41
  end
44
42
 
45
- it "should set action to :create" do
46
- expect(@resource.action).to eql([:create])
43
+ it "sets action to :create" do
44
+ expect(resource.action).to eql([:create])
47
45
  end
48
46
 
49
- it "should set manage_home to false" do
50
- expect(@resource.manage_home).to eql(false)
47
+ it "sets manage_home to false" do
48
+ expect(resource.manage_home).to eql(false)
51
49
  end
52
50
 
53
- it "should set non_unique to false" do
54
- expect(@resource.non_unique).to eql(false)
51
+ it "sets non_unique to false" do
52
+ expect(resource.non_unique).to eql(false)
55
53
  end
56
54
 
57
- it "should set force to false" do
58
- expect(@resource.force).to eql(false)
55
+ it "sets force to false" do
56
+ expect(resource.force).to eql(false)
59
57
  end
60
58
 
61
59
  %w{create remove modify manage lock unlock}.each do |action|
62
- it "should allow action #{action}" do
63
- expect(@resource.allowed_actions.detect { |a| a == action.to_sym }).to eql(action.to_sym)
60
+ it "allows action #{action}" do
61
+ expect(resource.allowed_actions.detect { |a| a == action.to_sym }).to eql(action.to_sym)
64
62
  end
65
63
  end
66
64
 
67
- it "should accept domain users (@ or \ separator) on non-windows" do
68
- expect { @resource.username "domain\@user" }.not_to raise_error
69
- expect(@resource.username).to eq("domain\@user")
70
- expect { @resource.username "domain\\user" }.not_to raise_error
71
- expect(@resource.username).to eq("domain\\user")
65
+ it "accepts domain users (@ or \ separator) on non-windows" do
66
+ expect { resource.username "domain\@user" }.not_to raise_error
67
+ expect(resource.username).to eq("domain\@user")
68
+ expect { resource.username "domain\\user" }.not_to raise_error
69
+ expect(resource.username).to eq("domain\\user")
72
70
  end
73
71
  end
74
72
 
75
73
  %w{username comment home shell password}.each do |attrib|
76
74
  describe Chef::Resource::User, attrib do
77
- before(:each) do
78
- @resource = Chef::Resource::User.new("adam")
79
- end
75
+ let(:resource) { Chef::Resource::User.new("adam") }
80
76
 
81
- it "should allow a string" do
82
- @resource.send(attrib, "adam")
83
- expect(@resource.send(attrib)).to eql("adam")
77
+ it "allows a string" do
78
+ resource.send(attrib, "adam")
79
+ expect(resource.send(attrib)).to eql("adam")
84
80
  end
85
81
 
86
- it "should not allow a hash" do
87
- expect { @resource.send(attrib, { :woot => "i found it" }) }.to raise_error(ArgumentError)
82
+ it "does not allow a hash" do
83
+ expect { resource.send(attrib, { :woot => "i found it" }) }.to raise_error(ArgumentError)
88
84
  end
89
85
  end
90
86
  end
91
87
 
92
88
  %w{uid gid}.each do |attrib|
93
89
  describe Chef::Resource::User, attrib do
94
- before(:each) do
95
- @resource = Chef::Resource::User.new("adam")
96
- end
90
+ let(:resource) { Chef::Resource::User.new("adam") }
97
91
 
98
- it "should allow a string" do
99
- @resource.send(attrib, "100")
100
- expect(@resource.send(attrib)).to eql("100")
92
+ it "allows a string" do
93
+ resource.send(attrib, "100")
94
+ expect(resource.send(attrib)).to eql("100")
101
95
  end
102
96
 
103
- it "should allow an integer" do
104
- @resource.send(attrib, 100)
105
- expect(@resource.send(attrib)).to eql(100)
97
+ it "allows an integer" do
98
+ resource.send(attrib, 100)
99
+ expect(resource.send(attrib)).to eql(100)
106
100
  end
107
101
 
108
- it "should not allow a hash" do
109
- expect { @resource.send(attrib, { :woot => "i found it" }) }.to raise_error(ArgumentError)
102
+ it "does not allow a hash" do
103
+ expect { resource.send(attrib, { :woot => "i found it" }) }.to raise_error(ArgumentError)
110
104
  end
111
105
  end
112
106
 
113
107
  describe "when it has uid, gid, and home" do
108
+ let(:resource) { Chef::Resource::User.new("root") }
109
+
114
110
  before do
115
- @resource = Chef::Resource::User.new("root")
116
- @resource.uid(123)
117
- @resource.gid(456)
118
- @resource.home("/usr/local/root/")
111
+ resource.uid(123)
112
+ resource.gid(456)
113
+ resource.home("/usr/local/root/")
119
114
  end
120
115
 
121
116
  it "describes its state" do
122
- state = @resource.state_for_resource_reporter
117
+ state = resource.state_for_resource_reporter
123
118
  expect(state[:uid]).to eq(123)
124
119
  expect(state[:gid]).to eq(456)
125
120
  expect(state[:home]).to eq("/usr/local/root/")
126
121
  end
127
122
 
128
123
  it "returns the username as its identity" do
129
- expect(@resource.identity).to eq("root")
124
+ expect(resource.identity).to eq("root")
130
125
  end
131
126
  end
132
-
133
127
  end
@@ -88,7 +88,7 @@ describe Chef::Resource::WindowsPackage, "initialize" do
88
88
  let(:resource_source) { "https://foo.bar/solitare.msi" }
89
89
  let(:resource) { Chef::Resource::WindowsPackage.new(resource_source) }
90
90
 
91
- it "should return the source unmodified" do
91
+ it "returns the source unmodified" do
92
92
  expect(resource.source).to eq(resource_source)
93
93
  end
94
94
  end
@@ -19,20 +19,23 @@
19
19
  require "spec_helper"
20
20
 
21
21
  describe Chef::Resource::WindowsPath do
22
- subject { Chef::Resource::WindowsPath.new("some_path") }
23
-
24
- it { is_expected.to be_a_kind_of(Chef::Resource) }
25
- it { is_expected.to be_a_instance_of(Chef::Resource::WindowsPath) }
22
+ let(:resource) { Chef::Resource::WindowsPath.new("some_path") }
26
23
 
27
24
  it "sets resource name as :windows_path" do
28
- expect(subject.resource_name).to eql(:windows_path)
25
+ expect(resource.resource_name).to eql(:windows_path)
29
26
  end
30
27
 
31
- it "sets the path as it's name" do
32
- expect(subject.path).to eql("some_path")
28
+ it "sets the path as its name" do
29
+ expect(resource.path).to eql("some_path")
33
30
  end
34
31
 
35
32
  it "sets the default action as :add" do
36
- expect(subject.action).to eql(:add)
33
+ expect(resource.action).to eql([:add])
34
+ end
35
+
36
+ it "supports :add and :remove actions" do
37
+ expect { resource.action :add }.not_to raise_error
38
+ expect { resource.action :remove }.not_to raise_error
39
+ expect { resource.action :delete }.to raise_error(ArgumentError)
37
40
  end
38
41
  end
@@ -30,12 +30,12 @@ describe Chef::Resource::WindowsTask do
30
30
  expect(resource.resource_name).to eql(:windows_task)
31
31
  end
32
32
 
33
- it "sets the task_name as it's name" do
33
+ it "sets the task_name as its name" do
34
34
  expect(resource.task_name).to eql("sample_task")
35
35
  end
36
36
 
37
37
  it "sets the default action as :create" do
38
- expect(resource.action).to eql(:create)
38
+ expect(resource.action).to eql([:create])
39
39
  end
40
40
 
41
41
  it "sets the default user as System" do
@@ -62,39 +62,86 @@ describe Chef::Resource::WindowsTask do
62
62
  expect(resource.frequency).to eql(:hourly)
63
63
  end
64
64
 
65
+ context "when user is set but password is not" do
66
+ it "raises an error if the user is a non-system user" do
67
+ resource.user "bob"
68
+ expect { resource.after_created }.to raise_error(ArgumentError, %q{Cannot specify a user other than the system users without specifying a password!. Valid passwordless users: 'NT AUTHORITY\SYSTEM', 'SYSTEM', 'NT AUTHORITY\LOCALSERVICE', 'NT AUTHORITY\NETWORKSERVICE', 'BUILTIN\USERS', 'USERS'})
69
+ end
70
+
71
+ it "does not raise an error if the user is a system user" do
72
+ resource.user 'NT AUTHORITY\SYSTEM'
73
+ expect { resource.after_created }.to_not raise_error
74
+ end
75
+
76
+ it "does not raise an error if the user is a system user even if lowercase" do
77
+ resource.user 'nt authority\system'
78
+ expect { resource.after_created }.to_not raise_error
79
+ end
80
+ end
81
+
65
82
  context "when random_delay is passed" do
66
83
  it "raises error if frequency is `:once`" do
67
84
  resource.frequency :once
68
85
  resource.random_delay "20"
69
- expect { resource.after_created }.to raise_error(Chef::Exceptions::ArgumentError, "`random_delay` property is supported only for frequency :minute, :hourly, :daily, :weekly and :monthly")
86
+ expect { resource.after_created }.to raise_error(ArgumentError, "`random_delay` property is supported only for frequency :minute, :hourly, :daily, :weekly and :monthly")
70
87
  end
71
88
 
72
89
  it "raises error for invalid random_delay" do
73
90
  resource.frequency :monthly
74
91
  resource.random_delay "xyz"
75
- expect { resource.after_created }.to raise_error(Chef::Exceptions::ArgumentError, "Invalid value passed for `random_delay`. Please pass seconds as a String e.g. '60'.")
92
+ expect { resource.after_created }.to raise_error(ArgumentError, "Invalid value passed for `random_delay`. Please pass seconds as an Integer (e.g. 60) or a String with numeric values only (e.g. '60').")
76
93
  end
77
94
 
78
- it "converts seconds into iso8601 format" do
95
+ it "raises error for invalid random_delay which looks like an Integer" do
96
+ resource.frequency :monthly
97
+ resource.random_delay "5,000"
98
+ expect { resource.after_created }.to raise_error(ArgumentError, "Invalid value passed for `random_delay`. Please pass seconds as an Integer (e.g. 60) or a String with numeric values only (e.g. '60').")
99
+ end
100
+
101
+ it "converts seconds String into iso8601 duration format" do
79
102
  resource.frequency :monthly
80
103
  resource.random_delay "60"
81
104
  resource.after_created
82
105
  expect(resource.random_delay).to eq("PT60S")
83
106
  end
107
+
108
+ it "converts seconds Integer into iso8601 duration format" do
109
+ resource.frequency :monthly
110
+ resource.random_delay 60
111
+ resource.after_created
112
+ expect(resource.random_delay).to eq("PT60S")
113
+ end
114
+
115
+ it "raises error that random_delay is not supported" do
116
+ expect { resource.send(:validate_random_delay, 60, :on_idle) }.to raise_error(ArgumentError, "`random_delay` property is supported only for frequency :minute, :hourly, :daily, :weekly and :monthly")
117
+ end
84
118
  end
85
119
 
86
- context "when execution_time_limit is passed" do
87
- it "sets the deafult value as PT72H" do
120
+ context "when execution_time_limit isn't specified" do
121
+ it "sets the default value to PT72H" do
88
122
  resource.after_created
89
123
  expect(resource.execution_time_limit).to eq("PT72H")
90
124
  end
125
+ end
91
126
 
127
+ context "when execution_time_limit is passed" do
92
128
  it "raises error for invalid execution_time_limit" do
93
129
  resource.execution_time_limit "abc"
94
- expect { resource.after_created }.to raise_error(Chef::Exceptions::ArgumentError, "Invalid value passed for `execution_time_limit`. Please pass seconds as a String e.g. '60'.")
130
+ expect { resource.after_created }.to raise_error(ArgumentError, "Invalid value passed for `execution_time_limit`. Please pass seconds as an Integer (e.g. 60) or a String with numeric values only (e.g. '60').")
95
131
  end
96
132
 
97
- it "converts seconds into iso8601 format" do
133
+ it "raises error for invalid execution_time_limit that looks like an Integer" do
134
+ resource.execution_time_limit "5,000"
135
+ expect { resource.after_created }.to raise_error(ArgumentError, "Invalid value passed for `execution_time_limit`. Please pass seconds as an Integer (e.g. 60) or a String with numeric values only (e.g. '60').")
136
+ end
137
+
138
+ it "converts seconds Integer into iso8601 format" do
139
+ resource.execution_time_limit 60
140
+ resource.after_created
141
+ expect(resource.execution_time_limit).to eq("PT60S")
142
+ end
143
+
144
+ it "converts seconds String into iso8601 format" do
98
145
  resource.execution_time_limit "60"
99
146
  resource.after_created
100
147
  expect(resource.execution_time_limit).to eq("PT60S")
@@ -104,28 +151,48 @@ describe Chef::Resource::WindowsTask do
104
151
  context "#validate_start_time" do
105
152
  it "raises error if start_time is nil when frequency `:once`" do
106
153
  resource.frequency :once
107
- expect { resource.send(:validate_start_time, nil, :once) }.to raise_error(Chef::Exceptions::ArgumentError, "`start_time` needs to be provided with `frequency :once`")
154
+ expect { resource.send(:validate_start_time, nil, :once) }.to raise_error(ArgumentError, "`start_time` needs to be provided with `frequency :once`")
108
155
  end
109
156
 
110
157
  it "raises error if start_time is given when frequency `:none`" do
111
158
  resource.frequency :none
112
- expect { resource.send(:validate_start_time, "12.00", :none) }.to raise_error(Chef::Exceptions::ArgumentError, "`start_time` property is not supported with `frequency :none`")
159
+ expect { resource.send(:validate_start_time, "12.00", :none) }.to raise_error(ArgumentError, "`start_time` property is not supported with `frequency :none`")
160
+ end
161
+
162
+ it "raises error if start_time is not HH:mm format" do
163
+ resource.frequency :once
164
+ expect { resource.send(:validate_start_time, "2:30", :once) }.to raise_error(ArgumentError, "`start_time` property must be in the HH:mm format (e.g. 6:20pm -> 18:20).")
165
+ end
166
+
167
+ it "does not raise error if start_time is in HH:mm format" do
168
+ resource.frequency :once
169
+ expect { resource.send(:validate_start_time, "12:30", :once) }.not_to raise_error
113
170
  end
114
171
  end
115
172
 
116
173
  context "#validate_start_day" do
117
- it "raise error if start_day is passed with frequency :on_logon" do
118
- resource.frequency :on_logon
119
- expect { resource.send(:validate_start_day, "Wed", :on_logon) }.to raise_error(Chef::Exceptions::ArgumentError, "`start_day` property is not supported with frequency: on_logon")
174
+ it "raise error if start_day is passed with invalid frequency (:on_logon)" do
175
+ expect { resource.send(:validate_start_day, "02/07/1984", :on_logon) }.to raise_error(ArgumentError, "`start_day` property is not supported with frequency: on_logon")
120
176
  end
121
- end
122
177
 
123
- context "#validate_user_and_password" do
124
- context "when password is not passed" do
125
- it "raises error with non-system users" do
126
- allow(resource).to receive(:use_password?).and_return(true)
127
- expect { resource.send(:validate_user_and_password, "Testuser", nil) }.to raise_error("Can't specify a non-system user without a password!")
128
- end
178
+ it "does not raise error if start_day is passed with valid frequency (:weekly)" do
179
+ expect { resource.send(:validate_start_day, "02/07/1984", :weekly) }.not_to raise_error
180
+ end
181
+
182
+ it "raise error if start_day is passed with invalid date format (DD/MM/YYYY)" do
183
+ expect { resource.send(:validate_start_day, "28/12/2009", :weekly) }.to raise_error(ArgumentError, "`start_day` property must be in the MM/DD/YYYY format.")
184
+ end
185
+
186
+ it "raise error if start_day is passed with invalid date format (M/DD/YYYY)" do
187
+ expect { resource.send(:validate_start_day, "2/07/1984", :weekly) }.to raise_error(ArgumentError, "`start_day` property must be in the MM/DD/YYYY format.")
188
+ end
189
+
190
+ it "raise error if start_day is passed with invalid date format (MM/D/YYYY)" do
191
+ expect { resource.send(:validate_start_day, "02/7/1984", :weekly) }.to raise_error(ArgumentError, "`start_day` property must be in the MM/DD/YYYY format.")
192
+ end
193
+
194
+ it "raise error if start_day is passed with invalid date format (MM/DD/YY)" do
195
+ expect { resource.send(:validate_start_day, "02/07/84", :weekly) }.to raise_error(ArgumentError, "`start_day` property must be in the MM/DD/YYYY format.")
129
196
  end
130
197
  end
131
198
 
@@ -138,42 +205,42 @@ describe Chef::Resource::WindowsTask do
138
205
  context "#validate_create_frequency_modifier" do
139
206
  context "when frequency is :minute" do
140
207
  it "raises error if frequency_modifier > 1439" do
141
- expect { resource.send(:validate_create_frequency_modifier, :minute, 1500) }.to raise_error("frequency_modifier value 1500 is invalid. Valid values for :minute frequency are 1 - 1439.")
208
+ expect { resource.send(:validate_create_frequency_modifier, :minute, 1500) }.to raise_error("frequency_modifier value 1500 is invalid. Valid values for :minute frequency are 1 - 1439.")
142
209
  end
143
210
  end
144
211
 
145
212
  context "when frequency is :hourly" do
146
213
  it "raises error if frequency_modifier > 23" do
147
- expect { resource.send(:validate_create_frequency_modifier, :hourly, 24) }.to raise_error("frequency_modifier value 24 is invalid. Valid values for :hourly frequency are 1 - 23.")
214
+ expect { resource.send(:validate_create_frequency_modifier, :hourly, 24) }.to raise_error("frequency_modifier value 24 is invalid. Valid values for :hourly frequency are 1 - 23.")
148
215
  end
149
216
  end
150
217
 
151
218
  context "when frequency is :daily" do
152
219
  it "raises error if frequency_modifier > 365" do
153
- expect { resource.send(:validate_create_frequency_modifier, :daily, 366) }.to raise_error("frequency_modifier value 366 is invalid. Valid values for :daily frequency are 1 - 365.")
220
+ expect { resource.send(:validate_create_frequency_modifier, :daily, 366) }.to raise_error("frequency_modifier value 366 is invalid. Valid values for :daily frequency are 1 - 365.")
154
221
  end
155
222
  end
156
223
 
157
224
  context "when frequency is :weekly" do
158
225
  it "raises error if frequency_modifier > 52" do
159
- expect { resource.send(:validate_create_frequency_modifier, :weekly, 53) }.to raise_error("frequency_modifier value 53 is invalid. Valid values for :weekly frequency are 1 - 52.")
226
+ expect { resource.send(:validate_create_frequency_modifier, :weekly, 53) }.to raise_error("frequency_modifier value 53 is invalid. Valid values for :weekly frequency are 1 - 52.")
160
227
  end
161
228
  end
162
229
 
163
230
  context "when frequency is :monthly" do
164
231
  it "raises error if frequency_modifier > 12" do
165
- expect { resource.send(:validate_create_frequency_modifier, :monthly, 14) }.to raise_error("frequency_modifier value 14 is invalid. Valid values for :monthly frequency are 1 - 12, 'FIRST', 'SECOND', 'THIRD', 'FOURTH', 'LAST', 'LASTDAY'.")
232
+ expect { resource.send(:validate_create_frequency_modifier, :monthly, 14) }.to raise_error("frequency_modifier value 14 is invalid. Valid values for :monthly frequency are 1 - 12, 'FIRST', 'SECOND', 'THIRD', 'FOURTH', 'LAST', 'LASTDAY'.")
166
233
  end
167
234
 
168
235
  it "raises error if frequency_modifier is invalid" do
169
- expect { resource.send(:validate_create_frequency_modifier, :monthly, "abc") }.to raise_error("frequency_modifier value abc is invalid. Valid values for :monthly frequency are 1 - 12, 'FIRST', 'SECOND', 'THIRD', 'FOURTH', 'LAST', 'LASTDAY'.")
236
+ expect { resource.send(:validate_create_frequency_modifier, :monthly, "abc") }.to raise_error("frequency_modifier value abc is invalid. Valid values for :monthly frequency are 1 - 12, 'FIRST', 'SECOND', 'THIRD', 'FOURTH', 'LAST', 'LASTDAY'.")
170
237
  end
171
238
  end
172
239
  end
173
240
 
174
241
  context "#validate_create_day" do
175
242
  it "raises error if frequency is not :weekly or :monthly" do
176
- expect { resource.send(:validate_create_day, "Mon", :once) }.to raise_error("day attribute is only valid for tasks that run monthly or weekly")
243
+ expect { resource.send(:validate_create_day, "Mon", :once) }.to raise_error("day property is only valid for tasks that run monthly or weekly")
177
244
  end
178
245
 
179
246
  it "accepts a valid single day" do
@@ -185,13 +252,13 @@ describe Chef::Resource::WindowsTask do
185
252
  end
186
253
 
187
254
  it "raises error for invalid day value" do
188
- expect { resource.send(:validate_create_day, "xyz", :weekly) }.to raise_error("day attribute invalid. Only valid values are: MON, TUE, WED, THU, FRI, SAT, SUN and *. Multiple values must be separated by a comma.")
255
+ expect { resource.send(:validate_create_day, "xyz", :weekly) }.to raise_error(ArgumentError, "day property invalid. Only valid values are: MON, TUE, WED, THU, FRI, SAT, SUN and *. Multiple values must be separated by a comma.")
189
256
  end
190
257
  end
191
258
 
192
259
  context "#validate_create_months" do
193
260
  it "raises error if frequency is not :monthly" do
194
- expect { resource.send(:validate_create_months, "Jan", :once) }.to raise_error("months attribute is only valid for tasks that run monthly")
261
+ expect { resource.send(:validate_create_months, "Jan", :once) }.to raise_error(ArgumentError, "months property is only valid for tasks that run monthly")
195
262
  end
196
263
 
197
264
  it "accepts a valid single month" do
@@ -203,17 +270,46 @@ describe Chef::Resource::WindowsTask do
203
270
  end
204
271
 
205
272
  it "raises error for invalid month value" do
206
- expect { resource.send(:validate_create_months, "xyz", :monthly) }.to raise_error("months attribute invalid. Only valid values are: JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC and *. Multiple values must be separated by a comma.")
273
+ expect { resource.send(:validate_create_months, "xyz", :monthly) }.to raise_error(ArgumentError, "months property invalid. Only valid values are: JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC and *. Multiple values must be separated by a comma.")
207
274
  end
208
275
  end
209
276
 
210
277
  context "#validate_idle_time" do
211
278
  it "raises error if frequency is not :on_idle" do
212
- expect { resource.send(:validate_idle_time, 5, :hourly) }.to raise_error("idle_time attribute is only valid for tasks that run on_idle")
279
+ expect { resource.send(:validate_idle_time, 5, :hourly) }.to raise_error(ArgumentError, "idle_time property is only valid for tasks that run on_idle")
213
280
  end
214
281
 
215
282
  it "raises error if idle_time > 999" do
216
- expect { resource.send(:validate_idle_time, 1000, :on_idle) }.to raise_error("idle_time value 1000 is invalid. Valid values for :on_idle frequency are 1 - 999.")
283
+ expect { resource.send(:validate_idle_time, 1000, :on_idle) }.to raise_error(ArgumentError, "idle_time value 1000 is invalid. Valid values for :on_idle frequency are 1 - 999.")
284
+ end
285
+
286
+ it "raises error if idle_time < 0" do
287
+ expect { resource.send(:validate_idle_time, -5, :on_idle) }.to raise_error(ArgumentError, "idle_time value -5 is invalid. Valid values for :on_idle frequency are 1 - 999.")
288
+ end
289
+
290
+ it "raises error if idle_time is not set" do
291
+ expect { resource.send(:validate_idle_time, nil, :on_idle) }.to raise_error(ArgumentError, "idle_time value should be set for :on_idle frequency.")
292
+ end
293
+ end
294
+
295
+ context "#sec_to_dur" do
296
+ it "return nil when passed 0" do
297
+ expect(resource.send(:sec_to_dur, 0)).to eql("PT0S")
298
+ end
299
+ it "return PT1S when passed 1" do
300
+ expect(resource.send(:sec_to_dur, 1)).to eql("PT1S")
301
+ end
302
+ it "return PT86400S when passed 86400" do
303
+ expect(resource.send(:sec_to_dur, 86400)).to eql("PT86400S")
304
+ end
305
+ it "return PT86401S when passed 86401" do
306
+ expect(resource.send(:sec_to_dur, 86401)).to eql("PT86401S")
307
+ end
308
+ it "return PT86500S when passed 86500" do
309
+ expect(resource.send(:sec_to_dur, 86500)).to eql("PT86500S")
310
+ end
311
+ it "return PT604801S when passed 604801" do
312
+ expect(resource.send(:sec_to_dur, 604801)).to eql("PT604801S")
217
313
  end
218
314
  end
219
315
  end