chef 15.12.22 → 15.16.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +10 -10
  3. data/Rakefile +11 -17
  4. data/chef-universal-mingw32.gemspec +4 -4
  5. data/chef.gemspec +22 -4
  6. data/lib/chef/api_client/registration.rb +2 -2
  7. data/lib/chef/chef_fs/file_system/repository/base_file.rb +1 -0
  8. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb +2 -2
  9. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb +1 -1
  10. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb +2 -2
  11. data/lib/chef/chef_fs/file_system/repository/directory.rb +1 -1
  12. data/lib/chef/chef_fs/file_system/repository/file_system_entry.rb +1 -1
  13. data/lib/chef/deprecated.rb +4 -0
  14. data/lib/chef/environment.rb +2 -2
  15. data/lib/chef/exceptions.rb +3 -0
  16. data/lib/chef/http.rb +2 -1
  17. data/lib/chef/knife/bootstrap.rb +3 -3
  18. data/lib/chef/knife/bootstrap/train_connector.rb +1 -0
  19. data/lib/chef/knife/cookbook_download.rb +1 -1
  20. data/lib/chef/knife/cookbook_metadata.rb +1 -1
  21. data/lib/chef/knife/core/gem_glob_loader.rb +1 -1
  22. data/lib/chef/knife/core/hashed_command_loader.rb +3 -2
  23. data/lib/chef/knife/core/subcommand_loader.rb +1 -1
  24. data/lib/chef/knife/exec.rb +2 -2
  25. data/lib/chef/knife/ssh.rb +20 -1
  26. data/lib/chef/log.rb +1 -1
  27. data/lib/chef/mixin/openssl_helper.rb +26 -3
  28. data/lib/chef/mixin/template.rb +1 -0
  29. data/lib/chef/node_map.rb +5 -2
  30. data/lib/chef/provider/mount/solaris.rb +0 -1
  31. data/lib/chef/provider/package/dnf/dnf_helper.py +5 -0
  32. data/lib/chef/provider/package/freebsd/pkgng.rb +3 -1
  33. data/lib/chef/provider/package/yum/yum_helper.py +4 -0
  34. data/lib/chef/provider/package/zypper.rb +0 -1
  35. data/lib/chef/provider/service/arch.rb +2 -2
  36. data/lib/chef/provider/service/debian.rb +1 -1
  37. data/lib/chef/provider/service/gentoo.rb +2 -2
  38. data/lib/chef/provider/service/macosx.rb +2 -2
  39. data/lib/chef/provider/service/openbsd.rb +1 -1
  40. data/lib/chef/provider/service/redhat.rb +2 -2
  41. data/lib/chef/provider/service/upstart.rb +1 -1
  42. data/lib/chef/provider/yum_repository.rb +1 -1
  43. data/lib/chef/provider/zypper_repository.rb +1 -1
  44. data/lib/chef/resource.rb +2 -0
  45. data/lib/chef/resource/cron_access.rb +2 -2
  46. data/lib/chef/resource/cron_d.rb +2 -1
  47. data/lib/chef/resource/homebrew_cask.rb +3 -3
  48. data/lib/chef/resource/hostname.rb +18 -18
  49. data/lib/chef/resource/locale.rb +1 -1
  50. data/lib/chef/resource/lwrp_base.rb +7 -0
  51. data/lib/chef/resource/ssh_known_hosts_entry.rb +1 -1
  52. data/lib/chef/resource/sudo.rb +2 -2
  53. data/lib/chef/resource/windows_feature_powershell.rb +6 -2
  54. data/lib/chef/resource/windows_font.rb +2 -1
  55. data/lib/chef/role.rb +2 -2
  56. data/lib/chef/shell.rb +32 -1
  57. data/lib/chef/shell/shell_session.rb +2 -0
  58. data/lib/chef/util/diff.rb +1 -1
  59. data/lib/chef/util/dsc/configuration_generator.rb +1 -1
  60. data/lib/chef/util/powershell/cmdlet.rb +1 -1
  61. data/lib/chef/version.rb +2 -2
  62. data/lib/chef/version_string.rb +1 -1
  63. data/lib/chef/win32/file.rb +2 -2
  64. data/spec/functional/knife/ssh_spec.rb +4 -4
  65. data/spec/functional/resource/aix_service_spec.rb +0 -1
  66. data/spec/functional/resource/aixinit_service_spec.rb +7 -8
  67. data/spec/functional/resource/apt_package_spec.rb +0 -1
  68. data/spec/functional/resource/bff_spec.rb +2 -2
  69. data/spec/functional/resource/cookbook_file_spec.rb +1 -1
  70. data/spec/functional/resource/cron_spec.rb +0 -1
  71. data/spec/functional/resource/dsc_resource_spec.rb +1 -1
  72. data/spec/functional/resource/insserv_spec.rb +4 -5
  73. data/spec/functional/resource/link_spec.rb +17 -17
  74. data/spec/functional/resource/rpm_spec.rb +2 -2
  75. data/spec/functional/resource/user/dscl_spec.rb +1 -1
  76. data/spec/functional/resource/user/mac_user_spec.rb +1 -1
  77. data/spec/functional/resource/windows_certificate_spec.rb +3 -3
  78. data/spec/functional/resource/windows_font_spec.rb +49 -0
  79. data/spec/functional/run_lock_spec.rb +2 -1
  80. data/spec/functional/shell_spec.rb +5 -5
  81. data/spec/functional/util/powershell/cmdlet_spec.rb +1 -1
  82. data/spec/functional/version_spec.rb +1 -1
  83. data/spec/functional/win32/service_manager_spec.rb +1 -1
  84. data/spec/integration/recipes/accumulator_spec.rb +1 -1
  85. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +2 -2
  86. data/spec/integration/recipes/lwrp_spec.rb +1 -1
  87. data/spec/integration/recipes/notifies_spec.rb +1 -1
  88. data/spec/integration/recipes/notifying_block_spec.rb +1 -1
  89. data/spec/integration/recipes/recipe_dsl_spec.rb +1 -1
  90. data/spec/integration/recipes/resource_converge_if_changed_spec.rb +2 -0
  91. data/spec/integration/recipes/resource_load_spec.rb +1 -0
  92. data/spec/integration/recipes/unified_mode_spec.rb +1 -1
  93. data/spec/scripts/ssl-serve.rb +1 -1
  94. data/spec/spec_helper.rb +10 -8
  95. data/spec/support/platform_helpers.rb +12 -42
  96. data/spec/support/platforms/win32/spec_service.rb +1 -1
  97. data/spec/support/shared/functional/directory_resource.rb +1 -1
  98. data/spec/support/shared/functional/execute_resource.rb +1 -1
  99. data/spec/support/shared/functional/file_resource.rb +2 -2
  100. data/spec/support/shared/functional/win32_service.rb +1 -1
  101. data/spec/support/shared/functional/windows_script.rb +3 -3
  102. data/spec/support/shared/integration/knife_support.rb +2 -5
  103. data/spec/unit/chef_fs/file_system/operation_failed_error_spec.rb +2 -4
  104. data/spec/unit/cookbook/gem_installer_spec.rb +2 -1
  105. data/spec/unit/dsl/platform_introspection_spec.rb +1 -0
  106. data/spec/unit/environment_spec.rb +7 -7
  107. data/spec/unit/event_dispatch/dispatcher_spec.rb +3 -0
  108. data/spec/unit/knife/bootstrap_spec.rb +14 -14
  109. data/spec/unit/knife/cookbook_download_spec.rb +4 -4
  110. data/spec/unit/knife/cookbook_metadata_from_file_spec.rb +1 -1
  111. data/spec/unit/knife/cookbook_upload_spec.rb +5 -6
  112. data/spec/unit/knife/core/hashed_command_loader_spec.rb +3 -3
  113. data/spec/unit/knife/ssh_spec.rb +2 -2
  114. data/spec/unit/knife/supermarket_share_spec.rb +5 -3
  115. data/spec/unit/lwrp_spec.rb +4 -4
  116. data/spec/unit/mixin/securable_spec.rb +0 -1
  117. data/spec/unit/property_spec.rb +5 -5
  118. data/spec/unit/provider/package/dnf/python_helper_spec.rb +1 -1
  119. data/spec/unit/provider/package/freebsd/pkgng_spec.rb +1 -1
  120. data/spec/unit/provider/package/rubygems_spec.rb +5 -10
  121. data/spec/unit/provider/package/windows_spec.rb +30 -53
  122. data/spec/unit/provider/service/arch_service_spec.rb +3 -2
  123. data/spec/unit/provider/service/debian_service_spec.rb +1 -1
  124. data/spec/unit/provider/service/gentoo_service_spec.rb +7 -7
  125. data/spec/unit/provider/service/macosx_spec.rb +3 -3
  126. data/spec/unit/provider/service/redhat_spec.rb +2 -2
  127. data/spec/unit/provider/service/upstart_service_spec.rb +3 -3
  128. data/spec/unit/provider/service/windows_spec.rb +2 -6
  129. data/spec/unit/provider/systemd_unit_spec.rb +28 -24
  130. data/spec/unit/provider_spec.rb +1 -0
  131. data/spec/unit/resource/windows_feature_powershell_spec.rb +30 -4
  132. data/spec/unit/resource/windows_package_spec.rb +1 -0
  133. data/spec/unit/role_spec.rb +11 -11
  134. data/spec/unit/run_context/cookbook_compiler_spec.rb +1 -1
  135. data/spec/unit/win32/security_spec.rb +4 -3
  136. metadata +36 -23
@@ -26,7 +26,7 @@ if RUBY_PLATFORM =~ /mswin|mingw|windows/
26
26
 
27
27
  def service_main(*startup_parameters)
28
28
  while running?
29
- unless File.exists?(@test_service_file)
29
+ unless File.exist?(@test_service_file)
30
30
  File.open(@test_service_file, "wb") do |f|
31
31
  f.write("This file is created by SpecService")
32
32
  end
@@ -173,6 +173,6 @@ shared_context Chef::Resource::Directory do
173
173
  end
174
174
 
175
175
  after(:each) do
176
- FileUtils.rm_r(path) if File.exists?(path)
176
+ FileUtils.rm_r(path) if File.exist?(path)
177
177
  end
178
178
  end
@@ -62,7 +62,7 @@ shared_context "a command that can be executed as an alternate user" do
62
62
  end
63
63
 
64
64
  after do
65
- File.delete(script_output_path) if File.exists?(script_output_path)
65
+ File.delete(script_output_path) if File.exist?(script_output_path)
66
66
  Dir.rmdir(script_output_dir) if Dir.exist?(script_output_dir)
67
67
  end
68
68
  end
@@ -1038,8 +1038,8 @@ shared_context Chef::Resource::File do
1038
1038
  end
1039
1039
 
1040
1040
  after(:each) do
1041
- FileUtils.rm_r(path) if File.exists?(path)
1042
- FileUtils.rm_r(CHEF_SPEC_BACKUP_PATH) if File.exists?(CHEF_SPEC_BACKUP_PATH)
1041
+ FileUtils.rm_r(path) if File.exist?(path)
1042
+ FileUtils.rm_r(CHEF_SPEC_BACKUP_PATH) if File.exist?(CHEF_SPEC_BACKUP_PATH)
1043
1043
  end
1044
1044
 
1045
1045
  after do
@@ -30,7 +30,7 @@ shared_context "using Win32::Service" do
30
30
  end
31
31
 
32
32
  # Delete the test_service_file if it exists
33
- if File.exists?(test_service_file)
33
+ if File.exist?(test_service_file)
34
34
  File.delete(test_service_file)
35
35
  end
36
36
  end
@@ -39,11 +39,11 @@ shared_context Chef::Resource::WindowsScript do
39
39
  end
40
40
 
41
41
  before(:each) do
42
- File.delete(script_output_path) if File.exists?(script_output_path)
42
+ File.delete(script_output_path) if File.exist?(script_output_path)
43
43
  end
44
44
 
45
45
  after(:each) do
46
- File.delete(script_output_path) if File.exists?(script_output_path)
46
+ File.delete(script_output_path) if File.exist?(script_output_path)
47
47
  end
48
48
 
49
49
  shared_examples_for "a script resource with architecture attribute" do
@@ -149,7 +149,7 @@ shared_context Chef::Resource::WindowsScript do
149
149
 
150
150
  after do
151
151
  script_file.close! if script_file
152
- ::File.delete(script_file.to_path) if script_file && ::File.exists?(script_file.to_path)
152
+ ::File.delete(script_file.to_path) if script_file && ::File.exist?(script_file.to_path)
153
153
  end
154
154
 
155
155
  include_context "alternate user identity"
@@ -39,10 +39,7 @@ module KnifeSupport
39
39
 
40
40
  # Work on machines where we can't access /var
41
41
  Dir.mktmpdir("checksums") do |checksums_cache_dir|
42
- Chef::Config[:cache_options] = {
43
- path: checksums_cache_dir,
44
- skip_expires: true,
45
- }
42
+ Chef::Config[:syntax_check_cache_path] = checksums_cache_dir
46
43
 
47
44
  # This is Chef::Knife.run without load_commands--we'll load stuff
48
45
  # ourselves, thank you very much
@@ -117,7 +114,7 @@ module KnifeSupport
117
114
  ensure
118
115
  Chef::Log.use_log_devices(old_loggers)
119
116
  Chef::Log.level = old_log_level
120
- Chef::Config.delete(:cache_options)
117
+ Chef::Config.delete(:syntax_check_cache_path)
121
118
  Chef::Config.delete(:concurrency)
122
119
  end
123
120
 
@@ -25,11 +25,9 @@ describe Chef::ChefFS::FileSystem::OperationFailedError do
25
25
 
26
26
  context "has a cause attribute and HTTP result code is 400" do
27
27
  it "include error cause" do
28
- allow_message_expectations_on_nil
29
28
  response_body = '{"error":["Invalid key test in request body"]}'
30
- allow(@response).to receive(:code).and_return("400")
31
- allow(@response).to receive(:body).and_return(response_body)
32
- exception = Net::HTTPClientException.new("(exception) unauthorized", @response)
29
+ response = double(:response, code: "400", body: response_body)
30
+ exception = Net::HTTPClientException.new("(exception) unauthorized", response)
33
31
  expect do
34
32
  raise Chef::ChefFS::FileSystem::OperationFailedError.new(:write, self, exception), error_message
35
33
  end.to raise_error(Chef::ChefFS::FileSystem::OperationFailedError, "#{error_message} cause: #{response_body}")
@@ -95,7 +95,8 @@ describe Chef::Cookbook::GemInstaller do
95
95
 
96
96
  it "skip metadata installation when Chef::Config[:skip_gem_metadata_installation] is set to true" do
97
97
  Chef::Config[:skip_gem_metadata_installation] = true
98
- expect(gem_installer.install).to_not receive(:shell_out!)
98
+ expect(gem_installer).to_not receive(:shell_out!)
99
+ expect(gem_installer.install).to be_nil
99
100
  end
100
101
 
101
102
  it "install metadata when Chef::Config[:skip_gem_metadata_installation] is not true" do
@@ -21,6 +21,7 @@ require "chef/dsl/platform_introspection"
21
21
 
22
22
  class LanguageTester
23
23
  attr_reader :node
24
+
24
25
  def initialize(node)
25
26
  @node = node
26
27
  end
@@ -402,8 +402,8 @@ describe Chef::Environment do
402
402
 
403
403
  it "should get the environment from the environment_path" do
404
404
  expect(File).to receive(:directory?).with(Chef::Config[:environment_path]).and_return(true)
405
- expect(File).to receive(:exists?).with(File.join(Chef::Config[:environment_path], "foo.json")).and_return(false)
406
- expect(File).to receive(:exists?).with(File.join(Chef::Config[:environment_path], "foo.rb")).exactly(1).times.and_return(true)
405
+ expect(File).to receive(:exist?).with(File.join(Chef::Config[:environment_path], "foo.json")).and_return(false)
406
+ expect(File).to receive(:exist?).with(File.join(Chef::Config[:environment_path], "foo.rb")).exactly(1).times.and_return(true)
407
407
  expect(File).to receive(:readable?).with(File.join(Chef::Config[:environment_path], "foo.rb")).and_return(true)
408
408
  expect(File).to receive(:file?).with(File.join(Chef::Config[:environment_path], "foo.rb")).and_return(true)
409
409
  role_dsl = "name \"foo\"\ndescription \"desc\"\n"
@@ -413,7 +413,7 @@ describe Chef::Environment do
413
413
 
414
414
  it "should return a Chef::Environment object from JSON" do
415
415
  expect(File).to receive(:directory?).with(Chef::Config[:environment_path]).and_return(true)
416
- expect(File).to receive(:exists?).with(File.join(Chef::Config[:environment_path], "foo.json")).and_return(true)
416
+ expect(File).to receive(:exist?).with(File.join(Chef::Config[:environment_path], "foo.json")).and_return(true)
417
417
  environment_hash = {
418
418
  "name" => "foo",
419
419
  "default_attributes" => {
@@ -436,8 +436,8 @@ describe Chef::Environment do
436
436
 
437
437
  it "should return a Chef::Environment object from Ruby DSL" do
438
438
  expect(File).to receive(:directory?).with(Chef::Config[:environment_path]).and_return(true)
439
- expect(File).to receive(:exists?).with(File.join(Chef::Config[:environment_path], "foo.json")).and_return(false)
440
- expect(File).to receive(:exists?).with(File.join(Chef::Config[:environment_path], "foo.rb")).exactly(1).times.and_return(true)
439
+ expect(File).to receive(:exist?).with(File.join(Chef::Config[:environment_path], "foo.json")).and_return(false)
440
+ expect(File).to receive(:exist?).with(File.join(Chef::Config[:environment_path], "foo.rb")).exactly(1).times.and_return(true)
441
441
  expect(File).to receive(:readable?).with(File.join(Chef::Config[:environment_path], "foo.rb")).and_return(true)
442
442
  expect(File).to receive(:file?).with(File.join(Chef::Config[:environment_path], "foo.rb")).and_return(true)
443
443
  role_dsl = "name \"foo\"\ndescription \"desc\"\n"
@@ -459,8 +459,8 @@ describe Chef::Environment do
459
459
 
460
460
  it "should raise an error if the file does not exist" do
461
461
  expect(File).to receive(:directory?).with(Chef::Config[:environment_path]).and_return(true)
462
- expect(File).to receive(:exists?).with(File.join(Chef::Config[:environment_path], "foo.json")).and_return(false)
463
- expect(File).to receive(:exists?).with(File.join(Chef::Config[:environment_path], "foo.rb")).and_return(false)
462
+ expect(File).to receive(:exist?).with(File.join(Chef::Config[:environment_path], "foo.json")).and_return(false)
463
+ expect(File).to receive(:exist?).with(File.join(Chef::Config[:environment_path], "foo.rb")).and_return(false)
464
464
 
465
465
  expect do
466
466
  Chef::Environment.load("foo")
@@ -61,6 +61,7 @@ describe Chef::EventDispatch::Dispatcher do
61
61
  let(:event_sink) do
62
62
  Class.new(Chef::EventDispatch::Base) do
63
63
  attr_reader :synchronized_cookbook_args
64
+
64
65
  def synchronized_cookbook(cookbook_name)
65
66
  @synchronized_cookbook_args = [cookbook_name]
66
67
  end
@@ -79,6 +80,7 @@ describe Chef::EventDispatch::Dispatcher do
79
80
  let(:event_sink_1) do
80
81
  Class.new(Chef::EventDispatch::Base) do
81
82
  attr_reader :synchronized_cookbook_args
83
+
82
84
  def synchronized_cookbook(cookbook_name)
83
85
  @synchronized_cookbook_args = [cookbook_name]
84
86
  end
@@ -87,6 +89,7 @@ describe Chef::EventDispatch::Dispatcher do
87
89
  let(:event_sink_2) do
88
90
  Class.new(Chef::EventDispatch::Base) do
89
91
  attr_reader :synchronized_cookbook_args
92
+
90
93
  def synchronized_cookbook(cookbook_name, cookbook)
91
94
  @synchronized_cookbook_args = [cookbook_name, cookbook]
92
95
  end
@@ -206,7 +206,7 @@ describe Chef::Knife::Bootstrap do
206
206
  end
207
207
 
208
208
  before(:each) do
209
- expect(File).to receive(:exists?).with(bootstrap_template).and_return(false)
209
+ expect(File).to receive(:exist?).with(bootstrap_template).and_return(false)
210
210
  end
211
211
 
212
212
  context "when file is available everywhere" do
@@ -215,7 +215,7 @@ describe Chef::Knife::Bootstrap do
215
215
  configure_env_home
216
216
  configure_gem_files
217
217
 
218
- expect(File).to receive(:exists?).with(builtin_template_path).and_return(true)
218
+ expect(File).to receive(:exist?).with(builtin_template_path).and_return(true)
219
219
  end
220
220
 
221
221
  it "should load the template from built-in templates" do
@@ -229,8 +229,8 @@ describe Chef::Knife::Bootstrap do
229
229
  configure_env_home
230
230
  configure_gem_files
231
231
 
232
- expect(File).to receive(:exists?).with(builtin_template_path).and_return(false)
233
- expect(File).to receive(:exists?).with(chef_config_dir_template_path).and_return(true)
232
+ expect(File).to receive(:exist?).with(builtin_template_path).and_return(false)
233
+ expect(File).to receive(:exist?).with(chef_config_dir_template_path).and_return(true)
234
234
 
235
235
  it "should load the template from chef_config_dir" do
236
236
  knife.find_template.should eq(chef_config_dir_template_path)
@@ -244,9 +244,9 @@ describe Chef::Knife::Bootstrap do
244
244
  configure_env_home
245
245
  configure_gem_files
246
246
 
247
- expect(File).to receive(:exists?).with(builtin_template_path).and_return(false)
248
- expect(File).to receive(:exists?).with(chef_config_dir_template_path).and_return(false)
249
- expect(File).to receive(:exists?).with(env_home_template_path).and_return(true)
247
+ expect(File).to receive(:exist?).with(builtin_template_path).and_return(false)
248
+ expect(File).to receive(:exist?).with(chef_config_dir_template_path).and_return(false)
249
+ expect(File).to receive(:exist?).with(env_home_template_path).and_return(true)
250
250
  end
251
251
 
252
252
  it "should load the template from chef_config_dir" do
@@ -260,10 +260,10 @@ describe Chef::Knife::Bootstrap do
260
260
  configure_env_home
261
261
  configure_gem_files
262
262
 
263
- expect(File).to receive(:exists?).with(builtin_template_path).and_return(false)
264
- expect(File).to receive(:exists?).with(chef_config_dir_template_path).and_return(false)
265
- expect(File).to receive(:exists?).with(env_home_template_path).and_return(false)
266
- expect(File).to receive(:exists?).with(gem_files_template_path).and_return(true)
263
+ expect(File).to receive(:exist?).with(builtin_template_path).and_return(false)
264
+ expect(File).to receive(:exist?).with(chef_config_dir_template_path).and_return(false)
265
+ expect(File).to receive(:exist?).with(env_home_template_path).and_return(false)
266
+ expect(File).to receive(:exist?).with(gem_files_template_path).and_return(true)
267
267
  end
268
268
 
269
269
  it "should load the template from Gem files" do
@@ -277,9 +277,9 @@ describe Chef::Knife::Bootstrap do
277
277
  configure_gem_files
278
278
  allow(Chef::Util::PathHelper).to receive(:home).with(".chef", "bootstrap", "example.erb").and_return(nil)
279
279
 
280
- expect(File).to receive(:exists?).with(builtin_template_path).and_return(false)
281
- expect(File).to receive(:exists?).with(chef_config_dir_template_path).and_return(false)
282
- expect(File).to receive(:exists?).with(gem_files_template_path).and_return(true)
280
+ expect(File).to receive(:exist?).with(builtin_template_path).and_return(false)
281
+ expect(File).to receive(:exist?).with(chef_config_dir_template_path).and_return(false)
282
+ expect(File).to receive(:exist?).with(gem_files_template_path).and_return(true)
283
283
  end
284
284
 
285
285
  it "should load the template from Gem files" do
@@ -94,7 +94,7 @@ describe Chef::Knife::CookbookDownload do
94
94
  let (:manifest_data) { { all_files: [] } }
95
95
  it "should determine which version to download" do
96
96
  expect(@knife).to receive(:determine_version).and_return("1.0.0")
97
- expect(File).to receive(:exists?).with("/var/tmp/chef/foobar-1.0.0").and_return(false)
97
+ expect(File).to receive(:exist?).with("/var/tmp/chef/foobar-1.0.0").and_return(false)
98
98
  @knife.run
99
99
  end
100
100
  end
@@ -111,7 +111,7 @@ describe Chef::Knife::CookbookDownload do
111
111
  end
112
112
 
113
113
  it "should print an error and exit if the cookbook download directory already exists" do
114
- expect(File).to receive(:exists?).with("/var/tmp/chef/foobar-1.0.0").and_return(true)
114
+ expect(File).to receive(:exist?).with("/var/tmp/chef/foobar-1.0.0").and_return(true)
115
115
  expect(@knife.ui).to receive(:fatal).with(%r{/var/tmp/chef/foobar-1\.0\.0 exists}i)
116
116
  expect { @knife.run }.to raise_error(SystemExit)
117
117
  end
@@ -135,7 +135,7 @@ describe Chef::Knife::CookbookDownload do
135
135
  end
136
136
 
137
137
  it "should download the cookbook when the cookbook download directory doesn't exist" do
138
- expect(File).to receive(:exists?).with("/var/tmp/chef/foobar-1.0.0").and_return(false)
138
+ expect(File).to receive(:exist?).with("/var/tmp/chef/foobar-1.0.0").and_return(false)
139
139
  @knife.run
140
140
  %w{attributes recipes templates}.each do |segment|
141
141
  expect(@stderr.string).to match /downloading #{segment}/im
@@ -147,7 +147,7 @@ describe Chef::Knife::CookbookDownload do
147
147
  describe "with -f or --force" do
148
148
  it "should remove the existing the cookbook download directory if it exists" do
149
149
  @knife.config[:force] = true
150
- expect(File).to receive(:exists?).with("/var/tmp/chef/foobar-1.0.0").and_return(true)
150
+ expect(File).to receive(:exist?).with("/var/tmp/chef/foobar-1.0.0").and_return(true)
151
151
  expect(FileUtils).to receive(:rm_rf).with("/var/tmp/chef/foobar-1.0.0")
152
152
  @knife.run
153
153
  end
@@ -34,7 +34,7 @@ describe Chef::Knife::CookbookMetadataFromFile do
34
34
  end
35
35
 
36
36
  after do
37
- if File.exists?(@tgt)
37
+ if File.exist?(@tgt)
38
38
  File.unlink(@tgt)
39
39
  end
40
40
  end
@@ -323,19 +323,18 @@ describe Chef::Knife::CookbookUpload do
323
323
 
324
324
  context "when cookbook path is an array" do
325
325
  it "should warn users that no cookbooks exist" do
326
- knife.config[:cookbook_path] = ["/chef-repo/cookbooks", "/home/user/cookbooks"]
327
- expect(knife.ui).to receive(:warn).with(
328
- /Could not find any cookbooks in your cookbook path: '#{knife.config[:cookbook_path].join(', ')}'\. Use --cookbook-path to specify the desired path\./
329
- )
326
+ cookbook_path = windows? ? "C:/chef-repo/cookbooks" : "/chef-repo/cookbooks"
327
+ knife.config[:cookbook_path] = [cookbook_path, "/home/user/cookbooks"]
328
+ expect(knife.ui).to receive(:warn).with("Could not find any cookbooks in your cookbook path: '#{knife.config[:cookbook_path].join(", ")}'. Use --cookbook-path to specify the desired path.")
330
329
  knife.run
331
330
  end
332
331
  end
333
332
 
334
333
  context "when cookbook path is a string" do
335
334
  it "should warn users that no cookbooks exist" do
336
- knife.config[:cookbook_path] = "/chef-repo/cookbooks"
335
+ knife.config[:cookbook_path] = windows? ? "C:/chef-repo/cookbooks" : "/chef-repo/cookbooks"
337
336
  expect(knife.ui).to receive(:warn).with(
338
- /Could not find any cookbooks in your cookbook path: '#{knife.config[:cookbook_path]}'\. Use --cookbook-path to specify the desired path\./
337
+ "Could not find any cookbooks in your cookbook path: '#{knife.config[:cookbook_path]}'. Use --cookbook-path to specify the desired path."
339
338
  )
340
339
  knife.run
341
340
  end
@@ -50,7 +50,7 @@ describe Chef::Knife::SubcommandLoader::HashedCommandLoader do
50
50
 
51
51
  describe "#list_commands" do
52
52
  before do
53
- allow(File).to receive(:exists?).and_return(true)
53
+ allow(File).to receive(:exist?).and_return(true)
54
54
  end
55
55
 
56
56
  it "lists all commands by category when no argument is given" do
@@ -63,7 +63,7 @@ describe Chef::Knife::SubcommandLoader::HashedCommandLoader do
63
63
 
64
64
  context "when the plugin path is invalid" do
65
65
  before do
66
- expect(File).to receive(:exists?).with("/file/for/plugin/b").and_return(false)
66
+ expect(File).to receive(:exist?).with("/file/for/plugin/b").and_return(false)
67
67
  end
68
68
 
69
69
  it "lists all commands by category when no argument is given" do
@@ -90,7 +90,7 @@ describe Chef::Knife::SubcommandLoader::HashedCommandLoader do
90
90
  end
91
91
 
92
92
  it "loads the correct file and returns true if the command exists" do
93
- allow(File).to receive(:exists?).and_return(true)
93
+ allow(File).to receive(:exist?).and_return(true)
94
94
  expect(Kernel).to receive(:load).with("/file/for/plugin/a").and_return(true)
95
95
  expect(loader.load_command(["cool_a"])).to eq(true)
96
96
  end
@@ -279,10 +279,10 @@ describe Chef::Knife::Ssh do
279
279
  end
280
280
 
281
281
  describe "#ssh_command" do
282
- let(:execution_channel) { double(:execution_channel, on_data: nil) }
282
+ let(:execution_channel) { double(:execution_channel, on_data: nil, on_extended_data: nil) }
283
283
  let(:session_channel) { double(:session_channel, request_pty: nil) }
284
284
 
285
- let(:execution_channel2) { double(:execution_channel, on_data: nil) }
285
+ let(:execution_channel2) { double(:execution_channel, on_data: nil, on_extended_data: nil) }
286
286
  let(:session_channel2) { double(:session_channel, request_pty: nil) }
287
287
 
288
288
  let(:session) { double(:session, loop: nil) }
@@ -108,7 +108,7 @@ describe Chef::Knife::SupermarketShare do
108
108
  expect { @knife.run }.to raise_error(SystemExit)
109
109
  end
110
110
 
111
- if File.exists?("/usr/bin/gnutar") || File.exists?("/bin/gnutar")
111
+ if File.exist?("/usr/bin/gnutar") || File.exist?("/bin/gnutar")
112
112
  it "should use gnutar to make a tarball of the cookbook" do
113
113
  expect(@knife).to receive(:shell_out!) do |args|
114
114
  expect(args.to_s).to match(/gnutar -czf/)
@@ -140,7 +140,9 @@ describe Chef::Knife::SupermarketShare do
140
140
  before do
141
141
  allow(Chef::CookbookSiteStreamingUploader).to receive(:create_build_dir).and_return("/var/tmp/dummy")
142
142
  @knife.config = { dry_run: true }
143
- allow(@knife).to receive_message_chain(:shell_out!, :stdout).and_return("file")
143
+ @so = instance_double("Mixlib::ShellOut")
144
+ allow(@knife).to receive(:shell_out!).and_return(@so)
145
+ allow(@so).to receive(:stdout).and_return("file")
144
146
  end
145
147
 
146
148
  it "should list files in the tarball" do
@@ -151,7 +153,7 @@ describe Chef::Knife::SupermarketShare do
151
153
  end
152
154
 
153
155
  it "does not upload the cookbook" do
154
- allow(@knife).to receive(:shell_out!).and_return(true)
156
+ allow(@knife).to receive(:shell_out!).and_return(@so)
155
157
  expect(@knife).not_to receive(:do_upload)
156
158
  @knife.run
157
159
  end
@@ -140,7 +140,7 @@ describe "LWRP" do
140
140
  before do
141
141
  @tmpdir = Dir.mktmpdir("lwrp_test")
142
142
  @lwrp_path = File.join(@tmpdir, "foo.rb")
143
- content = IO.read(File.expand_path("../../data/lwrp/resources/foo.rb", __FILE__))
143
+ content = IO.read(File.expand_path("../data/lwrp/resources/foo.rb", __dir__))
144
144
  IO.write(@lwrp_path, content)
145
145
  Chef::Resource::LWRPBase.build_from_file("lwrp", @lwrp_path, nil)
146
146
  @original_resource = Chef::ResourceResolver.resolve(:lwrp_foo)
@@ -152,7 +152,7 @@ describe "LWRP" do
152
152
 
153
153
  context "And the LWRP is asked to load again, this time with different code" do
154
154
  before do
155
- content = IO.read(File.expand_path("../../data/lwrp_override/resources/foo.rb", __FILE__))
155
+ content = IO.read(File.expand_path("../data/lwrp_override/resources/foo.rb", __dir__))
156
156
  IO.write(@lwrp_path, content)
157
157
  Chef::Resource::LWRPBase.build_from_file("lwrp", @lwrp_path, nil)
158
158
  end
@@ -390,11 +390,11 @@ describe "LWRP" do
390
390
  end
391
391
 
392
392
  before(:each) do
393
- Dir[File.expand_path(File.expand_path("../../data/lwrp/resources/*", __FILE__))].each do |file|
393
+ Dir[File.expand_path(File.expand_path("../data/lwrp/resources/*", __dir__))].each do |file|
394
394
  Chef::Resource::LWRPBase.build_from_file(lwrp_cookbook_name, file, run_context)
395
395
  end
396
396
 
397
- Dir[File.expand_path(File.expand_path("../../data/lwrp/providers/*", __FILE__))].each do |file|
397
+ Dir[File.expand_path(File.expand_path("../data/lwrp/providers/*", __dir__))].each do |file|
398
398
  Chef::Provider::LWRPBase.build_from_file(lwrp_cookbook_name, file, run_context)
399
399
  end
400
400
  end
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  #
3
2
  # Author:: Mark Mzyk (<mmzyk@chef.io>)
4
3
  # Copyright:: Copyright (c) Chef Software Inc.