summaryrefslogtreecommitdiff
path: root/spec/unit/provider/service/macosx_spec.rb
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2014-10-24 18:12:50 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2014-10-24 18:12:50 -0700
commitbd0b0a34e4dbb60fe61bbc8716df90e8f7c7d19a (patch)
treeacc7a2d09b2cec8eed863218c0400cd15cd27854 /spec/unit/provider/service/macosx_spec.rb
parentbdce1c5619fde7d277262df9336e06f73e4fc3f8 (diff)
downloadchef-bd0b0a34e4dbb60fe61bbc8716df90e8f7c7d19a.tar.gz
updating resources/providers unit tests to rpsec3
mechanically generated patch using transpec 2.3.7 gem
Diffstat (limited to 'spec/unit/provider/service/macosx_spec.rb')
-rw-r--r--spec/unit/provider/service/macosx_spec.rb98
1 files changed, 49 insertions, 49 deletions
diff --git a/spec/unit/provider/service/macosx_spec.rb b/spec/unit/provider/service/macosx_spec.rb
index c5df1e0637..0d31ae2ffb 100644
--- a/spec/unit/provider/service/macosx_spec.rb
+++ b/spec/unit/provider/service/macosx_spec.rb
@@ -22,21 +22,21 @@ describe Chef::Provider::Service::Macosx do
describe ".gather_plist_dirs" do
context "when HOME directory is set" do
before do
- ENV.stub(:[]).with('HOME').and_return("/User/someuser")
+ allow(ENV).to receive(:[]).with('HOME').and_return("/User/someuser")
end
it "includes users's LaunchAgents folder" do
- described_class.gather_plist_dirs.should include("#{ENV['HOME']}/Library/LaunchAgents")
+ expect(described_class.gather_plist_dirs).to include("#{ENV['HOME']}/Library/LaunchAgents")
end
end
context "when HOME directory is not set" do
before do
- ENV.stub(:[]).with('HOME').and_return(nil)
+ allow(ENV).to receive(:[]).with('HOME').and_return(nil)
end
it "doesn't include user's LaunchAgents folder" do
- described_class.gather_plist_dirs.should_not include("~/Library/LaunchAgents")
+ expect(described_class.gather_plist_dirs).not_to include("~/Library/LaunchAgents")
end
end
end
@@ -60,20 +60,20 @@ XML
["redis-server", "io.redis.redis-server"].each do |service_name|
before do
- Dir.stub(:glob).and_return(["/Users/igor/Library/LaunchAgents/io.redis.redis-server.plist"], [])
- provider.stub(:shell_out!).
+ allow(Dir).to receive(:glob).and_return(["/Users/igor/Library/LaunchAgents/io.redis.redis-server.plist"], [])
+ allow(provider).to receive(:shell_out!).
with("launchctl list", {:group => 1001, :user => 101}).
and_return(double("Status", :stdout => launchctl_stdout))
- provider.stub(:shell_out).
+ allow(provider).to receive(:shell_out).
with(/launchctl list /,
{:group => nil, :user => nil}).
and_return(double("Status",
:stdout => launchctl_stdout, :exitstatus => 0))
- provider.stub(:shell_out!).
+ allow(provider).to receive(:shell_out!).
with(/plutil -convert xml1 -o/).
and_return(double("Status", :stdout => plutil_stdout))
- File.stub(:stat).and_return(double("stat", :gid => 1001, :uid => 101))
+ allow(File).to receive(:stat).and_return(double("stat", :gid => 1001, :uid => 101))
end
context "#{service_name}" do
@@ -95,26 +95,26 @@ XML
end
before do
- Dir.stub(:glob).and_return([])
- provider.stub(:shell_out!).
+ allow(Dir).to receive(:glob).and_return([])
+ allow(provider).to receive(:shell_out!).
with(/plutil -convert xml1 -o/).
and_raise(Mixlib::ShellOut::ShellCommandFailed)
end
it "works for action :nothing" do
- lambda { run_resource_setup_for_action(:nothing) }.should_not raise_error
+ expect { run_resource_setup_for_action(:nothing) }.not_to raise_error
end
it "works for action :start" do
- lambda { run_resource_setup_for_action(:start) }.should_not raise_error
+ expect { run_resource_setup_for_action(:start) }.not_to raise_error
end
it "errors if action is :enable" do
- lambda { run_resource_setup_for_action(:enable) }.should raise_error(Chef::Exceptions::Service)
+ expect { run_resource_setup_for_action(:enable) }.to raise_error(Chef::Exceptions::Service)
end
it "errors if action is :disable" do
- lambda { run_resource_setup_for_action(:disable) }.should raise_error(Chef::Exceptions::Service)
+ expect { run_resource_setup_for_action(:disable) }.to raise_error(Chef::Exceptions::Service)
end
end
@@ -130,11 +130,11 @@ XML
end
it "sets resource running state to true" do
- provider.current_resource.running.should be_true
+ expect(provider.current_resource.running).to be_true
end
it "sets resouce enabled state to true" do
- provider.current_resource.enabled.should be_true
+ expect(provider.current_resource.enabled).to be_true
end
end
@@ -146,10 +146,10 @@ XML
SVC_LIST
before do
- Dir.stub(:glob).and_return(["/Users/igor/Library/LaunchAgents/io.redis.redis-server.plist"], [])
+ allow(Dir).to receive(:glob).and_return(["/Users/igor/Library/LaunchAgents/io.redis.redis-server.plist"], [])
end
it "should throw an exception when reload action is attempted" do
- lambda {provider.run_action(:reload)}.should raise_error(Chef::Exceptions::UnsupportedAction)
+ expect {provider.run_action(:reload)}.to raise_error(Chef::Exceptions::UnsupportedAction)
end
end
context "when launchctl returns empty service pid" do
@@ -164,11 +164,11 @@ SVC_LIST
end
it "sets resource running state to false" do
- provider.current_resource.running.should be_false
+ expect(provider.current_resource.running).to be_false
end
it "sets resouce enabled state to true" do
- provider.current_resource.enabled.should be_true
+ expect(provider.current_resource.enabled).to be_true
end
end
@@ -180,65 +180,65 @@ SVC_LIST
it "sets service running state to false" do
provider.load_current_resource
- provider.current_resource.running.should be_false
+ expect(provider.current_resource.running).to be_false
end
context "and plist for service is not available" do
before do
- Dir.stub(:glob).and_return([])
+ allow(Dir).to receive(:glob).and_return([])
provider.load_current_resource
end
it "sets resouce enabled state to false" do
- provider.current_resource.enabled.should be_false
+ expect(provider.current_resource.enabled).to be_false
end
end
context "and plist for service is available" do
before do
- Dir.stub(:glob).and_return(["/Users/igor/Library/LaunchAgents/io.redis.redis-server.plist"], [])
+ allow(Dir).to receive(:glob).and_return(["/Users/igor/Library/LaunchAgents/io.redis.redis-server.plist"], [])
provider.load_current_resource
end
it "sets resouce enabled state to true" do
- provider.current_resource.enabled.should be_true
+ expect(provider.current_resource.enabled).to be_true
end
end
describe "and several plists match service name" do
it "throws exception" do
- Dir.stub(:glob).and_return(["/Users/igor/Library/LaunchAgents/io.redis.redis-server.plist",
+ allow(Dir).to receive(:glob).and_return(["/Users/igor/Library/LaunchAgents/io.redis.redis-server.plist",
"/Users/wtf/something.plist"])
provider.load_current_resource
provider.define_resource_requirements
- lambda { provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Service)
+ expect { provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service)
end
end
end
end
describe "#start_service" do
before do
- Chef::Resource::Service.stub(:new).and_return(current_resource)
+ allow(Chef::Resource::Service).to receive(:new).and_return(current_resource)
provider.load_current_resource
- current_resource.stub(:running).and_return(false)
+ allow(current_resource).to receive(:running).and_return(false)
end
it "calls the start command if one is specified and service is not running" do
- new_resource.stub(:start_command).and_return("cowsay dirty")
+ allow(new_resource).to receive(:start_command).and_return("cowsay dirty")
- provider.should_receive(:shell_out_with_systems_locale!).with("cowsay dirty")
+ expect(provider).to receive(:shell_out_with_systems_locale!).with("cowsay dirty")
provider.start_service
end
it "shows warning message if service is already running" do
- current_resource.stub(:running).and_return(true)
- Chef::Log.should_receive(:debug).with("service[#{service_name}] already running, not starting")
+ allow(current_resource).to receive(:running).and_return(true)
+ expect(Chef::Log).to receive(:debug).with("service[#{service_name}] already running, not starting")
provider.start_service
end
it "starts service via launchctl if service found" do
- provider.should_receive(:shell_out_with_systems_locale!).
+ expect(provider).to receive(:shell_out_with_systems_locale!).
with("launchctl load -w '/Users/igor/Library/LaunchAgents/io.redis.redis-server.plist'",
:group => 1001, :user => 101).
and_return(0)
@@ -249,28 +249,28 @@ SVC_LIST
describe "#stop_service" do
before do
- Chef::Resource::Service.stub(:new).and_return(current_resource)
+ allow(Chef::Resource::Service).to receive(:new).and_return(current_resource)
provider.load_current_resource
- current_resource.stub(:running).and_return(true)
+ allow(current_resource).to receive(:running).and_return(true)
end
it "calls the stop command if one is specified and service is running" do
- new_resource.stub(:stop_command).and_return("kill -9 123")
+ allow(new_resource).to receive(:stop_command).and_return("kill -9 123")
- provider.should_receive(:shell_out_with_systems_locale!).with("kill -9 123")
+ expect(provider).to receive(:shell_out_with_systems_locale!).with("kill -9 123")
provider.stop_service
end
it "shows warning message if service is not running" do
- current_resource.stub(:running).and_return(false)
- Chef::Log.should_receive(:debug).with("service[#{service_name}] not running, not stopping")
+ allow(current_resource).to receive(:running).and_return(false)
+ expect(Chef::Log).to receive(:debug).with("service[#{service_name}] not running, not stopping")
provider.stop_service
end
it "stops the service via launchctl if service found" do
- provider.should_receive(:shell_out_with_systems_locale!).
+ expect(provider).to receive(:shell_out_with_systems_locale!).
with("launchctl unload '/Users/igor/Library/LaunchAgents/io.redis.redis-server.plist'",
:group => 1001, :user => 101).
and_return(0)
@@ -281,23 +281,23 @@ SVC_LIST
describe "#restart_service" do
before do
- Chef::Resource::Service.stub(:new).and_return(current_resource)
+ allow(Chef::Resource::Service).to receive(:new).and_return(current_resource)
provider.load_current_resource
- current_resource.stub(:running).and_return(true)
- provider.stub(:sleep)
+ allow(current_resource).to receive(:running).and_return(true)
+ allow(provider).to receive(:sleep)
end
it "issues a command if given" do
- new_resource.stub(:restart_command).and_return("reload that thing")
+ allow(new_resource).to receive(:restart_command).and_return("reload that thing")
- provider.should_receive(:shell_out_with_systems_locale!).with("reload that thing")
+ expect(provider).to receive(:shell_out_with_systems_locale!).with("reload that thing")
provider.restart_service
end
it "stops and then starts service" do
- provider.should_receive(:stop_service)
- provider.should_receive(:start_service);
+ expect(provider).to receive(:stop_service)
+ expect(provider).to receive(:start_service);
provider.restart_service
end