chefspec 7.2.1 → 7.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (342) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +21 -13
  3. data/CHANGELOG.md +4 -0
  4. data/Gemfile +14 -10
  5. data/README.md +322 -1025
  6. data/README_old.md +1291 -0
  7. data/Rakefile +8 -3
  8. data/examples/apt_package/spec/install_spec.rb +1 -1
  9. data/examples/apt_package/spec/lock_spec.rb +1 -1
  10. data/examples/apt_package/spec/purge_spec.rb +1 -1
  11. data/examples/apt_package/spec/reconfig_spec.rb +1 -1
  12. data/examples/apt_package/spec/remove_spec.rb +1 -1
  13. data/examples/apt_package/spec/unlock_spec.rb +1 -1
  14. data/examples/apt_package/spec/upgrade_spec.rb +1 -1
  15. data/examples/apt_repository/spec/add_spec.rb +1 -1
  16. data/examples/apt_repository/spec/remove_spec.rb +1 -1
  17. data/examples/apt_update/spec/periodic_spec.rb +1 -1
  18. data/examples/apt_update/spec/update_spec.rb +1 -1
  19. data/examples/attributes/spec/default_spec.rb +1 -1
  20. data/examples/batch/spec/run_spec.rb +1 -1
  21. data/examples/cab_package/spec/install_spec.rb +1 -1
  22. data/examples/cab_package/spec/remove_spec.rb +1 -1
  23. data/examples/cached/spec/default_spec.rb +1 -1
  24. data/examples/chef_gem/spec/install_spec.rb +1 -1
  25. data/examples/chef_gem/spec/purge_spec.rb +1 -1
  26. data/examples/chef_gem/spec/reconfig_spec.rb +1 -1
  27. data/examples/chef_gem/spec/remove_spec.rb +1 -1
  28. data/examples/chef_gem/spec/upgrade_spec.rb +1 -1
  29. data/examples/chocolatey_package/spec/install_spec.rb +1 -1
  30. data/examples/chocolatey_package/spec/remove_spec.rb +1 -1
  31. data/examples/chocolatey_package/spec/upgrade_spec.rb +1 -1
  32. data/examples/compile_time/spec/default_spec.rb +1 -1
  33. data/examples/cookbook_file/spec/create_if_missing_spec.rb +1 -1
  34. data/examples/cookbook_file/spec/create_spec.rb +1 -1
  35. data/examples/cookbook_file/spec/delete_spec.rb +1 -1
  36. data/examples/cookbook_file/spec/touch_spec.rb +1 -1
  37. data/examples/core/recipes/default.rb +1 -0
  38. data/examples/core/spec/default_spec.rb +7 -0
  39. data/examples/core/spec/non_recipe_spec.rb +5 -0
  40. data/examples/cron/spec/create_spec.rb +1 -1
  41. data/examples/cron/spec/delete_spec.rb +1 -1
  42. data/examples/custom_matcher/spec/install_spec.rb +1 -1
  43. data/examples/custom_matcher/spec/remove_spec.rb +1 -1
  44. data/examples/custom_resource/spec/default_spec.rb +1 -1
  45. data/examples/custom_resource_block/resources/default.rb +3 -0
  46. data/examples/custom_resource_block/spec/default_spec.rb +10 -0
  47. data/examples/directory/spec/create_spec.rb +1 -1
  48. data/examples/directory/spec/delete_spec.rb +1 -1
  49. data/examples/dnf_package/spec/install_spec.rb +1 -1
  50. data/examples/dnf_package/spec/purge_spec.rb +1 -1
  51. data/examples/dnf_package/spec/remove_spec.rb +1 -1
  52. data/examples/dnf_package/spec/upgrade_spec.rb +1 -1
  53. data/examples/do_nothing/spec/default_spec.rb +1 -1
  54. data/examples/dpkg_package/spec/install_spec.rb +1 -1
  55. data/examples/dpkg_package/spec/purge_spec.rb +1 -1
  56. data/examples/dpkg_package/spec/remove_spec.rb +1 -1
  57. data/examples/dsc_resource/spec/run_spec.rb +1 -1
  58. data/examples/dsc_script/spec/run_spec.rb +1 -1
  59. data/examples/env/spec/create_spec.rb +1 -1
  60. data/examples/env/spec/delete_spec.rb +1 -1
  61. data/examples/env/spec/modify_spec.rb +1 -1
  62. data/examples/execute/spec/run_spec.rb +1 -1
  63. data/examples/expect_exception/spec/compile_error_spec.rb +1 -1
  64. data/examples/expect_exception/spec/converge_error_spec.rb +1 -1
  65. data/examples/expect_exception/spec/no_error_spec.rb +1 -1
  66. data/examples/file/spec/create_if_missing_spec.rb +1 -1
  67. data/examples/file/spec/create_spec.rb +1 -1
  68. data/examples/file/spec/delete_spec.rb +1 -1
  69. data/examples/file/spec/touch_spec.rb +1 -1
  70. data/examples/freebsd_package/spec/install_spec.rb +1 -1
  71. data/examples/freebsd_package/spec/remove_spec.rb +1 -1
  72. data/examples/gem_package/spec/install_spec.rb +1 -1
  73. data/examples/gem_package/spec/purge_spec.rb +1 -1
  74. data/examples/gem_package/spec/reconfig_spec.rb +1 -1
  75. data/examples/gem_package/spec/remove_spec.rb +1 -1
  76. data/examples/gem_package/spec/upgrade_spec.rb +1 -1
  77. data/examples/git/spec/checkout_spec.rb +1 -1
  78. data/examples/git/spec/export_spec.rb +1 -1
  79. data/examples/git/spec/sync_spec.rb +1 -1
  80. data/examples/group/spec/create_spec.rb +1 -1
  81. data/examples/group/spec/manage_spec.rb +1 -1
  82. data/examples/group/spec/modify_spec.rb +1 -1
  83. data/examples/group/spec/remove_spec.rb +1 -1
  84. data/examples/guards/spec/default_spec.rb +1 -1
  85. data/examples/heavy_provider_light_resource/spec/provider_service_spec.rb +1 -1
  86. data/examples/homebrew_package/spec/install_spec.rb +1 -1
  87. data/examples/homebrew_package/spec/purge_spec.rb +1 -1
  88. data/examples/homebrew_package/spec/remove_spec.rb +1 -1
  89. data/examples/homebrew_package/spec/upgrade_spec.rb +1 -1
  90. data/examples/http_request/spec/delete_spec.rb +1 -1
  91. data/examples/http_request/spec/get_spec.rb +1 -1
  92. data/examples/http_request/spec/head_spec.rb +1 -1
  93. data/examples/http_request/spec/options_spec.rb +1 -1
  94. data/examples/http_request/spec/post_spec.rb +1 -1
  95. data/examples/http_request/spec/put_spec.rb +1 -1
  96. data/examples/ifconfig/spec/add_spec.rb +1 -1
  97. data/examples/ifconfig/spec/delete_spec.rb +1 -1
  98. data/examples/ifconfig/spec/disable_spec.rb +1 -1
  99. data/examples/ifconfig/spec/enable_spec.rb +1 -1
  100. data/examples/include_recipe/spec/default_spec.rb +1 -1
  101. data/examples/ips_package/spec/install_spec.rb +1 -1
  102. data/examples/ips_package/spec/remove_spec.rb +1 -1
  103. data/examples/ips_package/spec/upgrade_spec.rb +1 -1
  104. data/examples/launchd/spec/create_if_missing_spec.rb +1 -1
  105. data/examples/launchd/spec/create_spec.rb +1 -1
  106. data/examples/launchd/spec/delete_spec.rb +1 -1
  107. data/examples/launchd/spec/disable_spec.rb +1 -1
  108. data/examples/launchd/spec/enable_spec.rb +1 -1
  109. data/examples/library_patch/libraries/default.rb +5 -0
  110. data/examples/library_patch/recipes/default.rb +1 -0
  111. data/examples/library_patch/spec/default_spec.rb +14 -0
  112. data/examples/link/spec/create_spec.rb +1 -1
  113. data/examples/link/spec/delete_spec.rb +1 -1
  114. data/examples/link/spec/link_to_spec.rb +1 -1
  115. data/examples/log/spec/write_spec.rb +1 -1
  116. data/examples/macports_package/spec/install_spec.rb +1 -1
  117. data/examples/macports_package/spec/purge_spec.rb +1 -1
  118. data/examples/macports_package/spec/remove_spec.rb +1 -1
  119. data/examples/macports_package/spec/upgrade_spec.rb +1 -1
  120. data/examples/mdadm/spec/assemble_spec.rb +1 -1
  121. data/examples/mdadm/spec/create_spec.rb +1 -1
  122. data/examples/mdadm/spec/stop_spec.rb +1 -1
  123. data/examples/mount/spec/disable_spec.rb +1 -1
  124. data/examples/mount/spec/enable_spec.rb +1 -1
  125. data/examples/mount/spec/mount_spec.rb +1 -1
  126. data/examples/mount/spec/remount_spec.rb +1 -1
  127. data/examples/mount/spec/umount_spec.rb +1 -1
  128. data/examples/msu_package/spec/install_spec.rb +1 -1
  129. data/examples/msu_package/spec/remove_spec.rb +1 -1
  130. data/examples/multiple_actions/spec/default_spec.rb +1 -1
  131. data/examples/multiple_actions/spec/reversed_spec.rb +1 -1
  132. data/examples/multiple_actions/spec/sequential_spec.rb +1 -1
  133. data/examples/multiple_run_action/spec/default_spec.rb +1 -1
  134. data/examples/nothing_matcher/spec/default_spec.rb +1 -1
  135. data/examples/notifications/spec/before_spec.rb +1 -1
  136. data/examples/notifications/spec/chained_spec.rb +1 -1
  137. data/examples/notifications/spec/default_spec.rb +1 -1
  138. data/examples/notifications/spec/delayed_spec.rb +1 -1
  139. data/examples/notifications/spec/immediately_spec.rb +1 -1
  140. data/examples/ohai/spec/reload_spec.rb +1 -1
  141. data/examples/osx_profile/spec/install_spec.rb +1 -1
  142. data/examples/osx_profile/spec/remove_spec.rb +1 -1
  143. data/examples/package/spec/install_spec.rb +1 -1
  144. data/examples/package/spec/lock_spec.rb +1 -1
  145. data/examples/package/spec/purge_spec.rb +1 -1
  146. data/examples/package/spec/reconfig_spec.rb +1 -1
  147. data/examples/package/spec/remove_spec.rb +1 -1
  148. data/examples/package/spec/unlock_spec.rb +1 -1
  149. data/examples/package/spec/upgrade_spec.rb +1 -1
  150. data/examples/pacman_package/spec/install_spec.rb +1 -1
  151. data/examples/pacman_package/spec/purge_spec.rb +1 -1
  152. data/examples/pacman_package/spec/remove_spec.rb +1 -1
  153. data/examples/pacman_package/spec/upgrade_spec.rb +1 -1
  154. data/examples/paludis_package/spec/install_spec.rb +1 -1
  155. data/examples/paludis_package/spec/purge_spec.rb +1 -1
  156. data/examples/paludis_package/spec/remove_spec.rb +1 -1
  157. data/examples/paludis_package/spec/upgrade_spec.rb +1 -1
  158. data/examples/portage_package/spec/install_spec.rb +1 -1
  159. data/examples/portage_package/spec/purge_spec.rb +1 -1
  160. data/examples/portage_package/spec/remove_spec.rb +1 -1
  161. data/examples/portage_package/spec/upgrade_spec.rb +1 -1
  162. data/examples/powershell_script/spec/run_spec.rb +1 -1
  163. data/examples/reboot/spec/cancel_spec.rb +1 -1
  164. data/examples/reboot/spec/now_spec.rb +1 -1
  165. data/examples/reboot/spec/request_spec.rb +1 -1
  166. data/examples/recipe_block/metadata.rb +1 -0
  167. data/examples/recipe_block/spec/recipe_block_spec.rb +34 -0
  168. data/examples/recipe_block/templates/apache2.conf.erb +1 -0
  169. data/examples/registry_key/spec/create_if_missing_spec.rb +1 -1
  170. data/examples/registry_key/spec/create_spec.rb +1 -1
  171. data/examples/registry_key/spec/delete_key_spec.rb +1 -1
  172. data/examples/registry_key/spec/delete_spec.rb +1 -1
  173. data/examples/remote_directory/spec/create_if_missing_spec.rb +1 -1
  174. data/examples/remote_directory/spec/create_spec.rb +1 -1
  175. data/examples/remote_directory/spec/delete_spec.rb +1 -1
  176. data/examples/remote_file/spec/create_if_missing_spec.rb +1 -1
  177. data/examples/remote_file/spec/create_spec.rb +1 -1
  178. data/examples/remote_file/spec/delete_spec.rb +1 -1
  179. data/examples/remote_file/spec/touch_spec.rb +1 -1
  180. data/examples/render_file/spec/default_spec.rb +12 -1
  181. data/examples/render_file/spec/template_helpers_spec.rb +1 -1
  182. data/examples/roles/spec/default_spec.rb +1 -1
  183. data/examples/route/spec/add_spec.rb +1 -1
  184. data/examples/route/spec/delete_spec.rb +1 -1
  185. data/examples/rpm_package/spec/install_spec.rb +1 -1
  186. data/examples/rpm_package/spec/remove_spec.rb +1 -1
  187. data/examples/rpm_package/spec/upgrade_spec.rb +1 -1
  188. data/examples/ruby_block/spec/create_spec.rb +1 -1
  189. data/examples/ruby_block/spec/run_spec.rb +1 -1
  190. data/examples/runner/recipes/default.rb +1 -0
  191. data/examples/runner/spec/default_spec.rb +11 -0
  192. data/examples/script/spec/run_bash_spec.rb +1 -1
  193. data/examples/script/spec/run_csh_spec.rb +1 -1
  194. data/examples/script/spec/run_ksh_spec.rb +1 -1
  195. data/examples/script/spec/run_perl_spec.rb +1 -1
  196. data/examples/script/spec/run_python_spec.rb +1 -1
  197. data/examples/script/spec/run_ruby_spec.rb +1 -1
  198. data/examples/script/spec/run_script_spec.rb +1 -1
  199. data/examples/server/spec/client_spec.rb +1 -1
  200. data/examples/server/spec/data_bag_spec.rb +1 -1
  201. data/examples/server/spec/environment_spec.rb +1 -1
  202. data/examples/server/spec/exotic_port_spec.rb +1 -1
  203. data/examples/server/spec/node_spec.rb +4 -4
  204. data/examples/server/spec/render_with_cached_spec.rb +1 -1
  205. data/examples/server/spec/role_spec.rb +1 -1
  206. data/examples/server/spec/search_spec.rb +1 -1
  207. data/examples/service/spec/disable_spec.rb +1 -1
  208. data/examples/service/spec/enable_spec.rb +1 -1
  209. data/examples/service/spec/reload_spec.rb +1 -1
  210. data/examples/service/spec/restart_spec.rb +1 -1
  211. data/examples/service/spec/start_spec.rb +1 -1
  212. data/examples/service/spec/stop_spec.rb +1 -1
  213. data/examples/smartos_package/spec/install_spec.rb +1 -1
  214. data/examples/smartos_package/spec/remove_spec.rb +1 -1
  215. data/examples/smartos_package/spec/upgrade_spec.rb +1 -1
  216. data/examples/solaris_package/spec/install_spec.rb +1 -1
  217. data/examples/solaris_package/spec/remove_spec.rb +1 -1
  218. data/examples/solaris_package/spec/upgrade_spec.rb +1 -1
  219. data/examples/spec_attributes/attributes/default.rb +1 -0
  220. data/examples/spec_attributes/recipes/default.rb +5 -0
  221. data/examples/spec_attributes/spec/default_spec.rb +54 -0
  222. data/examples/spec_platform/recipes/default.rb +3 -0
  223. data/examples/spec_platform/spec/default_spec.rb +36 -0
  224. data/examples/spec_step_into/recipes/default.rb +3 -0
  225. data/examples/spec_step_into/resources/one.rb +3 -0
  226. data/examples/spec_step_into/resources/two.rb +3 -0
  227. data/examples/spec_step_into/spec/default_spec.rb +50 -0
  228. data/examples/state_attrs/spec/default_spec.rb +1 -1
  229. data/examples/step_into/spec/default_spec.rb +2 -2
  230. data/examples/stub_command/spec/default_spec.rb +1 -1
  231. data/examples/stub_data_bag/spec/default_spec.rb +1 -1
  232. data/examples/stub_data_bag_item/spec/default_spec.rb +1 -1
  233. data/examples/stub_node/spec/default_spec.rb +1 -1
  234. data/examples/stub_search/spec/block_spec.rb +1 -1
  235. data/examples/stub_search/spec/default_spec.rb +1 -1
  236. data/examples/stubs_for/resources/default.rb +20 -0
  237. data/examples/stubs_for/resources/old.rb +26 -0
  238. data/examples/stubs_for/spec/default_spec.rb +240 -0
  239. data/examples/subscribes/spec/before_spec.rb +1 -1
  240. data/examples/subscribes/spec/chained_spec.rb +1 -1
  241. data/examples/subscribes/spec/default_spec.rb +1 -1
  242. data/examples/subscribes/spec/delayed_spec.rb +1 -1
  243. data/examples/subscribes/spec/immediately_spec.rb +1 -1
  244. data/examples/subversion/spec/checkout_spec.rb +1 -1
  245. data/examples/subversion/spec/export_spec.rb +1 -1
  246. data/examples/subversion/spec/force_export_spec.rb +1 -1
  247. data/examples/subversion/spec/sync_spec.rb +1 -1
  248. data/examples/systemd_unit/spec/create_spec.rb +1 -1
  249. data/examples/systemd_unit/spec/delete_spec.rb +1 -1
  250. data/examples/systemd_unit/spec/disable_spec.rb +1 -1
  251. data/examples/systemd_unit/spec/enable_spec.rb +1 -1
  252. data/examples/systemd_unit/spec/mask_spec.rb +1 -1
  253. data/examples/systemd_unit/spec/reload_or_restart_spec.rb +1 -1
  254. data/examples/systemd_unit/spec/reload_or_try_restart_spec.rb +1 -1
  255. data/examples/systemd_unit/spec/restart_spec.rb +1 -1
  256. data/examples/systemd_unit/spec/start_spec.rb +1 -1
  257. data/examples/systemd_unit/spec/stop_spec.rb +1 -1
  258. data/examples/systemd_unit/spec/try_restart_spec.rb +1 -1
  259. data/examples/systemd_unit/spec/unmask_spec.rb +1 -1
  260. data/examples/template/spec/create_if_missing_spec.rb +1 -1
  261. data/examples/template/spec/create_spec.rb +1 -1
  262. data/examples/template/spec/delete_spec.rb +1 -1
  263. data/examples/template/spec/touch_spec.rb +1 -1
  264. data/examples/use_inline_resources/spec/default_spec.rb +1 -1
  265. data/examples/user/spec/create_spec.rb +1 -1
  266. data/examples/user/spec/lock_spec.rb +1 -1
  267. data/examples/user/spec/manage_spec.rb +1 -1
  268. data/examples/user/spec/modify_spec.rb +1 -1
  269. data/examples/user/spec/remove_spec.rb +1 -1
  270. data/examples/user/spec/unlock_spec.rb +1 -1
  271. data/examples/windows_package/spec/install_spec.rb +1 -1
  272. data/examples/windows_package/spec/remove_spec.rb +1 -1
  273. data/examples/windows_service/spec/configure_startup_spec.rb +1 -1
  274. data/examples/windows_service/spec/disable_spec.rb +1 -1
  275. data/examples/windows_service/spec/enable_spec.rb +1 -1
  276. data/examples/windows_service/spec/reload_spec.rb +1 -1
  277. data/examples/windows_service/spec/restart_spec.rb +1 -1
  278. data/examples/windows_service/spec/start_spec.rb +1 -1
  279. data/examples/windows_service/spec/stop_spec.rb +1 -1
  280. data/examples/yum_package/spec/install_spec.rb +1 -1
  281. data/examples/yum_package/spec/lock_spec.rb +1 -1
  282. data/examples/yum_package/spec/purge_spec.rb +1 -1
  283. data/examples/yum_package/spec/remove_spec.rb +1 -1
  284. data/examples/yum_package/spec/unlock_spec.rb +1 -1
  285. data/examples/yum_package/spec/upgrade_spec.rb +1 -1
  286. data/examples/yum_repository/spec/add_spec.rb +1 -1
  287. data/examples/yum_repository/spec/create_spec.rb +1 -1
  288. data/examples/yum_repository/spec/delete_spec.rb +1 -1
  289. data/examples/yum_repository/spec/makecache_spec.rb +1 -1
  290. data/examples/yum_repository/spec/remove_spec.rb +1 -1
  291. data/examples/zypper_package/spec/install_spec.rb +1 -1
  292. data/examples/zypper_package/spec/lock_spec.rb +1 -1
  293. data/examples/zypper_package/spec/purge_spec.rb +1 -1
  294. data/examples/zypper_package/spec/remove_spec.rb +1 -1
  295. data/examples/zypper_package/spec/unlock_spec.rb +1 -1
  296. data/examples/zypper_package/spec/upgrade_spec.rb +1 -1
  297. data/lib/chefspec.rb +1 -1
  298. data/lib/chefspec/api.rb +33 -14
  299. data/lib/chefspec/api/core.rb +195 -0
  300. data/lib/chefspec/api/described.rb +55 -0
  301. data/lib/chefspec/api/do_nothing.rb +24 -19
  302. data/lib/chefspec/api/include_recipe.rb +26 -21
  303. data/lib/chefspec/api/link.rb +26 -21
  304. data/lib/chefspec/api/notifications.rb +38 -33
  305. data/lib/chefspec/api/reboot.rb +11 -6
  306. data/lib/chefspec/api/render_file.rb +35 -30
  307. data/lib/chefspec/api/state_attrs.rb +28 -23
  308. data/lib/chefspec/api/stubs.rb +183 -0
  309. data/lib/chefspec/api/stubs_for.rb +134 -0
  310. data/lib/chefspec/api/subscriptions.rb +35 -30
  311. data/lib/chefspec/api/user.rb +222 -217
  312. data/lib/chefspec/berkshelf.rb +1 -1
  313. data/lib/chefspec/deprecations.rb +2 -11
  314. data/lib/chefspec/errors.rb +1 -0
  315. data/lib/chefspec/extensions.rb +4 -1
  316. data/lib/chefspec/extensions/chef/client.rb +3 -4
  317. data/lib/chefspec/extensions/chef/conditional.rb +3 -2
  318. data/lib/chefspec/extensions/chef/cookbook/gem_installer.rb +25 -28
  319. data/lib/chefspec/extensions/chef/cookbook_loader.rb +13 -0
  320. data/lib/chefspec/extensions/chef/cookbook_uploader.rb +3 -2
  321. data/lib/chefspec/extensions/chef/data_query.rb +5 -8
  322. data/lib/chefspec/extensions/chef/lwrp_base.rb +17 -21
  323. data/lib/chefspec/extensions/chef/provider.rb +36 -0
  324. data/lib/chefspec/extensions/chef/resource.rb +51 -4
  325. data/lib/chefspec/extensions/chef/resource/freebsd_package.rb +13 -16
  326. data/lib/chefspec/extensions/chef/run_context/cookbook_compiler.rb +64 -0
  327. data/lib/chefspec/matchers/render_file_matcher.rb +36 -26
  328. data/lib/chefspec/matchers/resource_matcher.rb +1 -1
  329. data/lib/chefspec/rspec.rb +3 -8
  330. data/lib/chefspec/runner.rb +8 -0
  331. data/lib/chefspec/server_methods.rb +1 -1
  332. data/lib/chefspec/server_runner.rb +13 -9
  333. data/lib/chefspec/solo_runner.rb +136 -32
  334. data/lib/chefspec/version.rb +1 -1
  335. data/spec/unit/deprecations_spec.rb +1 -26
  336. data/spec/unit/macros_spec.rb +14 -14
  337. data/spec/unit/matchers/render_file_matcher_spec.rb +8 -1
  338. data/spec/unit/solo_runner_spec.rb +3 -3
  339. data/templates/errors/may_need_to_specify_platform.erb +1 -1
  340. data/templates/errors/shell_out_not_stubbed.erb +10 -0
  341. metadata +38 -4
  342. data/lib/chefspec/macros.rb +0 -222
@@ -0,0 +1,64 @@
1
+ require 'chef/run_context/cookbook_compiler'
2
+
3
+ Chef::RunContext::CookbookCompiler.prepend(Module.new do
4
+ # List of compile phases as of Chef 14:
5
+ # compile_libraries
6
+ # compile_ohai_plugins
7
+ # compile_attributes
8
+ # compile_lwrps
9
+ # compile_resource_definitions
10
+ # compile_recipes
11
+
12
+ #
13
+ # Compile phases that should only ever run once, globally.
14
+ #
15
+
16
+ def load_libraries_from_cookbook(cookbook)
17
+ return super unless $CHEFSPEC_MODE
18
+ $CHEFSPEC_LIBRARY_PRELOAD ||= {}
19
+ # Already loaded this once.
20
+ return if $CHEFSPEC_LIBRARY_PRELOAD[cookbook]
21
+ $CHEFSPEC_LIBRARY_PRELOAD[cookbook] = true
22
+ super
23
+ end
24
+
25
+ def load_lwrps_from_cookbook(cookbook)
26
+ return super unless $CHEFSPEC_MODE
27
+ $CHEFSPEC_LWRP_PRELOAD ||= {}
28
+ # Already loaded this once.
29
+ return if $CHEFSPEC_LWRP_PRELOAD[cookbook]
30
+ $CHEFSPEC_LWRP_PRELOAD[cookbook] = true
31
+ super
32
+ end
33
+
34
+ def load_resource_definitions_from_cookbook(cookbook)
35
+ return super unless $CHEFSPEC_MODE
36
+ $CHEFSPEC_DEFINITION_PRELOAD ||= {}
37
+ # Already loaded this once.
38
+ return if $CHEFSPEC_DEFINITION_PRELOAD[cookbook]
39
+ $CHEFSPEC_DEFINITION_PRELOAD[cookbook] = true
40
+ super
41
+ end
42
+
43
+ #
44
+ # Compile phases that should not run during preload
45
+ #
46
+
47
+ def compile_ohai_plugins
48
+ return super unless $CHEFSPEC_MODE
49
+ return if $CHEFSPEC_PRELOAD
50
+ super
51
+ end
52
+
53
+ def compile_attributes
54
+ return super unless $CHEFSPEC_MODE
55
+ return if $CHEFSPEC_PRELOAD
56
+ super
57
+ end
58
+
59
+ def compile_recipes
60
+ return super unless $CHEFSPEC_MODE
61
+ return if $CHEFSPEC_PRELOAD
62
+ super
63
+ end
64
+ end)
@@ -3,6 +3,7 @@ module ChefSpec::Matchers
3
3
  attr_reader :expected_content
4
4
  def initialize(path)
5
5
  @path = path
6
+ @expected_content = []
6
7
  end
7
8
 
8
9
  def matches?(runner)
@@ -20,9 +21,9 @@ module ChefSpec::Matchers
20
21
  if expected_content && block
21
22
  raise ArgumentError, "Cannot specify expected content and a block!"
22
23
  elsif expected_content
23
- @expected_content = expected_content
24
+ @expected_content << expected_content
24
25
  elsif block_given?
25
- @expected_content = block
26
+ @expected_content << block
26
27
  else
27
28
  raise ArgumentError, "Must specify expected content or a block!"
28
29
  end
@@ -32,11 +33,11 @@ module ChefSpec::Matchers
32
33
 
33
34
  def description
34
35
  message = %Q{render file "#{@path}"}
35
- if @expected_content
36
- if @expected_content.to_s.include?("\n")
36
+ @expected_content.each do |expected|
37
+ if expected.to_s.include?("\n")
37
38
  message << " with content <suppressed>"
38
39
  else
39
- message << " with content #{@expected_content.inspect}"
40
+ message << " with content #{expected.inspect}"
40
41
  end
41
42
  end
42
43
  message
@@ -44,7 +45,7 @@ module ChefSpec::Matchers
44
45
 
45
46
  def failure_message
46
47
  message = %Q{expected Chef run to render "#{@path}"}
47
- if @expected_content
48
+ unless @expected_content.empty?
48
49
  message << " matching:"
49
50
  message << "\n\n"
50
51
  message << expected_content_message
@@ -59,7 +60,7 @@ module ChefSpec::Matchers
59
60
 
60
61
  def failure_message_when_negated
61
62
  message = %Q{expected file "#{@path}"}
62
- if @expected_content
63
+ unless @expected_content.empty?
63
64
  message << " matching:"
64
65
  message << "\n\n"
65
66
  message << expected_content_message
@@ -72,13 +73,16 @@ module ChefSpec::Matchers
72
73
  private
73
74
 
74
75
  def expected_content_message
75
- if RSpec::Matchers.is_a_matcher?(@expected_content) && @expected_content.respond_to?(:description)
76
- @expected_content.description
77
- elsif @expected_content.is_a?(Proc)
78
- "(the result of a proc)"
79
- else
80
- @expected_content.to_s
76
+ messages = @expected_content.collect do |expected|
77
+ if RSpec::Matchers.is_a_matcher?(expected) && expected.respond_to?(:description)
78
+ expected.description
79
+ elsif expected.is_a?(Proc)
80
+ "(the result of a proc)"
81
+ else
82
+ expected.to_s
83
+ end
81
84
  end
85
+ messages.join("\n\n")
82
86
  end
83
87
 
84
88
  def resource
@@ -106,25 +110,31 @@ module ChefSpec::Matchers
106
110
  # @return [true, false]
107
111
  #
108
112
  def matches_content?
109
- return true if @expected_content.nil?
113
+ return true if @expected_content.empty?
110
114
 
111
115
  @actual_content = ChefSpec::Renderer.new(@runner, resource).content
112
116
 
113
117
  return false if @actual_content.nil?
114
118
 
115
- if @expected_content.is_a?(Regexp)
116
- @actual_content =~ @expected_content
117
- elsif RSpec::Matchers.is_a_matcher?(@expected_content)
118
- @expected_content.matches?(@actual_content)
119
- elsif @expected_content.is_a?(Proc)
120
- @expected_content.call(@actual_content)
121
- # Weird RSpecish, but that block will return false for a negated check,
122
- # so we always return true. The block will raise an exception if the
123
- # assertion fails.
124
- true
125
- else
126
- @actual_content.include?(@expected_content)
119
+ # Knock out matches that pass. When we're done, we pass if the list is
120
+ # empty. Otherwise, @expected_content is the list of matchers that
121
+ # failed
122
+ @expected_content.delete_if do |expected|
123
+ if expected.is_a?(Regexp)
124
+ @actual_content =~ expected
125
+ elsif RSpec::Matchers.is_a_matcher?(expected)
126
+ expected.matches?(@actual_content)
127
+ elsif expected.is_a?(Proc)
128
+ expected.call(@actual_content)
129
+ # Weird RSpecish, but that block will return false for a negated check,
130
+ # so we always return true. The block will raise an exception if the
131
+ # assertion fails.
132
+ true
133
+ else
134
+ @actual_content.include?(expected)
135
+ end
127
136
  end
137
+ @expected_content.empty?
128
138
  end
129
139
  end
130
140
  end
@@ -39,7 +39,7 @@ module ChefSpec::Matchers
39
39
  end
40
40
 
41
41
  def description
42
- %Q{#{@expected_actioe} #{@resource_name} "#{@expected_identity}"}
42
+ %Q{#{@expected_action} #{@resource_name} "#{@expected_identity}"}
43
43
  end
44
44
 
45
45
  def matches?(runner)
@@ -1,16 +1,11 @@
1
1
  RSpec.configure do |config|
2
- config.include(ChefSpec::API)
3
- config.include(ChefSpec::Macros)
4
-
5
- config.after(:each) do
6
- ChefSpec::Stubs::CommandRegistry.reset!
7
- ChefSpec::Stubs::DataBagRegistry.reset!
8
- ChefSpec::Stubs::DataBagItemRegistry.reset!
9
- ChefSpec::Stubs::SearchRegistry.reset!
2
+ unless ENV['CHEFSPEC_NO_INCLUDE']
3
+ config.include(ChefSpec::API)
10
4
  end
11
5
 
12
6
  config.add_setting :berkshelf_options, default: {}
13
7
  config.add_setting :file_cache_path
8
+ config.add_setting :cookbook_root
14
9
  config.add_setting :cookbook_path
15
10
  config.add_setting :role_path
16
11
  config.add_setting :environment_path
@@ -0,0 +1,8 @@
1
+ require "chefspec/solo_runner"
2
+
3
+ module ChefSpec
4
+ # As we start to migrate back to only SoloRunner, include this alias for now.
5
+ #
6
+ # @since 7.3
7
+ Runner = SoloRunner
8
+ end
@@ -118,7 +118,7 @@ module ChefSpec
118
118
  #
119
119
  # @example Create a node from a +Chef::Node+ object
120
120
  #
121
- # node = stub_node('bacon', platform: 'ubuntu', version: '16.04')
121
+ # node = stub_node('bacon', platform: 'ubuntu', version: '18.04')
122
122
  # create_node(node)
123
123
  #
124
124
  # @param [String, Chef::Node] object
@@ -23,15 +23,6 @@ module ChefSpec
23
23
  # our yielding.
24
24
  super(options, &nil)
25
25
 
26
- Chef::Config[:client_key] = client_key
27
- Chef::Config[:client_name] = 'chefspec'
28
- Chef::Config[:node_name] = 'chefspec'
29
- Chef::Config[:solo] = false
30
- Chef::Config[:solo_legacy_mode] = false
31
-
32
- Chef::Config[:chef_server_url] = server.url
33
- Chef::Config[:http_retry_count] = 0
34
-
35
26
  # Unlike the SoloRunner, the node AND server object are yielded for
36
27
  # customization
37
28
  yield node, self if block_given?
@@ -68,5 +59,18 @@ module ChefSpec
68
59
  at_exit { FileUtils.rm_rf(tmp) }
69
60
  path
70
61
  end
62
+
63
+ # (see SoloRunner#apply_chef_config!)
64
+ def apply_chef_config!
65
+ super
66
+ Chef::Config[:client_key] = client_key
67
+ Chef::Config[:client_name] = 'chefspec'
68
+ Chef::Config[:node_name] = 'chefspec'
69
+ Chef::Config[:solo] = false
70
+ Chef::Config[:solo_legacy_mode] = false
71
+
72
+ Chef::Config[:chef_server_url] = server.url
73
+ Chef::Config[:http_retry_count] = 0
74
+ end
71
75
  end
72
76
  end
@@ -1,5 +1,6 @@
1
1
  require 'fauxhai'
2
2
  require 'chef/client'
3
+ require 'chef/cookbook/metadata'
3
4
  require 'chef/mash'
4
5
  require 'chef/providers'
5
6
  require 'chef/resources'
@@ -34,7 +35,7 @@ module ChefSpec
34
35
  # ChefSpec::SoloRunner.new
35
36
  #
36
37
  # @example Specifying the platform and version
37
- # ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04')
38
+ # ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '18.04')
38
39
  #
39
40
  # @example Specifying the cookbook path
40
41
  # ChefSpec::SoloRunner.new(cookbook_path: ['/cookbooks'])
@@ -63,26 +64,7 @@ module ChefSpec
63
64
  #
64
65
  def initialize(options = {})
65
66
  @options = with_default_options(options)
66
-
67
- Chef::Log.level = @options[:log_level]
68
-
69
- Chef::Config.reset!
70
- Chef::Config.formatters.clear
71
- Chef::Config.add_formatter('chefspec')
72
- Chef::Config[:cache_type] = 'Memory'
73
- Chef::Config[:client_key] = nil
74
- Chef::Config[:client_name] = nil
75
- Chef::Config[:node_name] = nil
76
- Chef::Config[:file_cache_path] = @options[:file_cache_path] || file_cache_path
77
- Chef::Config[:cookbook_path] = Array(@options[:cookbook_path])
78
- Chef::Config[:no_lazy_load] = true
79
- Chef::Config[:role_path] = Array(@options[:role_path])
80
- Chef::Config[:force_logger] = true
81
- Chef::Config[:solo] = true
82
- Chef::Config[:solo_legacy_mode] = true
83
- Chef::Config[:use_policyfile] = false
84
- Chef::Config[:environment_path] = @options[:environment_path]
85
-
67
+ apply_chef_config!
86
68
  yield node if block_given?
87
69
  end
88
70
 
@@ -105,6 +87,10 @@ module ChefSpec
105
87
  # A reference to the calling Runner (for chaining purposes)
106
88
  #
107
89
  def converge(*recipe_names)
90
+ # Re-apply the Chef config before converging in case something else
91
+ # called Config.reset too.
92
+ apply_chef_config!
93
+ @converging = false
108
94
  node.run_list.reset!
109
95
  recipe_names.each { |recipe_name| node.run_list.add(recipe_name) }
110
96
 
@@ -113,6 +99,14 @@ module ChefSpec
113
99
  # Expand the run_list
114
100
  expand_run_list!
115
101
 
102
+ # Merge in provided node attributes. Default and override use the role_
103
+ # levels so they win over the relevant bits from cookbooks since otherwise
104
+ # they would not and that would be confusing.
105
+ node.attributes.role_default = Chef::Mixin::DeepMerge.merge(node.attributes.role_default, options[:default_attributes]) if options[:default_attributes]
106
+ node.attributes.normal = Chef::Mixin::DeepMerge.merge(node.attributes.normal, options[:normal_attributes]) if options[:normal_attributes]
107
+ node.attributes.role_override = Chef::Mixin::DeepMerge.merge(node.attributes.role_override, options[:override_attributes]) if options[:override_attributes]
108
+ node.attributes.automatic = Chef::Mixin::DeepMerge.merge(node.attributes.automatic, options[:automatic_attributes]) if options[:automatic_attributes]
109
+
116
110
  # Setup the run_context, rescuing the exception that happens when a
117
111
  # resource is not defined on a particular platform
118
112
  begin
@@ -132,18 +126,53 @@ module ChefSpec
132
126
  self
133
127
  end
134
128
 
129
+ #
130
+ # Execute a block of recipe code.
131
+ #
132
+ # @param [Proc] block
133
+ # A block containing Chef recipe code
134
+ #
135
+ # @return [ChefSpec::SoloRunner]
136
+ #
137
+ def converge_block(&block)
138
+ converge do
139
+ recipe = Chef::Recipe.new(cookbook_name, '_test', run_context)
140
+ recipe.instance_exec(&block)
141
+ end
142
+ end
143
+
144
+ #
145
+ # Run a static preload of the cookbook under test. This will load libraries
146
+ # and resources, but not attributes or recipes.
147
+ #
148
+ # @return [void]
149
+ #
150
+ def preload!
151
+ # Flag to disable preloading for situations where it doesn't make sense.
152
+ return if ENV['CHEFSPEC_NO_PRELOAD']
153
+ begin
154
+ old_preload = $CHEFSPEC_PRELOAD
155
+ $CHEFSPEC_PRELOAD = true
156
+ converge("recipe[#{cookbook_name}]")
157
+ node.run_list.reset!
158
+ ensure
159
+ $CHEFSPEC_PRELOAD = old_preload
160
+ end
161
+ end
162
+
135
163
  #
136
164
  # The +Chef::Node+ corresponding to this Runner.
137
165
  #
138
166
  # @return [Chef::Node]
139
167
  #
140
168
  def node
141
- return @node if @node
142
-
143
- @node = client.build_node
144
- @node.instance_variable_set(:@runner, self)
145
- @node.class.send(:attr_reader, :runner)
146
- @node
169
+ runner = self
170
+ @node ||= begin
171
+ apply_chef_config!
172
+ client.build_node.tap do |node|
173
+ node.define_singleton_method(:runner) { runner }
174
+ end
175
+ end
147
176
  end
148
177
 
149
178
  #
@@ -306,7 +335,8 @@ module ChefSpec
306
335
  config = RSpec.configuration
307
336
 
308
337
  {
309
- cookbook_path: config.cookbook_path || calling_cookbook_path(caller),
338
+ cookbook_root: config.cookbook_root || calling_cookbook_root(options, caller),
339
+ cookbook_path: config.cookbook_path || calling_cookbook_path(options, caller),
310
340
  role_path: config.role_path || default_role_path,
311
341
  environment_path: config.environment_path || default_environment_path,
312
342
  file_cache_path: config.file_cache_path,
@@ -318,21 +348,37 @@ module ChefSpec
318
348
  end
319
349
 
320
350
  #
321
- # The inferred path from the calling spec.
351
+ # The inferred cookbook root from the calling spec.
322
352
  #
353
+ # @param [Hash<Symbol, Object>] options
354
+ # initial runner options
323
355
  # @param [Array<String>] kaller
324
356
  # the calling trace
325
357
  #
326
358
  # @return [String]
327
359
  #
328
- def calling_cookbook_path(kaller)
329
- calling_spec = kaller.find { |line| line =~ /\/spec/ }
360
+ def calling_cookbook_root(options, kaller)
361
+ calling_spec = options[:spec_declaration_locations] || kaller.find { |line| line =~ /\/spec/ }
330
362
  raise Error::CookbookPathNotFound if calling_spec.nil?
331
363
 
332
364
  bits = calling_spec.split(/:[0-9]/, 2).first.split(File::SEPARATOR)
333
365
  spec_dir = bits.index('spec') || 0
334
366
 
335
- File.expand_path(File.join(bits.slice(0, spec_dir), '..'))
367
+ File.join(bits.slice(0, spec_dir))
368
+ end
369
+
370
+ #
371
+ # The inferred path from the calling spec.
372
+ #
373
+ # @param [Hash<Symbol, Object>] options
374
+ # initial runner options
375
+ # @param [Array<String>] kaller
376
+ # the calling trace
377
+ #
378
+ # @return [String]
379
+ #
380
+ def calling_cookbook_path(options, kaller)
381
+ File.expand_path(File.join(calling_cookbook_root(options, kaller), '..'))
336
382
  end
337
383
 
338
384
  #
@@ -406,5 +452,63 @@ module ChefSpec
406
452
  end
407
453
  end
408
454
  end
455
+
456
+ #
457
+ # Try to load the cookbook metadata for the cookbook under test.
458
+ #
459
+ # @return [Chef::Cookbook::Metadata]
460
+ #
461
+ def cookbook
462
+ @cookbook ||= Chef::Cookbook::Metadata.new.tap {|m| m.from_file("#{options[:cookbook_root]}/metadata.rb") }
463
+ end
464
+
465
+ #
466
+ # Try to figure out the name for the cookbook under test.
467
+ #
468
+ # @return [String]
469
+ #
470
+ def cookbook_name
471
+ # Try to figure out the name of this cookbook, pretending this block
472
+ # is in the name context as the cookbook under test.
473
+ begin
474
+ cookbook.name
475
+ rescue IOError
476
+ # Old cookbook, has no metadata, use the folder name I guess.
477
+ File.basename(options[:cookbook_root])
478
+ end
479
+ end
480
+
481
+ #
482
+ # Apply the required options to {Chef::Config}.
483
+ #
484
+ # @api private
485
+ # @return [void]
486
+ #
487
+ def apply_chef_config!
488
+ Chef::Log.level = @options[:log_level]
489
+
490
+ Chef::Config.reset!
491
+ Chef::Config.formatters.clear
492
+ Chef::Config.add_formatter('chefspec')
493
+ Chef::Config[:cache_type] = 'Memory'
494
+ Chef::Config[:client_key] = nil
495
+ Chef::Config[:client_name] = nil
496
+ Chef::Config[:node_name] = nil
497
+ Chef::Config[:file_cache_path] = @options[:file_cache_path] || file_cache_path
498
+ Chef::Config[:cookbook_path] = Array(@options[:cookbook_path])
499
+ # If the word cookbook is in the folder name, treat it as the path. Otherwise
500
+ # it's probably not a cookbook path and so we activate the gross hack mode.
501
+ if Chef::Config[:cookbook_path].size == 1 && Chef::Config[:cookbook_path].first !~ /cookbook/
502
+ Chef::Config[:chefspec_cookbook_root] = @options[:cookbook_root]
503
+ end
504
+ Chef::Config[:no_lazy_load] = true
505
+ Chef::Config[:role_path] = Array(@options[:role_path])
506
+ Chef::Config[:force_logger] = true
507
+ Chef::Config[:solo] = true
508
+ Chef::Config[:solo_legacy_mode] = true
509
+ Chef::Config[:use_policyfile] = false
510
+ Chef::Config[:environment_path] = @options[:environment_path]
511
+ end
512
+
409
513
  end
410
514
  end