diff options
Diffstat (limited to 'spec/unit/file_access_control_spec.rb')
-rw-r--r-- | spec/unit/file_access_control_spec.rb | 112 |
1 files changed, 56 insertions, 56 deletions
diff --git a/spec/unit/file_access_control_spec.rb b/spec/unit/file_access_control_spec.rb index 4e257c2a22..cd0bd55cc3 100644 --- a/spec/unit/file_access_control_spec.rb +++ b/spec/unit/file_access_control_spec.rb @@ -43,47 +43,47 @@ describe Chef::FileAccessControl do end it "has a resource" do - @fac.resource.should equal(@resource) + expect(@fac.resource).to equal(@resource) end it "has a file to manage" do - @fac.file.should == '/tmp/different_file.txt' + expect(@fac.file).to eq('/tmp/different_file.txt') end it "is not modified yet" do - @fac.should_not be_modified + expect(@fac).not_to be_modified end it "determines the uid of the owner specified by the resource" do - Etc.should_receive(:getpwnam).with('toor').and_return(OpenStruct.new(:uid => 2342)) - @fac.target_uid.should == 2342 + expect(Etc).to receive(:getpwnam).with('toor').and_return(OpenStruct.new(:uid => 2342)) + expect(@fac.target_uid).to eq(2342) end it "raises a Chef::Exceptions::UserIDNotFound error when Etc can't find the user's name" do - Etc.should_receive(:getpwnam).with('toor').and_raise(ArgumentError) - lambda { @fac.target_uid ; @provider_requirements.run(:create) }.should raise_error(Chef::Exceptions::UserIDNotFound, "cannot determine user id for 'toor', does the user exist on this system?") + expect(Etc).to receive(:getpwnam).with('toor').and_raise(ArgumentError) + expect { @fac.target_uid ; @provider_requirements.run(:create) }.to raise_error(Chef::Exceptions::UserIDNotFound, "cannot determine user id for 'toor', does the user exist on this system?") end it "does not attempt to resolve the uid if the user is not specified" do resource = Chef::Resource::File.new("a file") fac = Chef::FileAccessControl.new(@current_resource, resource, @provider) - fac.target_uid.should be_nil + expect(fac.target_uid).to be_nil end it "does not want to update the owner if none is specified" do resource = Chef::Resource::File.new("a file") fac = Chef::FileAccessControl.new(@current_resource, resource, @provider) - fac.should_update_owner?.should be_false + expect(fac.should_update_owner?).to be_falsey end it "raises an ArgumentError if the resource's owner is set to something wack" do @resource.instance_variable_set(:@owner, :diaf) - lambda { @fac.target_uid ; @provider_requirements.run(:create) }.should raise_error(ArgumentError) + expect { @fac.target_uid ; @provider_requirements.run(:create) }.to raise_error(ArgumentError) end it "uses the resource's uid for the target uid when the resource's owner is specified by an integer" do @resource.owner(2342) - @fac.target_uid.should == 2342 + expect(@fac.target_uid).to eq(2342) end it "wraps uids to their negative complements to correctly handle negative uids" do @@ -93,28 +93,28 @@ describe Chef::FileAccessControl do # uids. So we have to get ruby and negative uids to smoke the peace pipe # with each other. @resource.owner('nobody') - Etc.should_receive(:getpwnam).with('nobody').and_return(OpenStruct.new(:uid => (4294967294))) - @fac.target_uid.should == -2 + expect(Etc).to receive(:getpwnam).with('nobody').and_return(OpenStruct.new(:uid => (4294967294))) + expect(@fac.target_uid).to eq(-2) end it "does not wrap uids to their negative complements beyond -9" do # More: when OSX userIDs are created by ActiveDirectory sync, it tends to use huge numbers # which had been incorrectly wrapped. It does not look like the OSX IDs go below -2 @resource.owner('bigdude') - Etc.should_receive(:getpwnam).with('bigdude').and_return(OpenStruct.new(:uid => (4294967286))) - @fac.target_uid.should == 4294967286 + expect(Etc).to receive(:getpwnam).with('bigdude').and_return(OpenStruct.new(:uid => (4294967286))) + expect(@fac.target_uid).to eq(4294967286) end it "wants to update the owner when the current owner is nil (creating a file)" do @current_resource.owner(nil) @resource.owner(2342) - @fac.should_update_owner?.should be_true + expect(@fac.should_update_owner?).to be_truthy end it "wants to update the owner when the current owner doesn't match desired" do @current_resource.owner(3224) @resource.owner(2342) - @fac.should_update_owner?.should be_true + expect(@fac.should_update_owner?).to be_truthy end it "includes updating ownership in its list of desired changes" do @@ -122,72 +122,72 @@ describe Chef::FileAccessControl do resource.owner(2342) @current_resource.owner(100) fac = Chef::FileAccessControl.new(@current_resource, resource, @provider) - fac.describe_changes.should == ["change owner from '100' to '2342'"] + expect(fac.describe_changes).to eq(["change owner from '100' to '2342'"]) end it "sets the file's owner as specified in the resource when the current owner is incorrect" do @resource.owner(2342) - File.should_receive(:chown).with(2342, nil, '/tmp/different_file.txt') + expect(File).to receive(:chown).with(2342, nil, '/tmp/different_file.txt') @fac.set_owner - @fac.should be_modified + expect(@fac).to be_modified end it "doesn't set the file's owner if it already matches" do @resource.owner(2342) @current_resource.owner(2342) - File.should_not_receive(:chown) + expect(File).not_to receive(:chown) @fac.set_owner - @fac.should_not be_modified + expect(@fac).not_to be_modified end it "doesn't want to update a file's owner when it's already correct" do @resource.owner(2342) @current_resource.owner(2342) - @fac.should_update_owner?.should be_false + expect(@fac.should_update_owner?).to be_falsey end it "determines the gid of the group specified by the resource" do - Etc.should_receive(:getgrnam).with('wheel').and_return(OpenStruct.new(:gid => 2342)) - @fac.target_gid.should == 2342 + expect(Etc).to receive(:getgrnam).with('wheel').and_return(OpenStruct.new(:gid => 2342)) + expect(@fac.target_gid).to eq(2342) end it "uses a user specified gid as the gid" do @resource.group(2342) - @fac.target_gid.should == 2342 + expect(@fac.target_gid).to eq(2342) end it "raises a Chef::Exceptions::GroupIDNotFound error when Etc can't find the user's name" do - Etc.should_receive(:getgrnam).with('wheel').and_raise(ArgumentError) - lambda { @fac.target_gid; @provider_requirements.run(:create) }.should raise_error(Chef::Exceptions::GroupIDNotFound, "cannot determine group id for 'wheel', does the group exist on this system?") + expect(Etc).to receive(:getgrnam).with('wheel').and_raise(ArgumentError) + expect { @fac.target_gid; @provider_requirements.run(:create) }.to raise_error(Chef::Exceptions::GroupIDNotFound, "cannot determine group id for 'wheel', does the group exist on this system?") end it "does not attempt to resolve a gid when none is supplied" do resource = Chef::Resource::File.new('crab') fac = Chef::FileAccessControl.new(@current_resource, resource, @provider) - fac.target_gid.should be_nil + expect(fac.target_gid).to be_nil end it "does not want to update the group when no target group is specified" do resource = Chef::Resource::File.new('crab') fac = Chef::FileAccessControl.new(@current_resource, resource, @provider) - fac.should_update_group?.should be_false + expect(fac.should_update_group?).to be_falsey end it "raises an error when the supplied group name is an alien" do @resource.instance_variable_set(:@group, :failburger) - lambda { @fac.target_gid; @provider_requirements.run(:create) }.should raise_error(ArgumentError) + expect { @fac.target_gid; @provider_requirements.run(:create) }.to raise_error(ArgumentError) end it "wants to update the group when the current group is nil (creating a file)" do @resource.group(2342) @current_resource.group(nil) - @fac.should_update_group?.should be_true + expect(@fac.should_update_group?).to be_truthy end it "wants to update the group when the current group doesn't match the target group" do @resource.group(2342) @current_resource.group(815) - @fac.should_update_group?.should be_true + expect(@fac.should_update_group?).to be_truthy end it "includes updating the group in the list of changes" do @@ -195,22 +195,22 @@ describe Chef::FileAccessControl do resource.group(2342) @current_resource.group(815) fac = Chef::FileAccessControl.new(@current_resource, resource, @provider) - fac.describe_changes.should == ["change group from '815' to '2342'"] + expect(fac.describe_changes).to eq(["change group from '815' to '2342'"]) end it "sets the file's group as specified in the resource when the group is not correct" do @resource.group(2342) @current_resource.group(815) - File.should_receive(:chown).with(nil, 2342, '/tmp/different_file.txt') + expect(File).to receive(:chown).with(nil, 2342, '/tmp/different_file.txt') @fac.set_group - @fac.should be_modified + expect(@fac).to be_modified end it "doesn't want to modify the file's group when the current group is correct" do @resource.group(2342) @current_resource.group(2342) - @fac.should_update_group?.should be_false + expect(@fac.should_update_group?).to be_falsey end it "doesnt set the file's group if it is already correct" do @@ -218,43 +218,43 @@ describe Chef::FileAccessControl do @current_resource.group(2342) # @fac.stub(:stat).and_return(OpenStruct.new(:gid => 2342)) - File.should_not_receive(:chown) + expect(File).not_to receive(:chown) @fac.set_group - @fac.should_not be_modified + expect(@fac).not_to be_modified end it "uses the supplied mode as octal when it's a string" do @resource.mode('444') - @fac.target_mode.should == 292 # octal 444 => decimal 292 + expect(@fac.target_mode).to eq(292) # octal 444 => decimal 292 end it "uses the supplied mode verbatim when it's an integer" do @resource.mode(00444) - @fac.target_mode.should == 292 + expect(@fac.target_mode).to eq(292) end it "does not try to determine the mode when none is given" do resource = Chef::Resource::File.new('blahblah') fac = Chef::FileAccessControl.new(@current_resource, resource, @provider) - fac.target_mode.should be_nil + expect(fac.target_mode).to be_nil end it "doesn't want to update the mode when no target mode is given" do resource = Chef::Resource::File.new('blahblah') fac = Chef::FileAccessControl.new(@current_resource, resource, @provider) - fac.should_update_mode?.should be_false + expect(fac.should_update_mode?).to be_falsey end it "wants to update the mode when the current mode is nil (creating a file)" do @resource.mode("0400") @current_resource.mode(nil) - @fac.should_update_mode?.should be_true + expect(@fac.should_update_mode?).to be_truthy end it "wants to update the mode when the desired mode does not match the current mode" do @resource.mode("0400") @current_resource.mode("0644") - @fac.should_update_mode?.should be_true + expect(@fac.should_update_mode?).to be_truthy end it "includes changing the mode in the list of desired changes" do @@ -262,41 +262,41 @@ describe Chef::FileAccessControl do resource.mode("0750") @current_resource.mode("0444") fac = Chef::FileAccessControl.new(@current_resource, resource, @provider) - fac.describe_changes.should == ["change mode from '0444' to '0750'"] + expect(fac.describe_changes).to eq(["change mode from '0444' to '0750'"]) end it "sets the file's mode as specified in the resource when the current modes are incorrect" do # stat returns modes like 0100644 (octal) => 33188 (decimal) #@fac.stub(:stat).and_return(OpenStruct.new(:mode => 33188)) @current_resource.mode("0644") - File.should_receive(:chmod).with(256, '/tmp/different_file.txt') + expect(File).to receive(:chmod).with(256, '/tmp/different_file.txt') @fac.set_mode - @fac.should be_modified + expect(@fac).to be_modified end it "does not want to update the mode when the current mode is correct" do @current_resource.mode("0400") - @fac.should_update_mode?.should be_false + expect(@fac.should_update_mode?).to be_falsey end it "does not set the file's mode when the current modes are correct" do #@fac.stub(:stat).and_return(OpenStruct.new(:mode => 0100400)) @current_resource.mode("0400") - File.should_not_receive(:chmod) + expect(File).not_to receive(:chmod) @fac.set_mode - @fac.should_not be_modified + expect(@fac).not_to be_modified end it "sets all access controls on a file" do - @fac.stub(:stat).and_return(OpenStruct.new(:owner => 99, :group => 99, :mode => 0100444)) + allow(@fac).to receive(:stat).and_return(OpenStruct.new(:owner => 99, :group => 99, :mode => 0100444)) @resource.mode(0400) @resource.owner(0) @resource.group(0) - File.should_receive(:chmod).with(0400, '/tmp/different_file.txt') - File.should_receive(:chown).with(0, nil, '/tmp/different_file.txt') - File.should_receive(:chown).with(nil, 0, '/tmp/different_file.txt') + expect(File).to receive(:chmod).with(0400, '/tmp/different_file.txt') + expect(File).to receive(:chown).with(0, nil, '/tmp/different_file.txt') + expect(File).to receive(:chown).with(nil, 0, '/tmp/different_file.txt') @fac.set_all - @fac.should be_modified + expect(@fac).to be_modified end end end |