chef 11.18.12 → 12.0.0.alpha.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (307) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +10 -0
  3. data/README.md +1 -1
  4. data/distro/common/html/_sources/index.txt +5 -2
  5. data/distro/common/html/_sources/knife_serve.txt +19 -0
  6. data/distro/common/html/_sources/knife_ssl_check.txt +2 -2
  7. data/distro/common/html/_sources/knife_ssl_fetch.txt +2 -2
  8. data/distro/common/html/_static/basic.css +1 -1
  9. data/distro/common/html/_static/doctools.js +1 -1
  10. data/distro/common/html/_static/searchtools.js +1 -1
  11. data/distro/common/html/_static/websupport.js +1 -1
  12. data/distro/common/html/ctl_chef_client.html +19 -9
  13. data/distro/common/html/ctl_chef_server.html +7 -1
  14. data/distro/common/html/ctl_chef_shell.html +3 -4
  15. data/distro/common/html/ctl_chef_solo.html +12 -7
  16. data/distro/common/html/index.html +19 -12
  17. data/distro/common/html/knife.html +1 -2
  18. data/distro/common/html/knife_bootstrap.html +16 -5
  19. data/distro/common/html/knife_client.html +8 -5
  20. data/distro/common/html/knife_common_options.html +11 -12
  21. data/distro/common/html/knife_configure.html +2 -3
  22. data/distro/common/html/knife_cookbook.html +16 -17
  23. data/distro/common/html/knife_cookbook_site.html +19 -18
  24. data/distro/common/html/knife_data_bag.html +6 -7
  25. data/distro/common/html/knife_delete.html +2 -3
  26. data/distro/common/html/knife_deps.html +2 -3
  27. data/distro/common/html/knife_diff.html +3 -4
  28. data/distro/common/html/knife_download.html +6 -7
  29. data/distro/common/html/knife_edit.html +0 -1
  30. data/distro/common/html/knife_environment.html +3 -4
  31. data/distro/common/html/knife_exec.html +0 -1
  32. data/distro/common/html/knife_index_rebuild.html +0 -1
  33. data/distro/common/html/knife_list.html +5 -6
  34. data/distro/common/html/knife_node.html +13 -6
  35. data/distro/common/html/knife_raw.html +0 -1
  36. data/distro/common/html/knife_recipe_list.html +0 -1
  37. data/distro/common/html/knife_role.html +1 -2
  38. data/distro/common/html/knife_search.html +2 -3
  39. data/distro/common/html/knife_serve.html +79 -0
  40. data/distro/common/html/knife_show.html +1 -2
  41. data/distro/common/html/knife_ssh.html +2 -3
  42. data/distro/common/html/knife_ssl_check.html +12 -9
  43. data/distro/common/html/knife_ssl_fetch.html +9 -10
  44. data/distro/common/html/knife_status.html +2 -3
  45. data/distro/common/html/knife_tag.html +0 -1
  46. data/distro/common/html/knife_upload.html +3 -4
  47. data/distro/common/html/knife_user.html +2 -3
  48. data/distro/common/html/knife_using.html +0 -1
  49. data/distro/common/html/knife_xargs.html +3 -4
  50. data/distro/common/html/search.html +0 -1
  51. data/distro/common/html/searchindex.js +1 -1
  52. data/lib/chef/api_client.rb +1 -1
  53. data/lib/chef/application.rb +24 -67
  54. data/lib/chef/application/client.rb +1 -1
  55. data/lib/chef/application/knife.rb +1 -1
  56. data/lib/chef/chef_fs/chef_fs_data_store.rb +2 -3
  57. data/lib/chef/chef_fs/command_line.rb +2 -3
  58. data/lib/chef/chef_fs/data_handler/group_data_handler.rb +1 -5
  59. data/lib/chef/chef_fs/file_system/acl_entry.rb +1 -2
  60. data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +1 -2
  61. data/lib/chef/chef_fs/file_system/cookbooks_dir.rb +2 -2
  62. data/lib/chef/chef_fs/file_system/rest_list_dir.rb +2 -3
  63. data/lib/chef/chef_fs/file_system/rest_list_entry.rb +4 -5
  64. data/lib/chef/config.rb +26 -2
  65. data/lib/chef/config_fetcher.rb +1 -1
  66. data/lib/chef/cookbook/cookbook_version_loader.rb +4 -4
  67. data/lib/chef/cookbook/metadata.rb +1 -1
  68. data/lib/chef/cookbook/synchronizer.rb +50 -8
  69. data/lib/chef/cookbook_uploader.rb +9 -23
  70. data/lib/chef/cookbook_version.rb +3 -2
  71. data/lib/chef/data_bag.rb +1 -1
  72. data/lib/chef/data_bag_item.rb +1 -1
  73. data/lib/chef/dsl/recipe.rb +1 -14
  74. data/lib/chef/encrypted_data_bag_item/decryptor.rb +3 -3
  75. data/lib/chef/environment.rb +1 -1
  76. data/lib/chef/exceptions.rb +2 -24
  77. data/lib/chef/file_content_management/tempfile.rb +8 -1
  78. data/lib/chef/formatters/base.rb +0 -7
  79. data/lib/chef/http.rb +12 -19
  80. data/lib/chef/http/json_input.rb +12 -1
  81. data/lib/chef/json_compat.rb +45 -64
  82. data/lib/chef/knife.rb +2 -5
  83. data/lib/chef/knife/bootstrap.rb +2 -2
  84. data/lib/chef/knife/bootstrap/archlinux-gems.erb +2 -2
  85. data/lib/chef/knife/bootstrap/centos5-gems.erb +2 -2
  86. data/lib/chef/knife/bootstrap/chef-aix.erb +2 -2
  87. data/lib/chef/knife/bootstrap/chef-full.erb +2 -2
  88. data/lib/chef/knife/bootstrap/fedora13-gems.erb +2 -2
  89. data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +2 -2
  90. data/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb +2 -2
  91. data/lib/chef/knife/bootstrap/ubuntu12.04-gems.erb +2 -2
  92. data/lib/chef/knife/cookbook_site_download.rb +1 -1
  93. data/lib/chef/knife/cookbook_site_install.rb +10 -34
  94. data/lib/chef/knife/cookbook_site_list.rb +1 -1
  95. data/lib/chef/knife/cookbook_site_search.rb +1 -1
  96. data/lib/chef/knife/cookbook_site_share.rb +3 -3
  97. data/lib/chef/knife/cookbook_site_show.rb +3 -3
  98. data/lib/chef/knife/cookbook_site_unshare.rb +1 -1
  99. data/lib/chef/knife/cookbook_upload.rb +1 -1
  100. data/lib/chef/knife/core/subcommand_loader.rb +0 -24
  101. data/lib/chef/knife/core/ui.rb +8 -7
  102. data/lib/chef/knife/deps.rb +2 -3
  103. data/lib/chef/knife/serve.rb +2 -1
  104. data/lib/chef/local_mode.rb +105 -0
  105. data/lib/chef/mixin/file_class.rb +1 -4
  106. data/lib/chef/mixin/shell_out.rb +15 -0
  107. data/lib/chef/mixin/windows_architecture_helper.rb +0 -16
  108. data/lib/chef/node.rb +1 -1
  109. data/lib/chef/platform/query_helpers.rb +1 -5
  110. data/lib/chef/policy_builder/expand_node_object.rb +3 -0
  111. data/lib/chef/provider.rb +2 -0
  112. data/lib/chef/provider/cookbook_file.rb +0 -1
  113. data/lib/chef/provider/deploy.rb +0 -1
  114. data/lib/chef/provider/deploy/revision.rb +1 -1
  115. data/lib/chef/provider/env.rb +10 -25
  116. data/lib/chef/provider/env/windows.rb +23 -10
  117. data/lib/chef/provider/execute.rb +0 -3
  118. data/lib/chef/provider/file.rb +0 -3
  119. data/lib/chef/provider/git.rb +0 -6
  120. data/lib/chef/provider/group/dscl.rb +9 -27
  121. data/lib/chef/provider/group/gpasswd.rb +0 -3
  122. data/lib/chef/provider/group/groupmod.rb +0 -4
  123. data/lib/chef/provider/group/suse.rb +0 -3
  124. data/lib/chef/provider/group/usermod.rb +0 -3
  125. data/lib/chef/provider/link.rb +22 -5
  126. data/lib/chef/provider/log.rb +15 -4
  127. data/lib/chef/provider/mdadm.rb +0 -3
  128. data/lib/chef/provider/mount/mount.rb +0 -2
  129. data/lib/chef/provider/mount/solaris.rb +0 -2
  130. data/lib/chef/provider/package.rb +0 -1
  131. data/lib/chef/provider/package/apt.rb +0 -3
  132. data/lib/chef/provider/package/dpkg.rb +0 -1
  133. data/lib/chef/provider/package/easy_install.rb +0 -4
  134. data/lib/chef/provider/package/freebsd/base.rb +0 -3
  135. data/lib/chef/provider/package/freebsd/pkgng.rb +0 -2
  136. data/lib/chef/provider/package/freebsd/port.rb +0 -2
  137. data/lib/chef/provider/package/ips.rb +0 -3
  138. data/lib/chef/provider/package/paludis.rb +0 -5
  139. data/lib/chef/provider/package/portage.rb +0 -2
  140. data/lib/chef/provider/package/rpm.rb +2 -4
  141. data/lib/chef/provider/package/rubygems.rb +0 -4
  142. data/lib/chef/provider/package/smartos.rb +0 -3
  143. data/lib/chef/provider/package/windows/msi.rb +0 -2
  144. data/lib/chef/provider/package/yum.rb +0 -4
  145. data/lib/chef/provider/package/zypper.rb +0 -3
  146. data/lib/chef/provider/registry_key.rb +0 -2
  147. data/lib/chef/provider/remote_directory.rb +0 -1
  148. data/lib/chef/provider/remote_file.rb +0 -1
  149. data/lib/chef/provider/remote_file/cache_control_data.rb +1 -3
  150. data/lib/chef/provider/remote_file/content.rb +0 -1
  151. data/lib/chef/provider/remote_file/fetcher.rb +0 -2
  152. data/lib/chef/provider/remote_file/ftp.rb +0 -1
  153. data/lib/chef/provider/resource_update.rb +0 -3
  154. data/lib/chef/provider/service/freebsd.rb +0 -3
  155. data/lib/chef/provider/service/init.rb +0 -3
  156. data/lib/chef/provider/service/macosx.rb +0 -1
  157. data/lib/chef/provider/service/redhat.rb +0 -2
  158. data/lib/chef/provider/service/simple.rb +0 -3
  159. data/lib/chef/provider/service/solaris.rb +0 -3
  160. data/lib/chef/provider/service/systemd.rb +15 -14
  161. data/lib/chef/provider/service/windows.rb +0 -3
  162. data/lib/chef/provider/subversion.rb +0 -2
  163. data/lib/chef/provider/template.rb +0 -2
  164. data/lib/chef/provider/template/content.rb +0 -1
  165. data/lib/chef/provider/user/dscl.rb +156 -549
  166. data/lib/chef/provider/user/solaris.rb +0 -1
  167. data/lib/chef/provider/user/useradd.rb +0 -3
  168. data/lib/chef/provider/whyrun_safe_ruby_block.rb +1 -1
  169. data/lib/chef/providers.rb +0 -1
  170. data/lib/chef/resource.rb +1 -4
  171. data/lib/chef/resource/freebsd_package.rb +2 -10
  172. data/lib/chef/resource/lwrp_base.rb +1 -12
  173. data/lib/chef/resource/user.rb +0 -18
  174. data/lib/chef/resource_collection.rb +1 -1
  175. data/lib/chef/resource_reporter.rb +10 -10
  176. data/lib/chef/resources.rb +0 -1
  177. data/lib/chef/role.rb +3 -3
  178. data/lib/chef/run_list.rb +1 -1
  179. data/lib/chef/tasks/chef_repo.rake +131 -264
  180. data/lib/chef/user.rb +1 -1
  181. data/lib/chef/util/path_helper.rb +2 -2
  182. data/lib/chef/version.rb +9 -1
  183. data/lib/chef/win32/api/system.rb +0 -9
  184. data/spec/data/bootstrap/test-hints.erb +1 -1
  185. data/spec/data/bootstrap/test.erb +1 -1
  186. data/spec/functional/dsl/reboot_pending_spec.rb +53 -58
  187. data/spec/functional/knife/cookbook_delete_spec.rb +3 -3
  188. data/spec/functional/knife/exec_spec.rb +1 -1
  189. data/spec/functional/mixin/shell_out_spec.rb +48 -0
  190. data/spec/functional/resource/base.rb +0 -10
  191. data/spec/functional/resource/group_spec.rb +1 -5
  192. data/spec/functional/resource/link_spec.rb +8 -0
  193. data/spec/functional/resource/{user/useradd_spec.rb → user_spec.rb} +1 -1
  194. data/spec/integration/knife/chef_fs_data_store_spec.rb +3 -3
  195. data/spec/integration/knife/chef_repo_path_spec.rb +1 -6
  196. data/spec/integration/knife/chef_repository_file_system_spec.rb +1 -1
  197. data/spec/integration/knife/chefignore_spec.rb +1 -1
  198. data/spec/integration/knife/common_options_spec.rb +50 -3
  199. data/spec/integration/knife/cookbook_api_ipv6_spec.rb +1 -1
  200. data/spec/integration/knife/delete_spec.rb +1 -1
  201. data/spec/integration/knife/deps_spec.rb +1 -1
  202. data/spec/integration/knife/diff_spec.rb +3 -3
  203. data/spec/integration/knife/download_spec.rb +3 -3
  204. data/spec/integration/knife/list_spec.rb +1 -1
  205. data/spec/integration/knife/raw_spec.rb +1 -11
  206. data/spec/integration/knife/redirection_spec.rb +1 -1
  207. data/spec/integration/knife/serve_spec.rb +2 -2
  208. data/spec/integration/knife/show_spec.rb +1 -1
  209. data/spec/integration/knife/upload_spec.rb +9 -9
  210. data/spec/spec_helper.rb +0 -9
  211. data/spec/support/pedant/pedant_config.rb +2 -1
  212. data/spec/support/pedant/run_pedant.rb +2 -1
  213. data/spec/support/platform_helpers.rb +5 -24
  214. data/spec/support/shared/integration/integration_helper.rb +2 -1
  215. data/spec/support/shared/matchers.rb +17 -0
  216. data/spec/tiny_server.rb +1 -2
  217. data/spec/unit/api_client_spec.rb +3 -3
  218. data/spec/unit/application_spec.rb +9 -32
  219. data/spec/unit/config_fetcher_spec.rb +1 -1
  220. data/spec/unit/cookbook/metadata_spec.rb +3 -7
  221. data/spec/unit/cookbook/synchronizer_spec.rb +441 -226
  222. data/spec/unit/cookbook_loader_spec.rb +1 -1
  223. data/spec/unit/cookbook_uploader_spec.rb +160 -0
  224. data/spec/unit/cookbook_version_spec.rb +0 -4
  225. data/spec/unit/data_bag_item_spec.rb +1 -5
  226. data/spec/unit/data_bag_spec.rb +1 -5
  227. data/spec/unit/deprecation_spec.rb +1 -1
  228. data/spec/unit/dsl/recipe_spec.rb +12 -0
  229. data/spec/unit/encrypted_data_bag_item_spec.rb +7 -14
  230. data/spec/unit/environment_spec.rb +3 -7
  231. data/spec/unit/exceptions_spec.rb +0 -6
  232. data/spec/unit/http/json_input_spec.rb +128 -0
  233. data/spec/unit/json_compat_spec.rb +17 -58
  234. data/spec/unit/knife/client_create_spec.rb +3 -3
  235. data/spec/unit/knife/configure_client_spec.rb +6 -5
  236. data/spec/unit/knife/cookbook_delete_spec.rb +1 -1
  237. data/spec/unit/knife/cookbook_download_spec.rb +5 -5
  238. data/spec/unit/knife/cookbook_metadata_from_file_spec.rb +1 -0
  239. data/spec/unit/knife/cookbook_metadata_spec.rb +1 -1
  240. data/spec/unit/knife/cookbook_site_download_spec.rb +10 -11
  241. data/spec/unit/knife/cookbook_site_install_spec.rb +116 -161
  242. data/spec/unit/knife/cookbook_site_share_spec.rb +8 -8
  243. data/spec/unit/knife/cookbook_upload_spec.rb +3 -2
  244. data/spec/unit/knife/core/bootstrap_context_spec.rb +3 -3
  245. data/spec/unit/knife/core/subcommand_loader_spec.rb +1 -66
  246. data/spec/unit/knife/data_bag_from_file_spec.rb +2 -1
  247. data/spec/unit/knife/tag_create_spec.rb +3 -3
  248. data/spec/unit/knife/tag_delete_spec.rb +3 -3
  249. data/spec/unit/knife/user_create_spec.rb +1 -1
  250. data/spec/unit/knife_spec.rb +14 -14
  251. data/spec/unit/lwrp_spec.rb +1 -21
  252. data/spec/unit/mixin/shell_out_spec.rb +92 -0
  253. data/spec/unit/node_spec.rb +0 -4
  254. data/spec/unit/platform/query_helpers_spec.rb +0 -23
  255. data/spec/unit/provider/env/windows_spec.rb +34 -70
  256. data/spec/unit/provider/env_spec.rb +11 -76
  257. data/spec/unit/provider/group/dscl_spec.rb +1 -38
  258. data/spec/unit/provider/log_spec.rb +18 -0
  259. data/spec/unit/provider/package/rpm_spec.rb +0 -12
  260. data/spec/unit/provider/remote_file/cache_control_data_spec.rb +1 -1
  261. data/spec/unit/provider/service/systemd_service_spec.rb +44 -27
  262. data/spec/unit/provider/user/dscl_spec.rb +264 -660
  263. data/spec/unit/provider/user/useradd_spec.rb +0 -1
  264. data/spec/unit/provider/whyrun_safe_ruby_block_spec.rb +2 -2
  265. data/spec/unit/provider_spec.rb +12 -0
  266. data/spec/unit/recipe_spec.rb +0 -41
  267. data/spec/unit/resource_collection_spec.rb +1 -5
  268. data/spec/unit/resource_reporter_spec.rb +3 -51
  269. data/spec/unit/resource_spec.rb +3 -14
  270. data/spec/unit/rest_spec.rb +1 -4
  271. data/spec/unit/role_spec.rb +0 -10
  272. data/spec/unit/run_list_spec.rb +1 -5
  273. data/spec/unit/user_spec.rb +1 -5
  274. metadata +20 -100
  275. data/lib/chef/mixin/windows_env_helper.rb +0 -56
  276. data/lib/chef/provider/dsc_script.rb +0 -175
  277. data/lib/chef/resource/dsc_script.rb +0 -126
  278. data/lib/chef/streaming_cookbook_uploader.rb +0 -205
  279. data/lib/chef/util/dsc/configuration_generator.rb +0 -115
  280. data/lib/chef/util/dsc/lcm_output_parser.rb +0 -133
  281. data/lib/chef/util/dsc/local_configuration_manager.rb +0 -141
  282. data/lib/chef/util/dsc/resource_info.rb +0 -26
  283. data/lib/chef/util/powershell/cmdlet.rb +0 -136
  284. data/lib/chef/util/powershell/cmdlet_result.rb +0 -46
  285. data/spec/data/mac_users/10.7-8.plist.xml +0 -559
  286. data/spec/data/mac_users/10.7-8.shadow.xml +0 -11
  287. data/spec/data/mac_users/10.7.plist.xml +0 -559
  288. data/spec/data/mac_users/10.7.shadow.xml +0 -11
  289. data/spec/data/mac_users/10.8.plist.xml +0 -559
  290. data/spec/data/mac_users/10.8.shadow.xml +0 -21
  291. data/spec/data/mac_users/10.9.plist.xml +0 -560
  292. data/spec/data/mac_users/10.9.shadow.xml +0 -21
  293. data/spec/functional/provider/whyrun_safe_ruby_block_spec.rb +0 -51
  294. data/spec/functional/resource/dsc_script_spec.rb +0 -382
  295. data/spec/functional/resource/env_spec.rb +0 -182
  296. data/spec/functional/resource/user/dscl_spec.rb +0 -199
  297. data/spec/functional/util/powershell/cmdlet_spec.rb +0 -113
  298. data/spec/support/lib/chef/resource/zen_follower.rb +0 -46
  299. data/spec/support/shared/shared_examples.rb +0 -10
  300. data/spec/unit/chef_fs/data_handler/group_handler_spec.rb +0 -63
  301. data/spec/unit/formatters/base_spec.rb +0 -48
  302. data/spec/unit/provider/dsc_script_spec.rb +0 -174
  303. data/spec/unit/resource/dsc_script_spec.rb +0 -98
  304. data/spec/unit/util/dsc/configuration_generator_spec.rb +0 -171
  305. data/spec/unit/util/dsc/lcm_output_parser_spec.rb +0 -169
  306. data/spec/unit/util/dsc/local_configuration_manager_spec.rb +0 -139
  307. data/spec/unit/util/powershell/cmdlet_spec.rb +0 -106
@@ -21,90 +21,49 @@ require 'chef/json_compat'
21
21
 
22
22
  describe Chef::JSONCompat do
23
23
 
24
- describe "#from_json with JSON containing an existing class" do
25
- let(:json) { '{"json_class": "Chef::Role"}' }
26
-
24
+ describe "with JSON containing an existing class" do
25
+ let(:json){'{"json_class": "Chef::Role"}'}
27
26
  it "returns an instance of the class instead of a Hash" do
28
- expect(Chef::JSONCompat.from_json(json).class).to eq Chef::Role
29
- end
30
- end
31
-
32
- describe "#from_json with JSON containing comments" do
33
- let(:json) { %Q{{\n/* comment */\n// comment 2\n"json_class": "Chef::Role"}} }
34
-
35
- it "returns an instance of the class instead of a Hash" do
36
- expect(Chef::JSONCompat.from_json(json).class).to eq Chef::Role
37
- end
38
- end
39
-
40
- describe "#parse with JSON containing comments" do
41
- let(:json) { %Q{{\n/* comment */\n// comment 2\n"json_class": "Chef::Role"}} }
42
-
43
- it "returns a Hash" do
44
- expect(Chef::JSONCompat.parse(json).class).to eq Hash
27
+ Chef::JSONCompat.from_json(json).class.should eq Chef::Role
45
28
  end
46
29
  end
47
30
 
48
31
  describe 'with JSON containing "Chef::Sandbox" as a json_class value' do
49
32
  require 'chef/sandbox' # Only needed for this test
50
-
51
- let(:json) { '{"json_class": "Chef::Sandbox", "arbitrary": "data"}' }
52
-
33
+ let(:json){'{"json_class": "Chef::Sandbox", "arbitrary": "data"}'}
53
34
  it "returns a Hash, because Chef::Sandbox is a dummy class" do
54
- expect(Chef::JSONCompat.from_json(json)).to eq({"json_class" => "Chef::Sandbox", "arbitrary" => "data"})
55
- end
56
- end
57
-
58
- describe "when pretty printing an object that defines #to_json" do
59
- class Foo
60
- def to_json(*a)
61
- Chef::JSONCompat.to_json({'bar' => {'baz' => 5678}}, *a)
62
- end
63
- end
64
-
65
- it "should work" do
66
- f = Foo.new
67
- expect(Chef::JSONCompat.to_json_pretty(f)).to eql("{\n \"bar\": {\n \"baz\": 5678\n }\n}\n")
68
- end
69
-
70
- include_examples "to_json equalivent to Chef::JSONCompat.to_json" do
71
- let(:subject) { Foo.new }
35
+ Chef::JSONCompat.from_json(json).should eq({"json_class" => "Chef::Sandbox", "arbitrary" => "data"})
72
36
  end
73
37
  end
74
38
 
75
39
  describe "with a file with 300 or less nested entries" do
76
- let(:json) { IO.read(File.join(CHEF_SPEC_DATA, 'big_json.json')) }
77
- let(:hash) { Chef::JSONCompat.from_json(json) }
40
+ before(:all) do
41
+ @json = IO.read(File.join(CHEF_SPEC_DATA, 'big_json.json'))
42
+ @hash = Chef::JSONCompat.from_json(@json)
43
+ end
78
44
 
79
45
  describe "when a big json file is loaded" do
80
46
  it "should create a Hash from the file" do
81
- expect(hash).to be_kind_of(Hash)
47
+ @hash.should be_kind_of(Hash)
82
48
  end
83
-
84
49
  it "should has 'test' as a 300th nested value" do
85
- expect(hash['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']).to eq('test')
50
+ @hash['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key'].should == 'test'
86
51
  end
87
52
  end
88
53
  end
89
-
90
54
  describe "with a file with more than 300 nested entries" do
91
- let(:json) { IO.read(File.join(CHEF_SPEC_DATA, 'big_json_plus_one.json')) }
92
- let(:hash) { Chef::JSONCompat.from_json(json, {:max_nesting => 301}) }
55
+ before(:all) do
56
+ @json = IO.read(File.join(CHEF_SPEC_DATA, 'big_json_plus_one.json'))
57
+ @hash = Chef::JSONCompat.from_json(@json, {:max_nesting => 301})
58
+ end
93
59
 
94
60
  describe "when a big json file is loaded" do
95
61
  it "should create a Hash from the file" do
96
- expect(hash).to be_kind_of(Hash)
62
+ @hash.should be_kind_of(Hash)
97
63
  end
98
-
99
64
  it "should has 'test' as a 301st nested value" do
100
- expect(hash['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']).to eq('test')
65
+ @hash['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key'].should == 'test'
101
66
  end
102
67
  end
103
68
  end
104
-
105
- it "should define .to_json on all classes" do
106
- class SomeClass; end
107
-
108
- expect(SomeClass.new.respond_to?(:to_json)).to eq(true)
109
- end
110
69
  end
@@ -35,15 +35,15 @@ describe Chef::Knife::ClientCreate do
35
35
  @knife.stub(:edit_data).and_return(@client)
36
36
  @knife.stub(:puts)
37
37
  Chef::ApiClient.stub(:new).and_return(@client)
38
- @stdout = StringIO.new
39
- @knife.ui.stub(:stdout).and_return(@stdout)
38
+ @stderr = StringIO.new
39
+ @knife.ui.stub(:stderr).and_return(@stderr)
40
40
  end
41
41
 
42
42
  describe "run" do
43
43
  it "should create a new Client" do
44
44
  Chef::ApiClient.should_receive(:new).and_return(@client)
45
45
  @knife.run
46
- @stdout.string.should match /created client.+adam/i
46
+ @stderr.string.should match /created client.+adam/i
47
47
  end
48
48
 
49
49
  it "should set the Client name" do
@@ -25,8 +25,8 @@ describe Chef::Knife::ConfigureClient do
25
25
  Chef::Config[:validation_client_name] = 'chef-validator'
26
26
  Chef::Config[:validation_key] = '/etc/chef/validation.pem'
27
27
 
28
- @stdout = StringIO.new
29
- @knife.ui.stub(:stdout).and_return(@stdout)
28
+ @stderr = StringIO.new
29
+ @knife.ui.stub(:stderr).and_return(@stderr)
30
30
  end
31
31
 
32
32
  describe 'run' do
@@ -73,11 +73,12 @@ describe Chef::Knife::ConfigureClient do
73
73
  it 'should print information on what is being configured' do
74
74
  FileUtils.stub(:mkdir_p)
75
75
  @knife.run
76
- @stdout.string.should match /creating client configuration/i
77
- @stdout.string.should match /writing client\.rb/i
78
- @stdout.string.should match /writing validation\.pem/i
76
+ @stderr.string.should match /creating client configuration/i
77
+ @stderr.string.should match /writing client\.rb/i
78
+ @stderr.string.should match /writing validation\.pem/i
79
79
  end
80
80
  end
81
81
  end
82
82
 
83
83
  end
84
+
@@ -204,7 +204,7 @@ describe Chef::Knife::CookbookDelete do
204
204
  it 'should output that the cookbook was deleted' do
205
205
  @knife.stub(:delete_request)
206
206
  @knife.delete_version_without_confirmation('1.0.0')
207
- @stdout.string.should match /deleted cookbook\[foobar\]\[1.0.0\]/im
207
+ @stderr.string.should match /deleted cookbook\[foobar\]\[1.0.0\]/im
208
208
  end
209
209
 
210
210
  describe 'with --print-after' do
@@ -21,8 +21,8 @@ require 'spec_helper'
21
21
  describe Chef::Knife::CookbookDownload do
22
22
  before(:each) do
23
23
  @knife = Chef::Knife::CookbookDownload.new
24
- @stdout = StringIO.new
25
- @knife.ui.stub(:stdout).and_return(@stdout)
24
+ @stderr = StringIO.new
25
+ @knife.ui.stub(:stderr).and_return(@stderr)
26
26
  end
27
27
 
28
28
  describe 'run' do
@@ -121,10 +121,10 @@ describe Chef::Knife::CookbookDownload do
121
121
  File.should_receive(:exists?).with('/var/tmp/chef/foobar-1.0.0').and_return(false)
122
122
  @knife.run
123
123
  ['attributes', 'recipes', 'templates'].each do |segment|
124
- @stdout.string.should match /downloading #{segment}/im
124
+ @stderr.string.should match /downloading #{segment}/im
125
125
  end
126
- @stdout.string.should match /downloading foobar cookbook version 1\.0\.0/im
127
- @stdout.string.should match /cookbook downloaded to \/var\/tmp\/chef\/foobar-1\.0\.0/im
126
+ @stderr.string.should match /downloading foobar cookbook version 1\.0\.0/im
127
+ @stderr.string.should match /cookbook downloaded to \/var\/tmp\/chef\/foobar-1\.0\.0/im
128
128
  end
129
129
 
130
130
  describe 'with -f or --force' do
@@ -27,6 +27,7 @@ describe Chef::Knife::CookbookMetadataFromFile do
27
27
  @tgt = File.expand_path(File.join(CHEF_SPEC_DATA, "metadata", "quick_start", "metadata.json"))
28
28
  @knife = Chef::Knife::CookbookMetadataFromFile.new
29
29
  @knife.name_args = [ @src ]
30
+ @knife.stub(:to_json_pretty).and_return(true)
30
31
  @md = Chef::Cookbook::Metadata.new
31
32
  Chef::Cookbook::Metadata.stub(:new).and_return(@md)
32
33
  $stdout.stub(:write)
@@ -119,7 +119,7 @@ describe Chef::Knife::CookbookMetadata do
119
119
  Chef::JSONCompat.should_receive(:to_json_pretty).with(@metadata_mock).
120
120
  and_return(@json_data)
121
121
  @knife.generate_metadata_from_file('foobar', "#{@cookbook_dir}/foobar/metadata.rb")
122
- @stdout.string.should match /generating metadata for foobar from #{@cookbook_dir}\/foobar\/metadata\.rb/im
122
+ @stderr.string.should match /generating metadata for foobar from #{@cookbook_dir}\/foobar\/metadata\.rb/im
123
123
  end
124
124
 
125
125
  { Chef::Exceptions::ObsoleteDependencySyntax => 'obsolote dependency',
@@ -25,16 +25,15 @@ describe Chef::Knife::CookbookSiteDownload do
25
25
  @knife = Chef::Knife::CookbookSiteDownload.new
26
26
  @knife.name_args = ['apache2']
27
27
  @noauth_rest = double('no auth rest')
28
- @stdout = StringIO.new
29
28
  @stderr = StringIO.new
30
- @cookbook_api_url = 'https://supermarket.getchef.com/api/v1/cookbooks'
29
+ @cookbook_api_url = 'http://cookbooks.opscode.com/api/v1/cookbooks'
31
30
  @version = '1.0.2'
32
31
  @version_us = @version.gsub '.', '_'
33
32
  @current_data = { 'deprecated' => false,
34
33
  'latest_version' => "#{@cookbook_api_url}/apache2/versions/#{@version_us}",
35
34
  'replacement' => 'other_apache2' }
36
35
 
37
- @knife.ui.stub(:stdout).and_return(@stdout)
36
+ @knife.ui.stub(:stderr).and_return(@stderr)
38
37
  @knife.stub(:noauth_rest).and_return(@noauth_rest)
39
38
  @noauth_rest.should_receive(:get_rest).
40
39
  with("#{@cookbook_api_url}/apache2").
@@ -86,8 +85,8 @@ describe Chef::Knife::CookbookSiteDownload do
86
85
  with(/.+deprecated.+replaced by other_apache2.+/i)
87
86
  FileUtils.should_receive(:cp).with(@temp_file.path, @file)
88
87
  @knife.run
89
- @stdout.string.should match /downloading apache2.+version.+#{Regexp.escape(@version)}/i
90
- @stdout.string.should match /cookbook save.+#{Regexp.escape(@file)}/i
88
+ @stderr.string.should match /downloading apache2.+version.+#{Regexp.escape(@version)}/i
89
+ @stderr.string.should match /cookbook save.+#{Regexp.escape(@file)}/i
91
90
  end
92
91
 
93
92
  end
@@ -95,8 +94,8 @@ describe Chef::Knife::CookbookSiteDownload do
95
94
  it 'should download the latest version' do
96
95
  FileUtils.should_receive(:cp).with(@temp_file.path, @file)
97
96
  @knife.run
98
- @stdout.string.should match /downloading apache2.+version.+#{Regexp.escape(@version)}/i
99
- @stdout.string.should match /cookbook save.+#{Regexp.escape(@file)}/i
97
+ @stderr.string.should match /downloading apache2.+version.+#{Regexp.escape(@version)}/i
98
+ @stderr.string.should match /cookbook save.+#{Regexp.escape(@file)}/i
100
99
  end
101
100
 
102
101
  context 'with -f or --file' do
@@ -108,8 +107,8 @@ describe Chef::Knife::CookbookSiteDownload do
108
107
 
109
108
  it 'should download the cookbook to the desired file' do
110
109
  @knife.run
111
- @stdout.string.should match /downloading apache2.+version.+#{Regexp.escape(@version)}/i
112
- @stdout.string.should match /cookbook save.+#{Regexp.escape(@file)}/i
110
+ @stderr.string.should match /downloading apache2.+version.+#{Regexp.escape(@version)}/i
111
+ @stderr.string.should match /cookbook save.+#{Regexp.escape(@file)}/i
113
112
  end
114
113
  end
115
114
 
@@ -140,8 +139,8 @@ describe Chef::Knife::CookbookSiteDownload do
140
139
  and_return(@temp_file)
141
140
  FileUtils.should_receive(:cp).with(@temp_file.path, @file)
142
141
  @knife.run
143
- @stdout.string.should match /downloading apache2.+version.+#{Regexp.escape(@version)}/i
144
- @stdout.string.should match /cookbook save.+#{Regexp.escape(@file)}/i
142
+ @stderr.string.should match /downloading apache2.+version.+#{Regexp.escape(@version)}/i
143
+ @stderr.string.should match /cookbook save.+#{Regexp.escape(@file)}/i
145
144
  end
146
145
  end
147
146
 
@@ -19,177 +19,132 @@
19
19
  require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper"))
20
20
 
21
21
  describe Chef::Knife::CookbookSiteInstall do
22
- let(:knife) { Chef::Knife::CookbookSiteInstall.new }
23
- let(:stdout) { StringIO.new }
24
- let(:stderr) { StringIO.new }
25
- let(:downloader) { Hash.new }
26
- let(:repo) { double(:sanity_check => true, :reset_to_default_state => true,
27
- :prepare_to_import => true, :finalize_updates_to => true,
28
- :merge_updates_from => true) }
29
- let(:install_path) { if Chef::Platform.windows?
30
- 'C:/tmp/chef'
31
- else
32
- '/var/tmp/chef'
33
- end }
34
-
35
22
  before(:each) do
36
23
  require 'chef/knife/core/cookbook_scm_repo'
37
-
38
- allow(knife.ui).to receive(:stdout).and_return(stdout)
39
- knife.config = {}
40
- knife.config[:cookbook_path] = [ install_path ]
41
-
42
- allow(knife).to receive(:stderr).and_return(stderr)
43
- allow(knife).to receive(:stdout).and_return(stdout)
44
-
45
- # Assume all external commands would have succeed. :(
46
- allow(File).to receive(:unlink)
47
- allow(File).to receive(:rmtree)
48
- allow(knife).to receive(:shell_out!).and_return(true)
49
-
50
- # CookbookSiteDownload Stup
51
- allow(knife).to receive(:download_cookbook_to).and_return(downloader)
52
- allow(downloader).to receive(:version) do
53
- if knife.name_args.size == 2
54
- knife.name_args[1]
24
+ @stdout = StringIO.new
25
+ @knife = Chef::Knife::CookbookSiteInstall.new
26
+ @knife.ui.stub(:stdout).and_return(@stdout)
27
+ @knife.config = {}
28
+ if Chef::Platform.windows?
29
+ @install_path = 'C:/tmp/chef'
30
+ else
31
+ @install_path = '/var/tmp/chef'
32
+ end
33
+ @knife.config[:cookbook_path] = [ @install_path ]
34
+
35
+ @stdout = StringIO.new
36
+ @stderr = StringIO.new
37
+ @knife.stub(:stderr).and_return(@stdout)
38
+ @knife.stub(:stdout).and_return(@stdout)
39
+
40
+ #Assume all external commands would have succeed. :(
41
+ File.stub(:unlink)
42
+ File.stub(:rmtree)
43
+ @knife.stub(:shell_out!).and_return(true)
44
+
45
+ #CookbookSiteDownload Stup
46
+ @downloader = {}
47
+ @knife.stub(:download_cookbook_to).and_return(@downloader)
48
+ @downloader.stub(:version).and_return do
49
+ if @knife.name_args.size == 2
50
+ @knife.name_args[1]
55
51
  else
56
52
  "0.3.0"
57
53
  end
58
54
  end
59
55
 
60
- # Stubs for CookbookSCMRepo
61
- allow(Chef::Knife::CookbookSCMRepo).to receive(:new).and_return(repo)
56
+ #Stubs for CookbookSCMRepo
57
+ @repo = double(:sanity_check => true, :reset_to_default_state => true,
58
+ :prepare_to_import => true, :finalize_updates_to => true,
59
+ :merge_updates_from => true)
60
+ Chef::Knife::CookbookSCMRepo.stub(:new).and_return(@repo)
62
61
  end
63
62
 
64
- describe "run" do
65
- it "raises an error if a cookbook name is not provided" do
66
- knife.name_args = []
67
- expect(knife.ui).to receive(:error).with("Please specify a cookbook to download and install.")
68
- expect { knife.run }.to raise_error(SystemExit)
69
- end
70
-
71
- it "raises an error if more than two arguments are given" do
72
- knife.name_args = ["foo", "bar", "baz"]
73
- expect(knife.ui).to receive(:error).with("Installing multiple cookbooks at once is not supported.")
74
- expect { knife.run }.to raise_error(SystemExit)
75
- end
76
-
77
- it "raises an error if the second argument is not a version" do
78
- knife.name_args = ["getting-started", "1pass"]
79
- expect(knife.ui).to receive(:error).with("Installing multiple cookbooks at once is not supported.")
80
- expect { knife.run }.to raise_error(SystemExit)
81
- end
82
-
83
- it "raises an error if the second argument is a four-digit version" do
84
- knife.name_args = ["getting-started", "0.0.0.1"]
85
- expect(knife.ui).to receive(:error).with("Installing multiple cookbooks at once is not supported.")
86
- expect { knife.run }.to raise_error(SystemExit)
87
- end
88
-
89
- it "raises an error if the second argument is a one-digit version" do
90
- knife.name_args = ["getting-started", "1"]
91
- expect(knife.ui).to receive(:error).with("Installing multiple cookbooks at once is not supported.")
92
- expect { knife.run }.to raise_error(SystemExit)
93
- end
94
-
95
- it "installs the specified version if second argument is a three-digit version" do
96
- knife.name_args = ["getting-started", "0.1.0"]
97
- knife.config[:no_deps] = true
98
- upstream_file = File.join(install_path, "getting-started.tar.gz")
99
- expect(knife).to receive(:download_cookbook_to).with(upstream_file)
100
- expect(knife).to receive(:extract_cookbook).with(upstream_file, "0.1.0")
101
- expect(knife).to receive(:clear_existing_files).with(File.join(install_path, "getting-started"))
102
- expect(repo).to receive(:merge_updates_from).with("getting-started", "0.1.0")
103
- knife.run
104
- end
105
-
106
- it "installs the specified version if second argument is a two-digit version" do
107
- knife.name_args = ["getting-started", "0.1"]
108
- knife.config[:no_deps] = true
109
- upstream_file = File.join(install_path, "getting-started.tar.gz")
110
- expect(knife).to receive(:download_cookbook_to).with(upstream_file)
111
- expect(knife).to receive(:extract_cookbook).with(upstream_file, "0.1")
112
- expect(knife).to receive(:clear_existing_files).with(File.join(install_path, "getting-started"))
113
- expect(repo).to receive(:merge_updates_from).with("getting-started", "0.1")
114
- knife.run
115
- end
116
-
117
- it "installs the latest version if only a cookbook name is given" do
118
- knife.name_args = ["getting-started"]
119
- knife.config[:no_deps] = true
120
- upstream_file = File.join(install_path, "getting-started.tar.gz")
121
- expect(knife).to receive(:download_cookbook_to).with(upstream_file)
122
- expect(knife).to receive(:extract_cookbook).with(upstream_file, "0.3.0")
123
- expect(knife).to receive(:clear_existing_files).with(File.join(install_path, "getting-started"))
124
- expect(repo).to receive(:merge_updates_from).with("getting-started", "0.3.0")
125
- knife.run
126
- end
127
-
128
- it "does not create/reset git branches if use_current_branch is set" do
129
- knife.name_args = ["getting-started"]
130
- knife.config[:use_current_branch] = true
131
- knife.config[:no_deps] = true
132
- upstream_file = File.join(install_path, "getting-started.tar.gz")
133
- expect(repo).not_to receive(:prepare_to_import)
134
- expect(repo).not_to receive(:reset_to_default_state)
135
- knife.run
136
- end
137
-
138
- it "does not raise an error if cookbook_path is a string" do
139
- knife.config[:cookbook_path] = install_path
140
- knife.config[:no_deps] = true
141
- knife.name_args = ["getting-started"]
142
- upstream_file = File.join(install_path, "getting-started.tar.gz")
143
- expect(knife).to receive(:download_cookbook_to).with(upstream_file)
144
- expect(knife).to receive(:extract_cookbook).with(upstream_file, "0.3.0")
145
- expect(knife).to receive(:clear_existing_files).with(File.join(install_path, "getting-started"))
146
- expect(repo).to receive(:merge_updates_from).with("getting-started", "0.3.0")
147
- expect { knife.run }.not_to raise_error
148
- end
149
- end # end of run
150
-
151
- let(:metadata) { Chef::Cookbook::Metadata.new }
152
- let(:rb_metadata_path) { File.join(install_path, "post-punk-kitchen", "metadata.rb") }
153
- let(:json_metadata_path) { File.join(install_path, "post-punk-kitchen", "metadata.json") }
154
-
155
- describe "preferred_metadata" do
156
- before do
157
- allow(Chef::Cookbook::Metadata).to receive(:new).and_return(metadata)
158
- allow(File).to receive(:exist?).and_return(false)
159
- knife.instance_variable_set(:@cookbook_name, "post-punk-kitchen")
160
- knife.instance_variable_set(:@install_path, install_path)
161
- end
162
63
 
163
- it "returns a populated Metadata object if metadata.rb exists" do
164
- allow(File).to receive(:exist?).with(rb_metadata_path).and_return(true)
165
- expect(metadata).to receive(:from_file).with(rb_metadata_path)
166
- knife.preferred_metadata
167
- end
168
-
169
- it "returns a populated Metadata object if metadata.json exists" do
170
- allow(File).to receive(:exist?).with(json_metadata_path).and_return(true)
171
- #expect(IO).to receive(:read).with(json_metadata_path)
172
- allow(IO).to receive(:read)
173
- expect(metadata).to receive(:from_json)
174
- knife.preferred_metadata
175
- end
176
-
177
- it "prefers metadata.rb over metadata.json" do
178
- allow(File).to receive(:exist?).with(rb_metadata_path).and_return(true)
179
- allow(File).to receive(:exist?).with(json_metadata_path).and_return(true)
180
- allow(IO).to receive(:read)
181
- expect(metadata).to receive(:from_file).with(rb_metadata_path)
182
- expect(metadata).not_to receive(:from_json)
183
- knife.preferred_metadata
184
- end
185
-
186
- it "rasies an error if it finds no metadata file" do
187
- expect { knife.preferred_metadata }.to raise_error { |error|
188
- expect(error).to be_a(Chef::Exceptions::MetadataNotFound)
189
- expect(error.cookbook_name).to eq("post-punk-kitchen")
190
- expect(error.install_path).to eq(install_path)
191
- }
64
+ describe "run" do
65
+ it "should return an error if a cookbook name is not provided" do
66
+ @knife.name_args = []
67
+ @knife.ui.should_receive(:error).with("Please specify a cookbook to download and install.")
68
+ lambda { @knife.run }.should raise_error(SystemExit)
69
+ end
70
+
71
+ it "should return an error if more than two arguments are given" do
72
+ @knife.name_args = ["foo", "bar", "baz"]
73
+ @knife.ui.should_receive(:error).with("Installing multiple cookbooks at once is not supported.")
74
+ lambda { @knife.run }.should raise_error(SystemExit)
75
+ end
76
+
77
+ it "should return an error if the second argument is not a version" do
78
+ @knife.name_args = ["getting-started", "1pass"]
79
+ @knife.ui.should_receive(:error).with("Installing multiple cookbooks at once is not supported.")
80
+ lambda { @knife.run }.should raise_error(SystemExit)
81
+ end
82
+
83
+ it "should return an error if the second argument is a four-digit version" do
84
+ @knife.name_args = ["getting-started", "0.0.0.1"]
85
+ @knife.ui.should_receive(:error).with("Installing multiple cookbooks at once is not supported.")
86
+ lambda { @knife.run }.should raise_error(SystemExit)
87
+ end
88
+
89
+ it "should return an error if the second argument is a one-digit version" do
90
+ @knife.name_args = ["getting-started", "1"]
91
+ @knife.ui.should_receive(:error).with("Installing multiple cookbooks at once is not supported.")
92
+ lambda { @knife.run }.should raise_error(SystemExit)
93
+ end
94
+
95
+ it "should install the specified version if second argument is a three-digit version" do
96
+ @knife.name_args = ["getting-started", "0.1.0"]
97
+ @knife.config[:no_deps] = true
98
+ upstream_file = File.join(@install_path, "getting-started.tar.gz")
99
+ @knife.should_receive(:download_cookbook_to).with(upstream_file)
100
+ @knife.should_receive(:extract_cookbook).with(upstream_file, "0.1.0")
101
+ @knife.should_receive(:clear_existing_files).with(File.join(@install_path, "getting-started"))
102
+ @repo.should_receive(:merge_updates_from).with("getting-started", "0.1.0")
103
+ @knife.run
104
+ end
105
+
106
+ it "should install the specified version if second argument is a two-digit version" do
107
+ @knife.name_args = ["getting-started", "0.1"]
108
+ @knife.config[:no_deps] = true
109
+ upstream_file = File.join(@install_path, "getting-started.tar.gz")
110
+ @knife.should_receive(:download_cookbook_to).with(upstream_file)
111
+ @knife.should_receive(:extract_cookbook).with(upstream_file, "0.1")
112
+ @knife.should_receive(:clear_existing_files).with(File.join(@install_path, "getting-started"))
113
+ @repo.should_receive(:merge_updates_from).with("getting-started", "0.1")
114
+ @knife.run
115
+ end
116
+
117
+ it "should install the latest version if only a cookbook name is given" do
118
+ @knife.name_args = ["getting-started"]
119
+ @knife.config[:no_deps] = true
120
+ upstream_file = File.join(@install_path, "getting-started.tar.gz")
121
+ @knife.should_receive(:download_cookbook_to).with(upstream_file)
122
+ @knife.should_receive(:extract_cookbook).with(upstream_file, "0.3.0")
123
+ @knife.should_receive(:clear_existing_files).with(File.join(@install_path, "getting-started"))
124
+ @repo.should_receive(:merge_updates_from).with("getting-started", "0.3.0")
125
+ @knife.run
126
+ end
127
+
128
+ it "should not create/reset git branches if use_current_branch is set" do
129
+ @knife.name_args = ["getting-started"]
130
+ @knife.config[:use_current_branch] = true
131
+ @knife.config[:no_deps] = true
132
+ upstream_file = File.join(@install_path, "getting-started.tar.gz")
133
+ @repo.should_not_receive(:prepare_to_import)
134
+ @repo.should_not_receive(:reset_to_default_state)
135
+ @knife.run
136
+ end
137
+
138
+ it "should not raise an error if cookbook_path is a string" do
139
+ @knife.config[:cookbook_path] = @install_path
140
+ @knife.config[:no_deps] = true
141
+ @knife.name_args = ["getting-started"]
142
+ upstream_file = File.join(@install_path, "getting-started.tar.gz")
143
+ @knife.should_receive(:download_cookbook_to).with(upstream_file)
144
+ @knife.should_receive(:extract_cookbook).with(upstream_file, "0.3.0")
145
+ @knife.should_receive(:clear_existing_files).with(File.join(@install_path, "getting-started"))
146
+ @repo.should_receive(:merge_updates_from).with("getting-started", "0.3.0")
147
+ lambda { @knife.run }.should_not raise_error
192
148
  end
193
-
194
149
  end
195
150
  end