diff options
-rw-r--r-- | lib/chef/provider/service/macosx.rb | 14 | ||||
-rw-r--r-- | spec/unit/provider/service/macosx_spec.rb | 2 |
2 files changed, 11 insertions, 5 deletions
diff --git a/lib/chef/provider/service/macosx.rb b/lib/chef/provider/service/macosx.rb index 4c40c5c865..f6a4c1a9c3 100644 --- a/lib/chef/provider/service/macosx.rb +++ b/lib/chef/provider/service/macosx.rb @@ -79,6 +79,12 @@ class Chef a.failure_message Chef::Exceptions::Service, "Several plist files match service name. Please use full service name." end + requirements.assert(:all_actions) do |a| + a.assertion {::File.exists?(@plist.to_s) } + a.failure_message Chef::Exceptions::Service, + "Could not find plist for #{@new_resource}" + end + requirements.assert(:enable, :disable) do |a| a.assertion { !@service_label.to_s.empty? } a.failure_message Chef::Exceptions::Service, @@ -94,11 +100,6 @@ class Chef @current_resource.running(false) end end - - requirements.assert(:all_actions) do |a| - a.assertion { @plist.nil? ? true : ::File.exists?(@plist) } - a.failure_message Chef::Exceptions::Service, "#{@plist} does not exist" - end end def start_service @@ -209,6 +210,9 @@ class Chef # onto the node yet." return nil if @plist.nil? + # Plist must exist by this point + raise Chef::Exceptions::FileNotFound, "Cannot find #{@plist}!" unless ::File.exists?(@plist) + # Most services have the same internal label as the name of the # plist file. However, there is no rule saying that *has* to be # the case, and some core services (notably, ssh) do not follow diff --git a/spec/unit/provider/service/macosx_spec.rb b/spec/unit/provider/service/macosx_spec.rb index 76301a8129..42d45f09e0 100644 --- a/spec/unit/provider/service/macosx_spec.rb +++ b/spec/unit/provider/service/macosx_spec.rb @@ -81,6 +81,7 @@ XML with(/(#{su_cmd} '#{cmd}'|#{cmd})/). and_return(double("Status", :stdout => launchctl_stdout, :exitstatus => 0)) + allow(File).to receive(:exists?).and_return([true], []) allow(provider).to receive(:shell_out_with_systems_locale!). with(/plutil -convert xml1 -o/). and_return(double("Status", :stdout => plutil_stdout)) @@ -106,6 +107,7 @@ XML before do allow(Dir).to receive(:glob).and_return([]) + allow(File).to receive(:exists?).and_return([true], []) allow(provider).to receive(:shell_out!). with(/plutil -convert xml1 -o/). and_raise(Mixlib::ShellOut::ShellCommandFailed) |