summaryrefslogtreecommitdiff
path: root/spec/unit/provider/group/dscl_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/group/dscl_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/group/dscl_spec.rb')
-rw-r--r--spec/unit/provider/group/dscl_spec.rb122
1 files changed, 61 insertions, 61 deletions
diff --git a/spec/unit/provider/group/dscl_spec.rb b/spec/unit/provider/group/dscl_spec.rb
index f2b602ee97..acd1ba3859 100644
--- a/spec/unit/provider/group/dscl_spec.rb
+++ b/spec/unit/provider/group/dscl_spec.rb
@@ -32,64 +32,64 @@ describe Chef::Provider::Group::Dscl do
@stdin = StringIO.new
@stdout = StringIO.new("\n")
@stderr = StringIO.new("")
- @provider.stub(:popen4).and_yield(@pid,@stdin,@stdout,@stderr).and_return(@status)
+ allow(@provider).to receive(:popen4).and_yield(@pid,@stdin,@stdout,@stderr).and_return(@status)
end
it "should run popen4 with the supplied array of arguments appended to the dscl command" do
- @provider.should_receive(:popen4).with("dscl . -cmd /Path arg1 arg2")
+ expect(@provider).to receive(:popen4).with("dscl . -cmd /Path arg1 arg2")
@provider.dscl("cmd", "/Path", "arg1", "arg2")
end
it "should return an array of four elements - cmd, status, stdout, stderr" do
dscl_retval = @provider.dscl("cmd /Path args")
- dscl_retval.should be_a_kind_of(Array)
- dscl_retval.should == ["dscl . -cmd /Path args",@status,"\n",""]
+ expect(dscl_retval).to be_a_kind_of(Array)
+ expect(dscl_retval).to eq(["dscl . -cmd /Path args",@status,"\n",""])
end
describe "safe_dscl" do
before do
@node = Chef::Node.new
@provider = Chef::Provider::Group::Dscl.new(@node, @new_resource)
- @provider.stub(:dscl).and_return(["cmd", @status, "stdout", "stderr"])
+ allow(@provider).to receive(:dscl).and_return(["cmd", @status, "stdout", "stderr"])
end
it "should run dscl with the supplied cmd /Path args" do
- @provider.should_receive(:dscl).with("cmd /Path args")
+ expect(@provider).to receive(:dscl).with("cmd /Path args")
@provider.safe_dscl("cmd /Path args")
end
describe "with the dscl command returning a non zero exit status for a delete" do
before do
@status = double("Process::Status", :exitstatus => 1)
- @provider.stub(:dscl).and_return(["cmd", @status, "stdout", "stderr"])
+ allow(@provider).to receive(:dscl).and_return(["cmd", @status, "stdout", "stderr"])
end
it "should return an empty string of standard output for a delete" do
safe_dscl_retval = @provider.safe_dscl("delete /Path args")
- safe_dscl_retval.should be_a_kind_of(String)
- safe_dscl_retval.should == ""
+ expect(safe_dscl_retval).to be_a_kind_of(String)
+ expect(safe_dscl_retval).to eq("")
end
it "should raise an exception for any other command" do
- lambda { @provider.safe_dscl("cmd /Path arguments") }.should raise_error(Chef::Exceptions::Group)
+ expect { @provider.safe_dscl("cmd /Path arguments") }.to raise_error(Chef::Exceptions::Group)
end
end
describe "with the dscl command returning no such key" do
before do
- @provider.stub(:dscl).and_return(["cmd", @status, "No such key: ", "stderr"])
+ allow(@provider).to receive(:dscl).and_return(["cmd", @status, "No such key: ", "stderr"])
end
it "should raise an exception" do
- lambda { @provider.safe_dscl("cmd /Path arguments") }.should raise_error(Chef::Exceptions::Group)
+ expect { @provider.safe_dscl("cmd /Path arguments") }.to raise_error(Chef::Exceptions::Group)
end
end
describe "with the dscl command returning a zero exit status" do
it "should return the third array element, the string of standard output" do
safe_dscl_retval = @provider.safe_dscl("cmd /Path args")
- safe_dscl_retval.should be_a_kind_of(String)
- safe_dscl_retval.should == "stdout"
+ expect(safe_dscl_retval).to be_a_kind_of(String)
+ expect(safe_dscl_retval).to eq("stdout")
end
end
end
@@ -98,21 +98,21 @@ describe Chef::Provider::Group::Dscl do
before do
@node = Chef::Node.new
@provider = Chef::Provider::Group::Dscl.new(@node, @new_resource)
- @provider.stub(:safe_dscl).and_return("\naj 200\njt 201\n")
+ allow(@provider).to receive(:safe_dscl).and_return("\naj 200\njt 201\n")
end
it "should run safe_dscl with list /Groups gid" do
- @provider.should_receive(:safe_dscl).with("list /Groups gid")
+ expect(@provider).to receive(:safe_dscl).with("list /Groups gid")
@provider.get_free_gid
end
it "should return the first unused gid number on or above 200" do
- @provider.get_free_gid.should equal(202)
+ expect(@provider.get_free_gid).to equal(202)
end
it "should raise an exception when the search limit is exhausted" do
search_limit = 1
- lambda { @provider.get_free_gid(search_limit) }.should raise_error(RuntimeError)
+ expect { @provider.get_free_gid(search_limit) }.to raise_error(RuntimeError)
end
end
@@ -120,41 +120,41 @@ describe Chef::Provider::Group::Dscl do
before do
@node = Chef::Node.new
@provider = Chef::Provider::Group::Dscl.new(@node, @new_resource)
- @provider.stub(:safe_dscl).and_return("\naj 500\n")
+ allow(@provider).to receive(:safe_dscl).and_return("\naj 500\n")
end
it "should run safe_dscl with list /Groups gid" do
- @provider.should_receive(:safe_dscl).with("list /Groups gid")
+ expect(@provider).to receive(:safe_dscl).with("list /Groups gid")
@provider.gid_used?(500)
end
it "should return true for a used gid number" do
- @provider.gid_used?(500).should be_true
+ expect(@provider.gid_used?(500)).to be_true
end
it "should return false for an unused gid number" do
- @provider.gid_used?(501).should be_false
+ expect(@provider.gid_used?(501)).to be_false
end
it "should return false if not given any valid gid number" do
- @provider.gid_used?(nil).should be_false
+ expect(@provider.gid_used?(nil)).to be_false
end
end
describe "set_gid" do
describe "with the new resource and a gid number which is already in use" do
before do
- @provider.stub(:gid_used?).and_return(true)
+ allow(@provider).to receive(:gid_used?).and_return(true)
end
it "should raise an exception if the new resources gid is already in use" do
- lambda { @provider.set_gid }.should raise_error(Chef::Exceptions::Group)
+ expect { @provider.set_gid }.to raise_error(Chef::Exceptions::Group)
end
end
describe "with no gid number for the new resources" do
it "should run get_free_gid and return a valid, unused gid number" do
- @provider.should_receive(:get_free_gid).and_return(501)
+ expect(@provider).to receive(:get_free_gid).and_return(501)
@provider.set_gid
end
end
@@ -162,20 +162,20 @@ describe Chef::Provider::Group::Dscl do
describe "with blank gid number for the new resources" do
before do
@new_resource.instance_variable_set(:@gid, nil)
- @new_resource.stub(:safe_dscl)
+ allow(@new_resource).to receive(:safe_dscl)
end
it "should run get_free_gid and return a valid, unused gid number" do
- @provider.should_receive(:get_free_gid).and_return(501)
+ expect(@provider).to receive(:get_free_gid).and_return(501)
@provider.set_gid
end
end
describe "with a valid gid number which is not already in use" do
it "should run safe_dscl with create /Groups/group PrimaryGroupID gid" do
- @provider.stub(:get_free_gid).and_return(50)
- @provider.should_receive(:safe_dscl).with("list /Groups gid")
- @provider.should_receive(:safe_dscl).with("create /Groups/aj PrimaryGroupID 50").and_return(true)
+ allow(@provider).to receive(:get_free_gid).and_return(50)
+ expect(@provider).to receive(:safe_dscl).with("list /Groups gid")
+ expect(@provider).to receive(:safe_dscl).with("create /Groups/aj PrimaryGroupID 50").and_return(true)
@provider.set_gid
end
end
@@ -185,19 +185,19 @@ describe Chef::Provider::Group::Dscl do
describe "with existing members in the current resource and append set to false in the new resource" do
before do
- @new_resource.stub(:members).and_return([])
- @new_resource.stub(:append).and_return(false)
- @current_resource.stub(:members).and_return(["all", "your", "base"])
+ allow(@new_resource).to receive(:members).and_return([])
+ allow(@new_resource).to receive(:append).and_return(false)
+ allow(@current_resource).to receive(:members).and_return(["all", "your", "base"])
end
it "should log an appropriate message" do
- Chef::Log.should_receive(:debug).with("group[aj] removing group members all your base")
+ expect(Chef::Log).to receive(:debug).with("group[aj] removing group members all your base")
@provider.set_members
end
it "should run safe_dscl with create /Groups/group GroupMembership to clear the Group's UID list" do
- @provider.should_receive(:safe_dscl).with("create /Groups/aj GroupMembers ''").and_return(true)
- @provider.should_receive(:safe_dscl).with("create /Groups/aj GroupMembership ''").and_return(true)
+ expect(@provider).to receive(:safe_dscl).with("create /Groups/aj GroupMembers ''").and_return(true)
+ expect(@provider).to receive(:safe_dscl).with("create /Groups/aj GroupMembership ''").and_return(true)
@provider.set_members
end
end
@@ -209,14 +209,14 @@ describe Chef::Provider::Group::Dscl do
end
it "should log an appropriate debug message" do
- Chef::Log.should_receive(:debug).with("group[aj] setting group members all, your, base")
+ expect(Chef::Log).to receive(:debug).with("group[aj] setting group members all, your, base")
@provider.set_members
end
it "should run safe_dscl with append /Groups/group GroupMembership and group members all, your, base" do
- @provider.should_receive(:safe_dscl).with("create /Groups/aj GroupMembers ''").and_return(true)
- @provider.should_receive(:safe_dscl).with("append /Groups/aj GroupMembership all your base").and_return(true)
- @provider.should_receive(:safe_dscl).with("create /Groups/aj GroupMembership ''").and_return(true)
+ expect(@provider).to receive(:safe_dscl).with("create /Groups/aj GroupMembers ''").and_return(true)
+ expect(@provider).to receive(:safe_dscl).with("append /Groups/aj GroupMembership all your base").and_return(true)
+ expect(@provider).to receive(:safe_dscl).with("create /Groups/aj GroupMembership ''").and_return(true)
@provider.set_members
end
end
@@ -228,7 +228,7 @@ describe Chef::Provider::Group::Dscl do
end
it "should not call safe_dscl" do
- @provider.should_not_receive(:safe_dscl)
+ expect(@provider).not_to receive(:safe_dscl)
@provider.set_members
end
end
@@ -242,23 +242,23 @@ describe Chef::Provider::Group::Dscl do
end
it "raises an error if the required binary /usr/bin/dscl doesn't exist" do
- File.should_receive(:exists?).with("/usr/bin/dscl").and_return(false)
+ expect(File).to receive(:exists?).with("/usr/bin/dscl").and_return(false)
- lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Group)
+ expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Group)
end
it "doesn't raise an error if /usr/bin/dscl exists" do
- File.stub(:exists?).and_return(true)
- lambda { @provider.process_resource_requirements }.should_not raise_error
+ allow(File).to receive(:exists?).and_return(true)
+ expect { @provider.process_resource_requirements }.not_to raise_error
end
end
describe "when creating the group" do
it "creates the group, password field, gid, and sets group membership" do
- @provider.should_receive(:set_gid).and_return(true)
- @provider.should_receive(:set_members).and_return(true)
- @provider.should_receive(:safe_dscl).with("create /Groups/aj Password '*'")
- @provider.should_receive(:safe_dscl).with("create /Groups/aj")
+ expect(@provider).to receive(:set_gid).and_return(true)
+ expect(@provider).to receive(:set_members).and_return(true)
+ expect(@provider).to receive(:safe_dscl).with("create /Groups/aj Password '*'")
+ expect(@provider).to receive(:safe_dscl).with("create /Groups/aj")
@provider.create_group
end
end
@@ -267,30 +267,30 @@ describe Chef::Provider::Group::Dscl do
it "should manage the group_name if it changed and the new resources group_name is not null" do
@current_resource.group_name("oldval")
@new_resource.group_name("newname")
- @provider.should_receive(:set_members).and_return(true)
- @provider.should_receive(:safe_dscl).with("create /Groups/newname")
- @provider.should_receive(:safe_dscl).with("create /Groups/newname Password '*'")
+ expect(@provider).to receive(:set_members).and_return(true)
+ expect(@provider).to receive(:safe_dscl).with("create /Groups/newname")
+ expect(@provider).to receive(:safe_dscl).with("create /Groups/newname Password '*'")
@provider.manage_group
end
it "should manage the gid if it changed and the new resources gid is not null" do
@current_resource.gid(23)
@new_resource.gid(42)
- @provider.should_receive(:set_gid)
+ expect(@provider).to receive(:set_gid)
@provider.manage_group
end
it "should manage the members if it changed and the new resources members is not null" do
@current_resource.members(%{charlie root})
@new_resource.members(%{crab revenge})
- @provider.should_receive(:set_members)
+ expect(@provider).to receive(:set_members)
@provider.manage_group
end
end
describe "remove_group" do
it "should run safe_dscl with delete /Groups/group and with the new resources group name" do
- @provider.should_receive(:safe_dscl).with("delete /Groups/aj").and_return(true)
+ expect(@provider).to receive(:safe_dscl).with("delete /Groups/aj").and_return(true)
@provider.remove_group
end
end
@@ -318,17 +318,17 @@ RecordName: com.apple.aj
RecordType: dsRecTypeStandard:Groups
GroupMembership: waka bar
EOF
- @provider.stub(:safe_dscl).with("read /Groups/aj").and_return(@output)
+ allow(@provider).to receive(:safe_dscl).with("read /Groups/aj").and_return(@output)
@current_resource = @provider.load_current_resource
end
it 'should parse gid properly' do
- File.stub(:exists?).and_return(true)
- @current_resource.gid.should eq("999")
+ allow(File).to receive(:exists?).and_return(true)
+ expect(@current_resource.gid).to eq("999")
end
it 'should parse members properly' do
- File.stub(:exists?).and_return(true)
- @current_resource.members.should eq(['waka', 'bar'])
+ allow(File).to receive(:exists?).and_return(true)
+ expect(@current_resource.members).to eq(['waka', 'bar'])
end
end