chefspec 4.0.2 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (264) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -1
  3. data/CHANGELOG.md +19 -0
  4. data/README.md +84 -87
  5. data/chefspec.gemspec +1 -1
  6. data/examples/apt_package/spec/install_spec.rb +1 -1
  7. data/examples/apt_package/spec/purge_spec.rb +1 -1
  8. data/examples/apt_package/spec/reconfig_spec.rb +1 -1
  9. data/examples/apt_package/spec/remove_spec.rb +1 -1
  10. data/examples/apt_package/spec/upgrade_spec.rb +1 -1
  11. data/examples/attributes/spec/default_spec.rb +1 -1
  12. data/examples/batch/spec/run_spec.rb +1 -1
  13. data/examples/cached/spec/default_spec.rb +1 -1
  14. data/examples/chef_gem/spec/install_spec.rb +1 -1
  15. data/examples/chef_gem/spec/purge_spec.rb +1 -1
  16. data/examples/chef_gem/spec/reconfig_spec.rb +1 -1
  17. data/examples/chef_gem/spec/remove_spec.rb +1 -1
  18. data/examples/chef_gem/spec/upgrade_spec.rb +1 -1
  19. data/examples/compile_time/spec/default_spec.rb +1 -1
  20. data/examples/cookbook_file/spec/create_if_missing_spec.rb +1 -1
  21. data/examples/cookbook_file/spec/create_spec.rb +1 -1
  22. data/examples/cookbook_file/spec/delete_spec.rb +1 -1
  23. data/examples/cookbook_file/spec/touch_spec.rb +1 -1
  24. data/examples/cron/spec/create_spec.rb +1 -1
  25. data/examples/cron/spec/delete_spec.rb +1 -1
  26. data/examples/custom_matcher/libraries/matcher.rb +1 -1
  27. data/examples/custom_matcher/spec/install_spec.rb +1 -1
  28. data/examples/custom_matcher/spec/remove_spec.rb +1 -1
  29. data/examples/deploy/spec/deploy_spec.rb +1 -1
  30. data/examples/deploy/spec/force_deploy_spec.rb +1 -1
  31. data/examples/deploy/spec/rollback_spec.rb +1 -1
  32. data/examples/directory/spec/create_spec.rb +1 -1
  33. data/examples/directory/spec/delete_spec.rb +1 -1
  34. data/examples/do_nothing/spec/default_spec.rb +1 -1
  35. data/examples/dpkg_package/spec/install_spec.rb +1 -1
  36. data/examples/dpkg_package/spec/purge_spec.rb +1 -1
  37. data/examples/dpkg_package/spec/remove_spec.rb +1 -1
  38. data/examples/easy_install_package/spec/install_spec.rb +1 -1
  39. data/examples/easy_install_package/spec/purge_spec.rb +1 -1
  40. data/examples/easy_install_package/spec/remove_spec.rb +1 -1
  41. data/examples/easy_install_package/spec/upgrade_spec.rb +1 -1
  42. data/examples/env/spec/create_spec.rb +1 -1
  43. data/examples/env/spec/delete_spec.rb +1 -1
  44. data/examples/env/spec/modify_spec.rb +1 -1
  45. data/examples/erl_call/spec/run_spec.rb +1 -1
  46. data/examples/execute/spec/run_spec.rb +1 -1
  47. data/examples/expect_exception/spec/compile_error_spec.rb +1 -1
  48. data/examples/expect_exception/spec/converge_error_spec.rb +1 -1
  49. data/examples/expect_exception/spec/no_error_spec.rb +1 -1
  50. data/examples/file/spec/create_if_missing_spec.rb +1 -1
  51. data/examples/file/spec/create_spec.rb +1 -1
  52. data/examples/file/spec/delete_spec.rb +1 -1
  53. data/examples/file/spec/touch_spec.rb +1 -1
  54. data/examples/freebsd_package/spec/install_spec.rb +1 -1
  55. data/examples/freebsd_package/spec/remove_spec.rb +1 -1
  56. data/examples/gem_package/spec/install_spec.rb +1 -1
  57. data/examples/gem_package/spec/purge_spec.rb +1 -1
  58. data/examples/gem_package/spec/reconfig_spec.rb +1 -1
  59. data/examples/gem_package/spec/remove_spec.rb +1 -1
  60. data/examples/gem_package/spec/upgrade_spec.rb +1 -1
  61. data/examples/git/spec/checkout_spec.rb +1 -1
  62. data/examples/git/spec/export_spec.rb +1 -1
  63. data/examples/git/spec/sync_spec.rb +1 -1
  64. data/examples/group/spec/create_spec.rb +1 -1
  65. data/examples/group/spec/manage_spec.rb +1 -1
  66. data/examples/group/spec/modify_spec.rb +1 -1
  67. data/examples/group/spec/remove_spec.rb +1 -1
  68. data/examples/guards/spec/default_spec.rb +1 -1
  69. data/examples/heavy_provider_light_resource/spec/provider_service_spec.rb +1 -1
  70. data/examples/http_request/spec/delete_spec.rb +1 -1
  71. data/examples/http_request/spec/get_spec.rb +1 -1
  72. data/examples/http_request/spec/head_spec.rb +1 -1
  73. data/examples/http_request/spec/options_spec.rb +1 -1
  74. data/examples/http_request/spec/post_spec.rb +1 -1
  75. data/examples/http_request/spec/put_spec.rb +1 -1
  76. data/examples/ifconfig/spec/add_spec.rb +1 -1
  77. data/examples/ifconfig/spec/delete_spec.rb +1 -1
  78. data/examples/ifconfig/spec/disable_spec.rb +1 -1
  79. data/examples/ifconfig/spec/enable_spec.rb +1 -1
  80. data/examples/include_recipe/spec/default_spec.rb +1 -1
  81. data/examples/inherits/spec/default_spec.rb +1 -1
  82. data/examples/ips_package/spec/install_spec.rb +1 -1
  83. data/examples/ips_package/spec/remove_spec.rb +1 -1
  84. data/examples/ips_package/spec/upgrade_spec.rb +1 -1
  85. data/examples/link/spec/create_spec.rb +1 -1
  86. data/examples/link/spec/delete_spec.rb +1 -1
  87. data/examples/link/spec/link_to_spec.rb +1 -1
  88. data/examples/log/spec/write_spec.rb +1 -1
  89. data/examples/macports_package/spec/install_spec.rb +1 -1
  90. data/examples/macports_package/spec/purge_spec.rb +1 -1
  91. data/examples/macports_package/spec/remove_spec.rb +1 -1
  92. data/examples/macports_package/spec/upgrade_spec.rb +1 -1
  93. data/examples/mdadm/spec/assemble_spec.rb +1 -1
  94. data/examples/mdadm/spec/create_spec.rb +1 -1
  95. data/examples/mdadm/spec/stop_spec.rb +1 -1
  96. data/examples/mount/spec/disable_spec.rb +1 -1
  97. data/examples/mount/spec/enable_spec.rb +1 -1
  98. data/examples/mount/spec/mount_spec.rb +1 -1
  99. data/examples/mount/spec/remount_spec.rb +1 -1
  100. data/examples/mount/spec/umount_spec.rb +1 -1
  101. data/examples/multiple_actions/spec/default_spec.rb +1 -1
  102. data/examples/multiple_actions/spec/sequential_spec.rb +4 -1
  103. data/examples/multiple_run_action/spec/default_spec.rb +1 -1
  104. data/examples/notifications/spec/chained_spec.rb +1 -1
  105. data/examples/notifications/spec/default_spec.rb +1 -1
  106. data/examples/notifications/spec/delayed_spec.rb +1 -1
  107. data/examples/notifications/spec/immediately_spec.rb +1 -1
  108. data/examples/ohai/spec/reload_spec.rb +1 -1
  109. data/examples/package/spec/install_spec.rb +1 -1
  110. data/examples/package/spec/purge_spec.rb +1 -1
  111. data/examples/package/spec/reconfig_spec.rb +1 -1
  112. data/examples/package/spec/remove_spec.rb +1 -1
  113. data/examples/package/spec/upgrade_spec.rb +1 -1
  114. data/examples/pacman_package/spec/install_spec.rb +1 -1
  115. data/examples/pacman_package/spec/purge_spec.rb +1 -1
  116. data/examples/pacman_package/spec/remove_spec.rb +1 -1
  117. data/examples/pacman_package/spec/upgrade_spec.rb +1 -1
  118. data/examples/portage_package/spec/install_spec.rb +1 -1
  119. data/examples/portage_package/spec/purge_spec.rb +1 -1
  120. data/examples/portage_package/spec/remove_spec.rb +1 -1
  121. data/examples/portage_package/spec/upgrade_spec.rb +1 -1
  122. data/examples/powershell_script/spec/run_spec.rb +1 -1
  123. data/examples/registry_key/spec/create_if_missing_spec.rb +1 -1
  124. data/examples/registry_key/spec/create_spec.rb +1 -1
  125. data/examples/registry_key/spec/delete_key_spec.rb +1 -1
  126. data/examples/registry_key/spec/delete_spec.rb +1 -1
  127. data/examples/remote_directory/spec/create_if_missing_spec.rb +1 -1
  128. data/examples/remote_directory/spec/create_spec.rb +1 -1
  129. data/examples/remote_directory/spec/delete_spec.rb +1 -1
  130. data/examples/remote_file/spec/create_if_missing_spec.rb +1 -1
  131. data/examples/remote_file/spec/create_spec.rb +1 -1
  132. data/examples/remote_file/spec/delete_spec.rb +1 -1
  133. data/examples/remote_file/spec/touch_spec.rb +1 -1
  134. data/examples/render_file/spec/default_spec.rb +1 -1
  135. data/examples/render_file/spec/template_helpers_spec.rb +1 -1
  136. data/examples/roles/spec/default_spec.rb +1 -1
  137. data/examples/route/spec/add_spec.rb +1 -1
  138. data/examples/route/spec/delete_spec.rb +1 -1
  139. data/examples/rpm_package/spec/install_spec.rb +1 -1
  140. data/examples/rpm_package/spec/remove_spec.rb +1 -1
  141. data/examples/rpm_package/spec/upgrade_spec.rb +1 -1
  142. data/examples/ruby_block/spec/run_spec.rb +1 -1
  143. data/examples/script/spec/run_bash_spec.rb +1 -1
  144. data/examples/script/spec/run_csh_spec.rb +1 -1
  145. data/examples/script/spec/run_perl_spec.rb +1 -1
  146. data/examples/script/spec/run_python_spec.rb +1 -1
  147. data/examples/script/spec/run_ruby_spec.rb +1 -1
  148. data/examples/script/spec/run_script_spec.rb +1 -1
  149. data/examples/server/spec/client_spec.rb +5 -4
  150. data/examples/server/spec/data_bag_spec.rb +10 -9
  151. data/examples/server/spec/environment_spec.rb +5 -4
  152. data/examples/server/spec/node_spec.rb +20 -14
  153. data/examples/server/spec/render_with_cached_spec.rb +1 -2
  154. data/examples/server/spec/role_spec.rb +5 -4
  155. data/examples/server/spec/search_spec.rb +7 -8
  156. data/examples/service/spec/disable_spec.rb +1 -1
  157. data/examples/service/spec/enable_spec.rb +1 -1
  158. data/examples/service/spec/reload_spec.rb +1 -1
  159. data/examples/service/spec/restart_spec.rb +1 -1
  160. data/examples/service/spec/start_spec.rb +1 -1
  161. data/examples/service/spec/stop_spec.rb +1 -1
  162. data/examples/smartos_package/spec/install_spec.rb +1 -1
  163. data/examples/smartos_package/spec/remove_spec.rb +1 -1
  164. data/examples/smartos_package/spec/upgrade_spec.rb +1 -1
  165. data/examples/solaris_package/spec/install_spec.rb +1 -1
  166. data/examples/solaris_package/spec/remove_spec.rb +1 -1
  167. data/examples/state_attrs/spec/default_spec.rb +2 -2
  168. data/examples/step_into/spec/default_spec.rb +5 -2
  169. data/examples/stub_command/spec/default_spec.rb +1 -1
  170. data/examples/stub_data_bag/spec/default_spec.rb +1 -1
  171. data/examples/stub_data_bag_item/spec/default_spec.rb +1 -1
  172. data/examples/stub_search/spec/default_spec.rb +1 -1
  173. data/examples/subscribes/spec/chained_spec.rb +1 -1
  174. data/examples/subscribes/spec/default_spec.rb +1 -1
  175. data/examples/subscribes/spec/delayed_spec.rb +1 -1
  176. data/examples/subscribes/spec/immediately_spec.rb +1 -1
  177. data/examples/subversion/spec/checkout_spec.rb +1 -1
  178. data/examples/subversion/spec/export_spec.rb +1 -1
  179. data/examples/subversion/spec/force_export_spec.rb +1 -1
  180. data/examples/subversion/spec/sync_spec.rb +1 -1
  181. data/examples/template/spec/create_if_missing_spec.rb +1 -1
  182. data/examples/template/spec/create_spec.rb +1 -1
  183. data/examples/template/spec/delete_spec.rb +1 -1
  184. data/examples/template/spec/touch_spec.rb +1 -1
  185. data/examples/use_inline_resources/spec/default_spec.rb +4 -1
  186. data/examples/user/spec/create_spec.rb +1 -1
  187. data/examples/user/spec/lock_spec.rb +1 -1
  188. data/examples/user/spec/manage_spec.rb +1 -1
  189. data/examples/user/spec/modify_spec.rb +1 -1
  190. data/examples/user/spec/remove_spec.rb +1 -1
  191. data/examples/user/spec/unlock_spec.rb +1 -1
  192. data/examples/yum_package/spec/install_spec.rb +1 -1
  193. data/examples/yum_package/spec/purge_spec.rb +1 -1
  194. data/examples/yum_package/spec/remove_spec.rb +1 -1
  195. data/examples/yum_package/spec/upgrade_spec.rb +1 -1
  196. data/features/batch.feature +0 -3
  197. data/features/powershell_script.feature +0 -3
  198. data/features/render_file.feature +1 -6
  199. data/features/server.feature +0 -3
  200. data/features/smartos_package.feature +0 -4
  201. data/features/solaris_package.feature +0 -4
  202. data/features/state_attrs.feature +0 -4
  203. data/features/support/env.rb +0 -7
  204. data/gemfiles/{chef-11.12.0.gemfile → chef-11.16.0.gemfile} +1 -1
  205. data/gemfiles/chef-12.0.0.alpha.gemfile +5 -0
  206. data/lib/chefspec.rb +46 -14
  207. data/lib/chefspec/api.rb +0 -2
  208. data/lib/chefspec/api/apt_package.rb +1 -1
  209. data/lib/chefspec/api/batch.rb +1 -1
  210. data/lib/chefspec/api/chef_gem.rb +1 -1
  211. data/lib/chefspec/api/cookbook_file.rb +1 -1
  212. data/lib/chefspec/api/cron.rb +1 -1
  213. data/lib/chefspec/api/deploy.rb +1 -1
  214. data/lib/chefspec/api/directory.rb +1 -1
  215. data/lib/chefspec/api/dpkg_package.rb +1 -1
  216. data/lib/chefspec/api/easy_install_package.rb +1 -1
  217. data/lib/chefspec/api/env.rb +1 -1
  218. data/lib/chefspec/api/erl_call.rb +1 -1
  219. data/lib/chefspec/api/execute.rb +1 -1
  220. data/lib/chefspec/api/file.rb +1 -1
  221. data/lib/chefspec/api/freebsd_package.rb +1 -1
  222. data/lib/chefspec/api/gem_package.rb +1 -1
  223. data/lib/chefspec/api/git.rb +1 -1
  224. data/lib/chefspec/api/group.rb +1 -1
  225. data/lib/chefspec/api/http_request.rb +1 -1
  226. data/lib/chefspec/api/ifconfig.rb +1 -1
  227. data/lib/chefspec/api/ips_package.rb +1 -1
  228. data/lib/chefspec/api/link.rb +1 -1
  229. data/lib/chefspec/api/log.rb +1 -1
  230. data/lib/chefspec/api/macports_package.rb +1 -1
  231. data/lib/chefspec/api/mdadm.rb +1 -1
  232. data/lib/chefspec/api/mount.rb +1 -1
  233. data/lib/chefspec/api/ohai.rb +2 -2
  234. data/lib/chefspec/api/package.rb +1 -1
  235. data/lib/chefspec/api/pacman_package.rb +1 -1
  236. data/lib/chefspec/api/portage_package.rb +1 -1
  237. data/lib/chefspec/api/powershell_script.rb +1 -1
  238. data/lib/chefspec/api/registry_key.rb +1 -1
  239. data/lib/chefspec/api/remote_directory.rb +4 -4
  240. data/lib/chefspec/api/remote_file.rb +1 -1
  241. data/lib/chefspec/api/route.rb +1 -1
  242. data/lib/chefspec/api/rpm_package.rb +1 -1
  243. data/lib/chefspec/api/ruby_block.rb +1 -1
  244. data/lib/chefspec/api/script.rb +6 -6
  245. data/lib/chefspec/api/service.rb +1 -1
  246. data/lib/chefspec/api/smartos_package.rb +1 -1
  247. data/lib/chefspec/api/solaris_package.rb +1 -1
  248. data/lib/chefspec/api/subversion.rb +1 -1
  249. data/lib/chefspec/api/template.rb +1 -1
  250. data/lib/chefspec/api/user.rb +1 -1
  251. data/lib/chefspec/api/yum_package.rb +1 -1
  252. data/lib/chefspec/coverage/filters.rb +3 -0
  253. data/lib/chefspec/deprecations.rb +19 -123
  254. data/lib/chefspec/macros.rb +2 -2
  255. data/lib/chefspec/matchers/render_file_matcher.rb +2 -2
  256. data/lib/chefspec/matchers/resource_matcher.rb +1 -1
  257. data/lib/chefspec/matchers/state_attrs_matcher.rb +1 -1
  258. data/lib/chefspec/server.rb +4 -361
  259. data/lib/chefspec/server_methods.rb +175 -0
  260. data/lib/chefspec/server_runner.rb +86 -0
  261. data/lib/chefspec/{runner.rb → solo_runner.rb} +92 -43
  262. data/lib/chefspec/version.rb +1 -1
  263. data/spec/unit/{runner_spec.rb → solo_runner_spec.rb} +31 -25
  264. metadata +13 -10
@@ -1,7 +1,7 @@
1
1
  module ChefSpec::API
2
2
  # @since 0.0.1
3
3
  module ServiceMatchers
4
- ChefSpec::Runner.define_runner_method :service
4
+ ChefSpec.define_matcher :service
5
5
 
6
6
  #
7
7
  # Assert that a +service+ resource exists in the Chef run with the
@@ -1,7 +1,7 @@
1
1
  module ChefSpec::API
2
2
  # @since 3.0.0
3
3
  module SmartosPackageMatchers
4
- ChefSpec::Runner.define_runner_method :smartos_package
4
+ ChefSpec.define_matcher :smartos_package
5
5
 
6
6
  #
7
7
  # Assert that a +smartos_package+ resource exists in the Chef run with the
@@ -1,7 +1,7 @@
1
1
  module ChefSpec::API
2
2
  # @since 3.0.0
3
3
  module SolarisPackageMatchers
4
- ChefSpec::Runner.define_runner_method :solaris_package
4
+ ChefSpec.define_matcher :solaris_package
5
5
 
6
6
  #
7
7
  # Assert that a +solaris_package+ resource exists in the Chef run with the
@@ -1,7 +1,7 @@
1
1
  module ChefSpec::API
2
2
  # @since 3.0.0
3
3
  module SubversionMatchers
4
- ChefSpec::Runner.define_runner_method :subversion
4
+ ChefSpec.define_matcher :subversion
5
5
 
6
6
  #
7
7
  # Assert that a +subversion+ resource exists in the Chef run with the
@@ -1,7 +1,7 @@
1
1
  module ChefSpec::API
2
2
  # @since 0.0.1
3
3
  module TemplateMatchers
4
- ChefSpec::Runner.define_runner_method :template
4
+ ChefSpec.define_matcher :template
5
5
 
6
6
  #
7
7
  # Assert that a +template+ resource exists in the Chef run with the
@@ -1,7 +1,7 @@
1
1
  module ChefSpec::API
2
2
  # @since 0.3.0
3
3
  module UserMatchers
4
- ChefSpec::Runner.define_runner_method :user
4
+ ChefSpec.define_matcher :user
5
5
 
6
6
  #
7
7
  # Assert that a +user+ resource exists in the Chef run with the
@@ -1,7 +1,7 @@
1
1
  module ChefSpec::API
2
2
  # @since 3.0.0
3
3
  module YumPackageMatchers
4
- ChefSpec::Runner.define_runner_method :yum_package
4
+ ChefSpec.define_matcher :yum_package
5
5
 
6
6
  #
7
7
  # Assert that a +yum_package+ resource exists in the Chef run with the
@@ -16,6 +16,7 @@ module ChefSpec
16
16
  #
17
17
  class RegexpFilter < Filter
18
18
  def matches?(resource)
19
+ return true if resource.source_line.nil?
19
20
  @filter =~ resource.source_line
20
21
  end
21
22
  end
@@ -39,6 +40,7 @@ module ChefSpec
39
40
  #
40
41
  class BlockFilter < Filter
41
42
  def matches?(resource)
43
+ return true if resource.source_line.nil?
42
44
  @filter.call(resource)
43
45
  end
44
46
  end
@@ -68,6 +70,7 @@ module ChefSpec
68
70
  end
69
71
 
70
72
  def matches?(resource)
73
+ return true if resource.source_line.nil?
71
74
  resource.source_line =~ /cookbooks\/(?!#{@metadatas.join('|')})/
72
75
  end
73
76
  end
@@ -14,141 +14,37 @@ module Kernel
14
14
  end
15
15
  end
16
16
 
17
- module ChefSpec
18
- # @deprecated {ChefSpec::ChefRunner} is deprecated. Please use
19
- # {ChefSpec::Runner} instead.
20
- class ChefRunner
21
- def self.new(*args, &block)
22
- deprecated '`ChefSpec::ChefRunner` is deprecated. Please use' \
23
- ' `ChefSpec::Runner` instead.'
24
-
25
- ChefSpec::Runner.new(*args, &block)
26
- end
27
- end
28
- end
29
-
30
17
  module ChefSpec
31
18
  class Runner
32
- alias_method :existing_initialize, :initialize
33
- def initialize(*args, &block)
34
- if args.first.is_a?(Hash)
35
- if args.first.has_key?(:evaluate_guards)
36
- deprecated 'The `:evaluate_guards` option is deprecated. Guards are' \
37
- ' automatically evaluated by default. Please use `stub_command` to' \
38
- ' stub shell guards.'
39
- end
40
-
41
- if args.first.has_key?(:actually_run_shell_guards)
42
- deprecated 'The `:actually_run_shell_guards` option is deprecated.' \
43
- ' Shell commands must be stubbed using `stub_command`.'
44
- end
45
- end
46
-
47
- existing_initialize(*args, &block)
48
- end
49
- end
50
- end
51
-
52
- module ChefSpec::API
53
- #
54
- # @todo Remove in v4.0.0
55
- #
56
- module DeprecatedMatchers
57
- def be_owned_by(user, group)
58
- deprecated "The `be_owned_by` matcher is deprecated. Please use:" \
59
- "\n\n" \
60
- " expect(resource.owner).to eq('#{user}')\n" \
61
- " expect(resource.group).to eq('#{group}')" \
62
- "\n\n" \
63
- "instead"
64
- raise ChefSpec::NoConversionError.new('be_owned_by')
65
- end
19
+ # @deprecated {ChefSpec.define_runner_method} is deprecated. Please
20
+ # use {ChefSpec.define_runner_method} instead.
21
+ def self.define_runner_method(resource_name)
22
+ deprecated "`ChefSpec.define_runner_method' is deprecated. " \
23
+ "Please use `ChefSpec.define_runner_method' instead."
66
24
 
67
- def create_file_with_content(path, content)
68
- deprecated "The `create_file_with_content` matcher is deprecated." \
69
- " Please use `render_file(#{path.inspect})" \
70
- ".with_content(#{content.inspect})` instead."
71
- ChefSpec::Matchers::RenderFileMatcher.new(path).with_content(content)
25
+ ChefSpec.define_matcher(resource_name)
72
26
  end
73
27
 
74
- [:package, :yum_package, :gem_package, :chef_gem].each do |type|
75
- matcher_name = "install_#{type}_at_version".to_sym
76
- define_method(matcher_name) do |name, version|
77
- deprecated "The `#{matcher_name}` matcher is deprecated." \
78
- " Please use `install_package(#{name.inspect})" \
79
- ".with(version: #{version.inspect})` instead."
80
- ChefSpec::Matchers::ResourceMatcher.new(type, :install, package)
81
- .with(version: version)
82
- end
83
- end
84
-
85
- [:bash, :csh, :perl, :python, :ruby, :script].each do |type|
86
- matcher_name = "execute_#{type}_script".to_sym
87
- define_method(matcher_name) do |name|
88
- deprecated "The `#{matcher_name}` matcher is deprecated." \
89
- " Please use `run_#{type}(#{name.inspect})` instead."
90
- ChefSpec::Matchers::ResourceMatcher.new(type, :run, name)
91
- end
92
- end
93
-
94
- def log(message)
95
- deprecated "The `log` matcher is deprcated. Please use" \
96
- " `write_log(#{message.inspect}) instead."
97
- ChefSpec::Matchers::ResourceMatcher.new(:log, :write, message)
98
- end
99
-
100
- def set_service_to_start_on_boot(service)
101
- deprecated "The `set_service_to_start_on_boot` matcher is" \
102
- " deprecated. Please use `enable_service(#{service.inspect})`" \
103
- " instead."
104
- ChefSpec::Matchers::ResourceMatcher.new(:service, :enable, service)
105
- end
106
-
107
- def set_service_to_not_start_on_boot(service)
108
- deprecated "The `set_service_to_not_start_on_boot` matcher is" \
109
- " deprecated. Please use `enable_service(#{service.inspect})`" \
110
- " with a negating argument instead."
111
- raise ChefSpec::NoConversionError.new('set_service_to_start_on_boot')
112
- end
113
-
114
- def execute_ruby_block(name)
115
- deprecated "The `execute_ruby_block` matcher is deprecated. Please" \
116
- " use `run_ruby_block(#{name.inspect})` instead."
117
- ChefSpec::Matchers::ResourceMatcher.new(:ruby_block, :run, name)
118
- end
28
+ # @deprecated {ChefSpec::Runner.new} is deprecated. Please use
29
+ # {ChefSpec::SoloRunner} or {ChefSpec::ServerRunner} instead.
30
+ def self.new(*args, &block)
31
+ deprecated "`ChefSpec::Runner' is deprecated. Please use" \
32
+ " `ChefSpec::SoloRunner' or `ChefSpec::ServerRunner' instead."
119
33
 
120
- def execute_command(command)
121
- deprecated "The `execute_command` matcher is deprecated. Please" \
122
- " use `run_execute(#{command.inspect})` instead."
123
- ChefSpec::Matchers::ResourceMatcher.new(:execute, :run, command)
34
+ ChefSpec::SoloRuner.new(*args, &block)
124
35
  end
125
36
  end
126
- end
127
37
 
128
- module ChefSpec::API
129
- module NotificationsMatchers
130
- alias_method :new_notify, :notify
131
- def notify(resource, action = nil)
132
- if action
133
- deprecated "The `notify` matcher arity has changed. Please use" \
134
- " `notify(#{resource.inspect}).to(#{action.to_sym.inspect})`" \
135
- " instead."
136
- new_notify(resource).to(action.to_sym)
137
- else
138
- new_notify(resource)
139
- end
38
+ class Server
39
+ def self.method_missing(m, *args, &block)
40
+ deprecated "`ChefSpec::Server.#{m}' is deprecated. There is no longer" \
41
+ " a global Chef Server instance. Please use a ChefSpec::ServerRunner" \
42
+ " instead. More documentation can be found in the ChefSpec README."
43
+ raise NoConversionError
140
44
  end
141
45
  end
142
46
  end
143
47
 
144
48
  module ChefSpec::Error
145
- class NoConversionError < ChefSpecError
146
- def initialize(matcher)
147
- message = "I cannot convert `#{matcher}` to use a new matcher format!" \
148
- " Please see the ChefSpec documentation and CHANGELOG for details" \
149
- " on converting this matcher. Sorry :("
150
-
151
- super(message)
152
- end
153
- end
49
+ class NoConversionError < ChefSpecError; end
154
50
  end
@@ -34,8 +34,8 @@ module ChefSpec
34
34
  #
35
35
  # The value of +described_recipe+ is "my_cookbook::my_recipe".
36
36
  #
37
- # @example Using +described_recipe+ in the +ChefSpec::Runner+
38
- # let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) }
37
+ # @example Using +described_recipe+ in the +ChefSpec::SoloRunner+
38
+ # let(:chef_run) { ChefSpec::SoloRunner.new.converge(described_recipe) }
39
39
  #
40
40
  #
41
41
  # @return [String]
@@ -80,7 +80,7 @@ module ChefSpec::Matchers
80
80
  #
81
81
  # @param [Chef::Resource] resource
82
82
  #
83
- # @return [Boolean]
83
+ # @return [true, false]
84
84
  #
85
85
  def has_create_action?
86
86
  [:create, :create_if_missing].any? { |action| resource.performed_action?(action) }
@@ -91,7 +91,7 @@ module ChefSpec::Matchers
91
91
  #
92
92
  # @param [Chef::Resource] resource
93
93
  #
94
- # @return [Boolean]
94
+ # @return [true, false]
95
95
  #
96
96
  def matches_content?
97
97
  return true if @expected_content.nil?
@@ -153,7 +153,7 @@ module ChefSpec::Matchers
153
153
  # Find the resource in the Chef run by the given class name and
154
154
  # resource identity/name.
155
155
  #
156
- # @see ChefSpec::Runner#find_resource
156
+ # @see ChefSpec::SoloRunner#find_resource
157
157
  #
158
158
  # @return [Chef::Resource, nil]
159
159
  #
@@ -53,7 +53,7 @@ module ChefSpec::Matchers
53
53
  # Determine if all the expected state attributes are present on the
54
54
  # given resource.
55
55
  #
56
- # @return [Boolean]
56
+ # @return [true, false]
57
57
  #
58
58
  def matches_state_attrs?
59
59
  @expected_attrs == state_attrs
@@ -1,361 +1,4 @@
1
- begin
2
- require 'chef_zero/server'
3
- rescue LoadError
4
- raise ChefSpec::Error::GemLoadError.new(gem: 'chef-zero', name: 'Chef Zero')
5
- end
6
-
7
- require 'chef/cookbook_loader'
8
- require 'chef/cookbook_uploader'
9
-
10
- class Chef::CookbookUploader
11
- #
12
- # Don't validate uploaded cookbooks. Validating a cookbook takes *forever*
13
- # to complete. It's just not worth it...
14
- #
15
- def validate_cookbooks
16
- # noop
17
- end
18
- end
19
-
20
- class ChefSpec::Runner
21
- alias_method :old_initialize, :initialize
22
-
23
- #
24
- # Override the existing initialize method, setting the appropriate
25
- # configuration to use a real Chef Server instead.
26
- #
27
- # @see ChefSpec::Runner#initialize
28
- #
29
- def initialize(options = {}, &block)
30
- old_initialize(options, &block)
31
-
32
- Chef::Config[:client_key] = ChefSpec::Server.client_key
33
- Chef::Config[:client_name] = 'chefspec'
34
- Chef::Config[:node_name] = 'chefspec'
35
- Chef::Config[:file_cache_path] = Dir.mktmpdir
36
- Chef::Config[:solo] = false
37
-
38
- upload_cookbooks!
39
- end
40
-
41
- private
42
-
43
- #
44
- # Upload the cookbooks to the Chef Server.
45
- #
46
- def upload_cookbooks!
47
- loader = Chef::CookbookLoader.new(Chef::Config[:cookbook_path])
48
- loader.load_cookbooks
49
-
50
- uploader = Chef::CookbookUploader.new(loader.cookbooks, loader.cookbook_paths)
51
- uploader.upload_cookbooks
52
- end
53
- end
54
-
55
- module ChefSpec
56
- class Server
57
- #
58
- # Delegate all methods to the singleton instance.
59
- #
60
- def self.method_missing(m, *args, &block)
61
- instance.send(m, *args, &block)
62
- end
63
-
64
- #
65
- # RSpec 3 checks +respond_to?+ for some odd reason.
66
- #
67
- def self.respond_to_missing?(m, include_private = false)
68
- instance.respond_to?(m, include_private) || super
69
- end
70
-
71
- #
72
- # @macro entity
73
- # @method create_$1(name, data = {})
74
- # Create a new $1 on the Chef Server
75
- #
76
- # @param [String] name
77
- # the name of the $1
78
- # @param [Hash] data
79
- # the list of data to load
80
- #
81
- #
82
- # @method $1(name)
83
- # Find a $1 at the given name
84
- #
85
- # @param [String] name
86
- # the name of the $1
87
- #
88
- # @return [$2, nil]
89
- #
90
- #
91
- # @method $3
92
- # The list of $1 on the Chef Server
93
- #
94
- # @return [Array<Hash>]
95
- # all the $1 on the Chef Server
96
- #
97
- #
98
- # @method has_$1?(name)
99
- # Determine if the Chef Server has the given $1
100
- #
101
- # @param [String] name
102
- # the name of the $1 to find
103
- #
104
- # @return [Boolean]
105
- #
106
- def self.entity(method, klass, key)
107
- class_eval <<-EOH, __FILE__, __LINE__ + 1
108
- def create_#{method}(name, data = {})
109
- # Automatically set the "name" if no explicit one was given
110
- data[:name] ||= name
111
-
112
- # Convert it to JSON
113
- data = JSON.fast_generate(data)
114
-
115
- load_data(name, '#{key}', data)
116
- end
117
-
118
- def #{method}(name)
119
- data = get('#{key}', name)
120
- json = JSON.parse(data)
121
-
122
- if #{klass}.respond_to?(:json_create)
123
- #{klass}.json_create(json)
124
- else
125
- #{klass}.new(json)
126
- end
127
- rescue ChefZero::DataStore::DataNotFoundError
128
- nil
129
- end
130
-
131
- def #{key}
132
- get('#{key}')
133
- end
134
-
135
- def has_#{method}?(name)
136
- !get('#{key}', name).nil?
137
- rescue ChefZero::DataStore::DataNotFoundError
138
- false
139
- end
140
- EOH
141
- end
142
-
143
- entity :client, Chef::Client, 'clients'
144
- entity :data_bag, Chef::DataBag, 'data'
145
- entity :environment, Chef::Environment, 'environments'
146
- entity :node, Chef::Node, 'nodes'
147
- entity :role, Chef::Role, 'roles'
148
-
149
- include Singleton
150
-
151
- attr_reader :server
152
-
153
- #
154
- # Create a new instance of the +ChefSpec::Server+ singleton. This method
155
- # also starts the Chef Zero server in the background.
156
- #
157
- def initialize
158
- @server = ChefZero::Server.new(
159
- # Set the log level from RSpec, defaulting to warn
160
- log_level: RSpec.configuration.log_level || :warn,
161
-
162
- # Set a random port so ChefSpec may be run in multiple jobs
163
- port: port,
164
- )
165
- end
166
-
167
- #
168
- # Create a new data_bag on the Chef Server. This overrides the method
169
- # created by {entity}
170
- #
171
- # @param [String] name
172
- # the name of the data bag
173
- # @param [Hash] data
174
- # the data to load into the data bag
175
- #
176
- def create_data_bag(name, data = {})
177
- load_data(name, 'data', data)
178
- end
179
-
180
- #
181
- # Create a new node on the Chef Server. This overrides the method created
182
- # by {entity}, permitting users to pass a raw +Chef::Node+ object in
183
- # addition to a hash.
184
- #
185
- # @example Create a node from a hash
186
- #
187
- # create_node('bacon', attribute: 'value')
188
- #
189
- # @example Create a node from a +Chef::Node+ object
190
- #
191
- # node = stub_node('bacon', platform: 'ubuntu', version: '12.04')
192
- # create_node(node)
193
- #
194
- # @param [String, Chef::Node] object
195
- # the object to create; this can be the name of the node, or an actual
196
- # +Chef::Node+ object
197
- # @param [Hash] data
198
- # the list of data to populate the node with; this is ignored if an
199
- # actual node object is given
200
- #
201
- def create_node(object, data = {})
202
- if object.is_a?(Chef::Node)
203
- name = object.name
204
- data = object.to_json
205
- else
206
- name = object.to_s
207
- data[:name] ||= name
208
- data = JSON.fast_generate(data)
209
- end
210
-
211
- load_data(name, 'nodes', data)
212
- end
213
-
214
- #
215
- # The path to the insecure Chef Zero private key on disk. Because Chef
216
- # requires the path to a file instead of the contents of the key (why),
217
- # this method dynamically writes the +ChefZero::PRIVATE_KEY+ to disk and
218
- # then returns that path.
219
- #
220
- # @return [String]
221
- # the path to the client key on disk
222
- #
223
- def client_key
224
- @client_key ||= begin
225
- path = File.join(cache_dir, 'client.pem')
226
- File.open(path, 'w') { |f| f.write(ChefZero::PRIVATE_KEY) }
227
- path
228
- end
229
- end
230
-
231
- #
232
- # The URL where ChefZero is listening.
233
- #
234
- # @return [String]
235
- #
236
- def chef_server_url
237
- @chef_server_url ||= File.join(@server.url)
238
- end
239
-
240
- #
241
- # Start the Chef Zero server in the background, updating the +Chef::Config+
242
- # with the proper +chef_server_url+.
243
- #
244
- def start!
245
- unless @server.running?
246
- @server.start_background
247
- Chef::Config[:chef_server_url] = chef_server_url
248
- end
249
- end
250
-
251
- #
252
- # Clear the contents of the server (used between examples)
253
- #
254
- def reset!
255
- @server.clear_data
256
- end
257
-
258
- #
259
- # Stop the Chef Zero server, if it is running. This method also runs any
260
- # cleanup hooks, such as clearing the cache directories.
261
- #
262
- def stop!
263
- @server.stop if @server.running?
264
- FileUtils.rm_rf(cache_dir)
265
- end
266
-
267
- private
268
-
269
- #
270
- # The directory where any cache information (such as private keys) should
271
- # be stored. This cache is destroyed at the end of the run.
272
- #
273
- # @return [String]
274
- # the path to the cache directory on disk
275
- #
276
- def cache_dir
277
- @cache_dir ||= Dir.mktmpdir(['chefspec', 'cache'])
278
- end
279
-
280
- #
281
- # Shortcut method for loading data into Chef Zero.
282
- #
283
- # @param [String] name
284
- # the name or id of the item to load
285
- # @param [String, Symbol] key
286
- # the key to load
287
- # @param [Hash] data
288
- # the data for the object, which will be converted to JSON and uploaded
289
- # to the server
290
- #
291
- def load_data(name, key, data = {})
292
- @server.load_data({ key => { name => data } })
293
- end
294
-
295
- #
296
- # Get the path to an item in the data store.
297
- #
298
- def get(*args)
299
- # This is a real-life "what in the actual fuck!?". Since some engineers
300
- # cannot seem to understand the importance of an unchanging public API,
301
- # we have to implement crazy, outlandish checks like this.
302
- #
303
- # In the 2.0 series of Chef Zero, the DataStore did not prefix values.
304
- # In the 2.1+ series, DataStore values are nested under
305
- # +organizations/chef+, for some ridiciously reason.
306
- #
307
- # Oh, and for the record, there was no CHANGELOG entry or anything. They
308
- # just decided it would be a good idea to change one of the main APIs in
309
- # the system.
310
- if ChefZero::VERSION.to_f == 2.0
311
- get_without_prefix(*args)
312
- else
313
- get_with_prefix(*args)
314
- end
315
- end
316
-
317
- # @see {get}
318
- def get_without_prefix(*args)
319
- if args.size == 1
320
- @server.data_store.list(args)
321
- else
322
- @server.data_store.get(args)
323
- end
324
- end
325
-
326
- # @see {get}
327
- def get_with_prefix(*args)
328
- args.unshift('organizations', 'chef')
329
-
330
- if args.size == 3
331
- @server.data_store.list(args)
332
- else
333
- @server.data_store.get(args)
334
- end
335
- end
336
-
337
- #
338
- # A randomly assigned, open port for run the Chef Zero server.
339
- #
340
- # @return [Fixnum]
341
- #
342
- def port
343
- return @port if @port
344
-
345
- @server = TCPServer.new('127.0.0.1', 0)
346
- @port = @server.addr[1].to_i
347
- @server.close
348
-
349
- return @port
350
- end
351
- end
352
- end
353
-
354
- ChefSpec::Server.start!
355
-
356
- RSpec.configure do |config|
357
- config.before(:each) { ChefSpec::Server.reset! }
358
- config.after(:each) { ChefSpec::Server.reset! }
359
- end
360
-
361
- at_exit { ChefSpec::Server.stop! }
1
+ # @todo Remove in v5.0.0
2
+ require_relative 'deprecations'
3
+ deprecated "require 'chefspec/server' is no longer required and " \
4
+ "will be removed in the next major release."