diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2014-10-24 18:12:50 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2014-10-24 18:12:50 -0700 |
commit | bd0b0a34e4dbb60fe61bbc8716df90e8f7c7d19a (patch) | |
tree | acc7a2d09b2cec8eed863218c0400cd15cd27854 /spec/unit/provider/group | |
parent | bdce1c5619fde7d277262df9336e06f73e4fc3f8 (diff) | |
download | chef-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')
-rw-r--r-- | spec/unit/provider/group/dscl_spec.rb | 122 | ||||
-rw-r--r-- | spec/unit/provider/group/gpasswd_spec.rb | 28 | ||||
-rw-r--r-- | spec/unit/provider/group/groupadd_spec.rb | 66 | ||||
-rw-r--r-- | spec/unit/provider/group/groupmod_spec.rb | 46 | ||||
-rw-r--r-- | spec/unit/provider/group/pw_spec.rb | 42 | ||||
-rw-r--r-- | spec/unit/provider/group/usermod_spec.rb | 40 | ||||
-rw-r--r-- | spec/unit/provider/group/windows_spec.rb | 30 |
7 files changed, 187 insertions, 187 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 diff --git a/spec/unit/provider/group/gpasswd_spec.rb b/spec/unit/provider/group/gpasswd_spec.rb index 5bd7fdc569..55d978fa7e 100644 --- a/spec/unit/provider/group/gpasswd_spec.rb +++ b/spec/unit/provider/group/gpasswd_spec.rb @@ -41,14 +41,14 @@ describe Chef::Provider::Group::Gpasswd, "modify_group_members" do # for Chef::Provider::Group - no need to repeat it here. We'll # include only what's specific to this provider. it "should raise an error if the required binary /usr/bin/gpasswd doesn't exist" do - File.stub(:exists?).and_return(true) - File.should_receive(:exists?).with("/usr/bin/gpasswd").and_return(false) - lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Group) + allow(File).to receive(:exists?).and_return(true) + expect(File).to receive(:exists?).with("/usr/bin/gpasswd").and_return(false) + expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Group) end it "shouldn't raise an error if the required binaries exist" 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 @@ -65,8 +65,8 @@ describe Chef::Provider::Group::Gpasswd, "modify_group_members" do end it "logs a message and sets group's members to 'none'" do - Chef::Log.should_receive(:debug).with("group[wheel] setting group members to: none") - @provider.should_receive(:shell_out!).with("gpasswd -M \"\" wheel") + expect(Chef::Log).to receive(:debug).with("group[wheel] setting group members to: none") + expect(@provider).to receive(:shell_out!).with("gpasswd -M \"\" wheel") @provider.modify_group_members end end @@ -78,20 +78,20 @@ describe Chef::Provider::Group::Gpasswd, "modify_group_members" do end it "does not modify group membership" do - @provider.should_not_receive(:shell_out!) + expect(@provider).not_to receive(:shell_out!) @provider.modify_group_members end end describe "when the resource specifies group members" do it "should log an appropriate debug message" do - Chef::Log.should_receive(:debug).with("group[wheel] setting group members to: lobster, rage, fist") - @provider.stub(:shell_out!) + expect(Chef::Log).to receive(:debug).with("group[wheel] setting group members to: lobster, rage, fist") + allow(@provider).to receive(:shell_out!) @provider.modify_group_members end it "should run gpasswd with the members joined by ',' followed by the target group" do - @provider.should_receive(:shell_out!).with("gpasswd -M lobster,rage,fist wheel") + expect(@provider).to receive(:shell_out!).with("gpasswd -M lobster,rage,fist wheel") @provider.modify_group_members end @@ -104,9 +104,9 @@ describe Chef::Provider::Group::Gpasswd, "modify_group_members" do it "should run gpasswd individually for each user when the append option is set" do @new_resource.append(true) - @provider.should_receive(:shell_out!).with("gpasswd -a lobster wheel") - @provider.should_receive(:shell_out!).with("gpasswd -a rage wheel") - @provider.should_receive(:shell_out!).with("gpasswd -a fist wheel") + expect(@provider).to receive(:shell_out!).with("gpasswd -a lobster wheel") + expect(@provider).to receive(:shell_out!).with("gpasswd -a rage wheel") + expect(@provider).to receive(:shell_out!).with("gpasswd -a fist wheel") @provider.modify_group_members end end diff --git a/spec/unit/provider/group/groupadd_spec.rb b/spec/unit/provider/group/groupadd_spec.rb index 793615d04c..94150b7a88 100644 --- a/spec/unit/provider/group/groupadd_spec.rb +++ b/spec/unit/provider/group/groupadd_spec.rb @@ -43,47 +43,47 @@ describe Chef::Provider::Group::Groupadd, "set_options" do field_list.each do |attribute, option| it "should check for differences in #{attribute.to_s} between the current and new resources" do - @new_resource.should_receive(attribute) - @current_resource.should_receive(attribute) + expect(@new_resource).to receive(attribute) + expect(@current_resource).to receive(attribute) @provider.set_options end it "should set the option for #{attribute} if the new resources #{attribute} is not null" do - @new_resource.stub(attribute).and_return("wowaweea") - @provider.set_options.should eql(" #{option} '#{@new_resource.send(attribute)}' #{@new_resource.group_name}") + allow(@new_resource).to receive(attribute).and_return("wowaweea") + expect(@provider.set_options).to eql(" #{option} '#{@new_resource.send(attribute)}' #{@new_resource.group_name}") end end it "should combine all the possible options" do match_string = "" field_list.sort{ |a,b| a[0] <=> b[0] }.each do |attribute, option| - @new_resource.stub(attribute).and_return("hola") + allow(@new_resource).to receive(attribute).and_return("hola") match_string << " #{option} 'hola'" end match_string << " aj" - @provider.set_options.should eql(match_string) + expect(@provider.set_options).to eql(match_string) end describe "when we want to create a system group" do it "should not set groupadd_options '-r' when system is false" do @new_resource.system(false) - @provider.groupadd_options.should_not =~ /-r/ + expect(@provider.groupadd_options).not_to match(/-r/) end it "should set groupadd -r if system is true" do @new_resource.system(true) - @provider.groupadd_options.should == " -r" + expect(@provider.groupadd_options).to eq(" -r") end end describe "when we want to create a non_unique gid group" do it "should not set groupadd_options '-o' when non_unique is false" do @new_resource.non_unique(false) - @provider.groupadd_options.should_not =~ /-o/ + expect(@provider.groupadd_options).not_to match(/-o/) end it "should set groupadd -o if non_unique is true" do @new_resource.non_unique(true) - @provider.groupadd_options.should == " -o" + expect(@provider.groupadd_options).to eq(" -o") end end end @@ -93,19 +93,19 @@ describe Chef::Provider::Group::Groupadd, "create_group" do @node = Chef::Node.new @new_resource = Chef::Resource::Group.new("aj") @provider = Chef::Provider::Group::Groupadd.new(@node, @new_resource) - @provider.stub(:run_command).and_return(true) - @provider.stub(:set_options).and_return(" monkey") - @provider.stub(:groupadd_options).and_return("") - @provider.stub(:modify_group_members).and_return(true) + allow(@provider).to receive(:run_command).and_return(true) + allow(@provider).to receive(:set_options).and_return(" monkey") + allow(@provider).to receive(:groupadd_options).and_return("") + allow(@provider).to receive(:modify_group_members).and_return(true) end it "should run groupadd with the return of set_options" do - @provider.should_receive(:run_command).with({ :command => "groupadd monkey" }).and_return(true) + expect(@provider).to receive(:run_command).with({ :command => "groupadd monkey" }).and_return(true) @provider.create_group end it "should modify the group members" do - @provider.should_receive(:modify_group_members).and_return(true) + expect(@provider).to receive(:modify_group_members).and_return(true) @provider.create_group end end @@ -117,20 +117,20 @@ describe Chef::Provider::Group::Groupadd do @run_context = Chef::RunContext.new(@node, {}, @events) @new_resource = Chef::Resource::Group.new("aj") @provider = Chef::Provider::Group::Groupadd.new(@new_resource, @run_context) - @provider.stub(:run_command).and_return(true) - @provider.stub(:set_options).and_return(" monkey") + allow(@provider).to receive(:run_command).and_return(true) + allow(@provider).to receive(:set_options).and_return(" monkey") end describe "manage group" do it "should run groupmod with the return of set_options" do - @provider.stub(:modify_group_members).and_return(true) - @provider.should_receive(:run_command).with({ :command => "groupmod monkey" }).and_return(true) + allow(@provider).to receive(:modify_group_members).and_return(true) + expect(@provider).to receive(:run_command).with({ :command => "groupmod monkey" }).and_return(true) @provider.manage_group end it "should modify the group members" do - @provider.should_receive(:modify_group_members).and_return(true) + expect(@provider).to receive(:modify_group_members).and_return(true) @provider.manage_group end end @@ -138,36 +138,36 @@ describe Chef::Provider::Group::Groupadd do describe "remove_group" do it "should run groupdel with the new resources group name" do - @provider.should_receive(:run_command).with({ :command => "groupdel aj" }).and_return(true) + expect(@provider).to receive(:run_command).with({ :command => "groupdel aj" }).and_return(true) @provider.remove_group end end [:add_member, :remove_member, :set_members].each do |m| it "should raise an error when calling #{m}" do - lambda { @provider.send(m, [ ]) }.should raise_error(Chef::Exceptions::Group, "you must override #{m} in #{@provider.to_s}") + expect { @provider.send(m, [ ]) }.to raise_error(Chef::Exceptions::Group, "you must override #{m} in #{@provider.to_s}") end end describe "load_current_resource" do before do - File.stub(:exists?).and_return(false) + allow(File).to receive(:exists?).and_return(false) @provider.define_resource_requirements end it "should raise an error if the required binary /usr/sbin/groupadd doesn't exist" do - File.should_receive(:exists?).with("/usr/sbin/groupadd").and_return(false) - lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Group) + expect(File).to receive(:exists?).with("/usr/sbin/groupadd").and_return(false) + expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Group) end it "should raise an error if the required binary /usr/sbin/groupmod doesn't exist" do - File.should_receive(:exists?).with("/usr/sbin/groupadd").and_return(true) - File.should_receive(:exists?).with("/usr/sbin/groupmod").and_return(false) - lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Group) + expect(File).to receive(:exists?).with("/usr/sbin/groupadd").and_return(true) + expect(File).to receive(:exists?).with("/usr/sbin/groupmod").and_return(false) + expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Group) end it "should raise an error if the required binary /usr/sbin/groupdel doesn't exist" do - File.should_receive(:exists?).with("/usr/sbin/groupadd").and_return(true) - File.should_receive(:exists?).with("/usr/sbin/groupmod").and_return(true) - File.should_receive(:exists?).with("/usr/sbin/groupdel").and_return(false) - lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Group) + expect(File).to receive(:exists?).with("/usr/sbin/groupadd").and_return(true) + expect(File).to receive(:exists?).with("/usr/sbin/groupmod").and_return(true) + expect(File).to receive(:exists?).with("/usr/sbin/groupdel").and_return(false) + expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Group) end end diff --git a/spec/unit/provider/group/groupmod_spec.rb b/spec/unit/provider/group/groupmod_spec.rb index 001f9c66e8..496d1e28fa 100644 --- a/spec/unit/provider/group/groupmod_spec.rb +++ b/spec/unit/provider/group/groupmod_spec.rb @@ -33,18 +33,18 @@ describe Chef::Provider::Group::Groupmod do describe "manage_group" do describe "when determining the current group state" do it "should raise an error if the required binary /usr/sbin/group doesn't exist" do - File.should_receive(:exists?).with("/usr/sbin/group").and_return(false) - lambda { @provider.load_current_resource }.should raise_error(Chef::Exceptions::Group) + expect(File).to receive(:exists?).with("/usr/sbin/group").and_return(false) + expect { @provider.load_current_resource }.to raise_error(Chef::Exceptions::Group) end it "should raise an error if the required binary /usr/sbin/user doesn't exist" do - File.should_receive(:exists?).with("/usr/sbin/group").and_return(true) - File.should_receive(:exists?).with("/usr/sbin/user").and_return(false) - lambda { @provider.load_current_resource }.should raise_error(Chef::Exceptions::Group) + expect(File).to receive(:exists?).with("/usr/sbin/group").and_return(true) + expect(File).to receive(:exists?).with("/usr/sbin/user").and_return(false) + expect { @provider.load_current_resource }.to raise_error(Chef::Exceptions::Group) end it "shouldn't raise an error if the required binaries exist" do - File.stub(:exists?).and_return(true) - lambda { @provider.load_current_resource }.should_not raise_error + allow(File).to receive(:exists?).and_return(true) + expect { @provider.load_current_resource }.not_to raise_error end end @@ -61,10 +61,10 @@ describe Chef::Provider::Group::Groupmod do end it "logs a message and sets group's members to 'none', then removes existing group members" do - Chef::Log.should_receive(:debug).with("group[wheel] setting group members to: none") - @provider.should_receive(:shell_out!).with("group mod -n wheel_bak wheel") - @provider.should_receive(:shell_out!).with("group add -g '123' -o wheel") - @provider.should_receive(:shell_out!).with("group del wheel_bak") + expect(Chef::Log).to receive(:debug).with("group[wheel] setting group members to: none") + expect(@provider).to receive(:shell_out!).with("group mod -n wheel_bak wheel") + expect(@provider).to receive(:shell_out!).with("group add -g '123' -o wheel") + expect(@provider).to receive(:shell_out!).with("group del wheel_bak") @provider.manage_group end end @@ -76,8 +76,8 @@ describe Chef::Provider::Group::Groupmod do end it "logs a message and does not modify group membership" do - Chef::Log.should_receive(:debug).with("group[wheel] not changing group members, the group has no members to add") - @provider.should_not_receive(:shell_out!) + expect(Chef::Log).to receive(:debug).with("group[wheel] not changing group members, the group has no members to add") + expect(@provider).not_to receive(:shell_out!) @provider.manage_group end end @@ -89,11 +89,11 @@ describe Chef::Provider::Group::Groupmod do end it "updates group membership correctly" do - Chef::Log.stub(:debug) - @provider.should_receive(:shell_out!).with("group mod -n wheel_bak wheel") - @provider.should_receive(:shell_out!).with("user mod -G wheel lobster") - @provider.should_receive(:shell_out!).with("group add -g '123' -o wheel") - @provider.should_receive(:shell_out!).with("group del wheel_bak") + allow(Chef::Log).to receive(:debug) + expect(@provider).to receive(:shell_out!).with("group mod -n wheel_bak wheel") + expect(@provider).to receive(:shell_out!).with("user mod -G wheel lobster") + expect(@provider).to receive(:shell_out!).with("group add -g '123' -o wheel") + expect(@provider).to receive(:shell_out!).with("group del wheel_bak") @provider.manage_group end end @@ -108,10 +108,10 @@ describe Chef::Provider::Group::Groupmod do end it "should run a group add command and some user mod commands" do - @provider.should_receive(:shell_out!).with("group add -g '123' wheel") - @provider.should_receive(:shell_out!).with("user mod -G wheel lobster") - @provider.should_receive(:shell_out!).with("user mod -G wheel rage") - @provider.should_receive(:shell_out!).with("user mod -G wheel fist") + expect(@provider).to receive(:shell_out!).with("group add -g '123' wheel") + expect(@provider).to receive(:shell_out!).with("user mod -G wheel lobster") + expect(@provider).to receive(:shell_out!).with("user mod -G wheel rage") + expect(@provider).to receive(:shell_out!).with("user mod -G wheel fist") @provider.create_group end end @@ -125,7 +125,7 @@ describe Chef::Provider::Group::Groupmod do end it "should run a group del command" do - @provider.should_receive(:shell_out!).with("group del wheel") + expect(@provider).to receive(:shell_out!).with("group del wheel") @provider.remove_group end end diff --git a/spec/unit/provider/group/pw_spec.rb b/spec/unit/provider/group/pw_spec.rb index fdc2e35746..af74b3b2ce 100644 --- a/spec/unit/provider/group/pw_spec.rb +++ b/spec/unit/provider/group/pw_spec.rb @@ -37,19 +37,19 @@ describe Chef::Provider::Group::Pw do describe "when setting options for the pw command" do it "does not set the gid option if gids match or are unmanaged" do - @provider.set_options.should == " wheel" + expect(@provider.set_options).to eq(" wheel") end it "sets the option for gid if it is not nil" do @new_resource.gid(42) - @provider.set_options.should eql(" wheel -g '42'") + expect(@provider.set_options).to eql(" wheel -g '42'") end end describe "when creating a group" do it "should run pw groupadd with the return of set_options and set_members_option" do @new_resource.gid(23) - @provider.should_receive(:run_command).with({ :command => "pw groupadd wheel -g '23' -M root,aj" }).and_return(true) + expect(@provider).to receive(:run_command).with({ :command => "pw groupadd wheel -g '23' -M root,aj" }).and_return(true) @provider.create_group end end @@ -59,8 +59,8 @@ describe Chef::Provider::Group::Pw do it "should run pw groupmod with the return of set_options" do @new_resource.gid(42) @new_resource.members(["someone"]) - @provider.should_receive(:run_command).with({ :command => "pw groupmod wheel -g '42' -m someone" }).and_return(true) - @provider.should_receive(:run_command).with({ :command => "pw groupmod wheel -g '42' -d root,aj" }).and_return(true) + expect(@provider).to receive(:run_command).with({ :command => "pw groupmod wheel -g '42' -m someone" }).and_return(true) + expect(@provider).to receive(:run_command).with({ :command => "pw groupmod wheel -g '42' -d root,aj" }).and_return(true) @provider.manage_group end @@ -68,7 +68,7 @@ describe Chef::Provider::Group::Pw do describe "when removing the group" do it "should run pw groupdel with the new resources group name" do - @provider.should_receive(:run_command).with({ :command => "pw groupdel wheel" }).and_return(true) + expect(@provider).to receive(:run_command).with({ :command => "pw groupdel wheel" }).and_return(true) @provider.remove_group end end @@ -77,44 +77,44 @@ describe Chef::Provider::Group::Pw do describe "with an empty members array in both the new and current resource" do before do - @new_resource.stub(:members).and_return([]) - @current_resource.stub(:members).and_return([]) + allow(@new_resource).to receive(:members).and_return([]) + allow(@current_resource).to receive(:members).and_return([]) end it "should set no options" do - @provider.set_members_options.should eql([ ]) + expect(@provider.set_members_options).to eql([ ]) end end describe "with an empty members array in the new resource and existing members in the current resource" do before do - @new_resource.stub(:members).and_return([]) - @current_resource.stub(:members).and_return(["all", "your", "base"]) + allow(@new_resource).to receive(:members).and_return([]) + 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[wheel] removing group members: all,your,base") + expect(Chef::Log).to receive(:debug).with("group[wheel] removing group members: all,your,base") @provider.set_members_options end it "should set the -d option with the members joined by ','" do - @provider.set_members_options.should eql([ " -d all,your,base" ]) + expect(@provider.set_members_options).to eql([ " -d all,your,base" ]) end end describe "with supplied members array in the new resource and an empty members array in the current resource" do before do - @new_resource.stub(:members).and_return(["all", "your", "base"]) - @current_resource.stub(:members).and_return([]) + allow(@new_resource).to receive(:members).and_return(["all", "your", "base"]) + allow(@current_resource).to receive(:members).and_return([]) end it "should log an appropriate debug message" do - Chef::Log.should_receive(:debug).with("group[wheel] adding group members: all,your,base") + expect(Chef::Log).to receive(:debug).with("group[wheel] adding group members: all,your,base") @provider.set_members_options end it "should set the -m option with the members joined by ','" do - @provider.set_members_options.should eql([ " -m all,your,base" ]) + expect(@provider.set_members_options).to eql([ " -m all,your,base" ]) end end end @@ -126,13 +126,13 @@ describe Chef::Provider::Group::Pw do @provider.define_resource_requirements end it "should raise an error if the required binary /usr/sbin/pw doesn't exist" do - File.should_receive(:exists?).with("/usr/sbin/pw").and_return(false) - lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Group) + expect(File).to receive(:exists?).with("/usr/sbin/pw").and_return(false) + expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Group) end it "shouldn't raise an error if /usr/sbin/pw 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 end diff --git a/spec/unit/provider/group/usermod_spec.rb b/spec/unit/provider/group/usermod_spec.rb index bd9eac4ede..3f06e9ebf1 100644 --- a/spec/unit/provider/group/usermod_spec.rb +++ b/spec/unit/provider/group/usermod_spec.rb @@ -27,19 +27,19 @@ describe Chef::Provider::Group::Usermod do @new_resource.members [ "all", "your", "base" ] @new_resource.excluded_members [ ] @provider = Chef::Provider::Group::Usermod.new(@new_resource, @run_context) - @provider.stub(:run_command) + allow(@provider).to receive(:run_command) end describe "modify_group_members" do describe "with an empty members array" do before do - @new_resource.stub(:append).and_return(true) - @new_resource.stub(:members).and_return([]) + allow(@new_resource).to receive(:append).and_return(true) + allow(@new_resource).to receive(:members).and_return([]) end it "should log an appropriate message" do - @provider.should_not_receive(:shell_out!) + expect(@provider).not_to receive(:shell_out!) @provider.modify_group_members end end @@ -56,8 +56,8 @@ describe Chef::Provider::Group::Usermod do } before do - @new_resource.stub(:members).and_return(["all", "your", "base"]) - File.stub(:exists?).and_return(true) + allow(@new_resource).to receive(:members).and_return(["all", "your", "base"]) + allow(File).to receive(:exists?).and_return(true) end it "should raise an error when setting the entire group directly" do @@ -65,7 +65,7 @@ describe Chef::Provider::Group::Usermod do @provider.load_current_resource @provider.instance_variable_set("@group_exists", true) @provider.action = :modify - lambda { @provider.run_action(@provider.process_resource_requirements) }.should raise_error(Chef::Exceptions::Group, "setting group members directly is not supported by #{@provider.to_s}, must set append true in group") + expect { @provider.run_action(@provider.process_resource_requirements) }.to raise_error(Chef::Exceptions::Group, "setting group members directly is not supported by #{@provider.to_s}, must set append true in group") end it "should raise an error when excluded_members are set" do @@ -73,9 +73,9 @@ describe Chef::Provider::Group::Usermod do @provider.load_current_resource @provider.instance_variable_set("@group_exists", true) @provider.action = :modify - @new_resource.stub(:append).and_return(true) - @new_resource.stub(:excluded_members).and_return(["someone"]) - lambda { @provider.run_action(@provider.process_resource_requirements) }.should raise_error(Chef::Exceptions::Group, "excluded_members is not supported by #{@provider.to_s}") + allow(@new_resource).to receive(:append).and_return(true) + allow(@new_resource).to receive(:excluded_members).and_return(["someone"]) + expect { @provider.run_action(@provider.process_resource_requirements) }.to raise_error(Chef::Exceptions::Group, "excluded_members is not supported by #{@provider.to_s}") end platforms.each do |platform, flags| @@ -84,10 +84,10 @@ describe Chef::Provider::Group::Usermod do current_resource.members([ ]) @provider.current_resource = current_resource @node.automatic_attrs[:platform] = platform - @new_resource.stub(:append).and_return(true) - @provider.should_receive(:shell_out!).with("usermod #{flags} wheel all") - @provider.should_receive(:shell_out!).with("usermod #{flags} wheel your") - @provider.should_receive(:shell_out!).with("usermod #{flags} wheel base") + allow(@new_resource).to receive(:append).and_return(true) + expect(@provider).to receive(:shell_out!).with("usermod #{flags} wheel all") + expect(@provider).to receive(:shell_out!).with("usermod #{flags} wheel your") + expect(@provider).to receive(:shell_out!).with("usermod #{flags} wheel base") @provider.modify_group_members end end @@ -96,20 +96,20 @@ describe Chef::Provider::Group::Usermod do describe "when loading the current resource" do before(:each) do - File.stub(:exists?).and_return(false) + allow(File).to receive(:exists?).and_return(false) @provider.action = :create @provider.define_resource_requirements end it "should raise an error if the required binary /usr/sbin/usermod doesn't exist" do - File.stub(:exists?).and_return(true) - File.should_receive(:exists?).with("/usr/sbin/usermod").and_return(false) - lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Group) + allow(File).to receive(:exists?).and_return(true) + expect(File).to receive(:exists?).with("/usr/sbin/usermod").and_return(false) + expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Group) end it "shouldn't raise an error if the required binaries exist" 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 end diff --git a/spec/unit/provider/group/windows_spec.rb b/spec/unit/provider/group/windows_spec.rb index 6888c750f5..23dfa8315f 100644 --- a/spec/unit/provider/group/windows_spec.rb +++ b/spec/unit/provider/group/windows_spec.rb @@ -34,14 +34,14 @@ describe Chef::Provider::Group::Windows do @run_context = Chef::RunContext.new(@node, {}, @events) @new_resource = Chef::Resource::Group.new("staff") @net_group = double("Chef::Util::Windows::NetGroup") - Chef::Util::Windows::NetGroup.stub(:new).and_return(@net_group) + allow(Chef::Util::Windows::NetGroup).to receive(:new).and_return(@net_group) @provider = Chef::Provider::Group::Windows.new(@new_resource, @run_context) end describe "when creating the group" do it "should call @net_group.local_add" do - @net_group.should_receive(:local_set_members).with([]) - @net_group.should_receive(:local_add) + expect(@net_group).to receive(:local_set_members).with([]) + expect(@net_group).to receive(:local_add) @provider.create_group end end @@ -52,22 +52,22 @@ describe Chef::Provider::Group::Windows do @current_resource = Chef::Resource::Group.new("staff") @current_resource.members [ "all", "your", "base" ] - Chef::Util::Windows::NetGroup.stub(:new).and_return(@net_group) - @net_group.stub(:local_add_members) - @net_group.stub(:local_set_members) - @provider.stub(:local_group_name_to_sid) + allow(Chef::Util::Windows::NetGroup).to receive(:new).and_return(@net_group) + allow(@net_group).to receive(:local_add_members) + allow(@net_group).to receive(:local_set_members) + allow(@provider).to receive(:local_group_name_to_sid) @provider.current_resource = @current_resource end it "should call @net_group.local_set_members" do - @new_resource.stub(:append).and_return(false) - @net_group.should_receive(:local_set_members).with(@new_resource.members) + allow(@new_resource).to receive(:append).and_return(false) + expect(@net_group).to receive(:local_set_members).with(@new_resource.members) @provider.manage_group end it "should call @net_group.local_add_members" do - @new_resource.stub(:append).and_return(true) - @net_group.should_receive(:local_add_members).with(@new_resource.members) + allow(@new_resource).to receive(:append).and_return(true) + expect(@net_group).to receive(:local_add_members).with(@new_resource.members) @provider.manage_group end @@ -75,12 +75,12 @@ describe Chef::Provider::Group::Windows do describe "remove_group" do before do - Chef::Util::Windows::NetGroup.stub(:new).and_return(@net_group) - @provider.stub(:run_command).and_return(true) + allow(Chef::Util::Windows::NetGroup).to receive(:new).and_return(@net_group) + allow(@provider).to receive(:run_command).and_return(true) end it "should call @net_group.local_delete" do - @net_group.should_receive(:local_delete) + expect(@net_group).to receive(:local_delete) @provider.remove_group end end @@ -95,7 +95,7 @@ describe Chef::Provider::Group::Windows, "NetGroup" do @new_resource.group_name "Remote Desktop Users" end it 'sets group_name correctly' do - Chef::Util::Windows::NetGroup.should_receive(:new).with("Remote Desktop Users") + expect(Chef::Util::Windows::NetGroup).to receive(:new).with("Remote Desktop Users") Chef::Provider::Group::Windows.new(@new_resource, @run_context) end end |