diff options
Diffstat (limited to 'spec/unit/file_access_control_spec.rb')
-rw-r--r-- | spec/unit/file_access_control_spec.rb | 60 |
1 files changed, 30 insertions, 30 deletions
diff --git a/spec/unit/file_access_control_spec.rb b/spec/unit/file_access_control_spec.rb index 2c68792c63..724c2385c7 100644 --- a/spec/unit/file_access_control_spec.rb +++ b/spec/unit/file_access_control_spec.rb @@ -16,8 +16,8 @@ # limitations under the License. # -require 'spec_helper' -require 'ostruct' +require "spec_helper" +require "ostruct" describe Chef::FileAccessControl do describe "Unix" do @@ -27,14 +27,14 @@ describe Chef::FileAccessControl do # platform specific module is mixed in @node = Chef::Node.new load File.join(File.dirname(__FILE__), "..", "..", "lib", "chef", "file_access_control.rb") - @resource = Chef::Resource::File.new('/tmp/a_file.txt') - @resource.owner('toor') - @resource.group('wheel') - @resource.mode('0400') + @resource = Chef::Resource::File.new("/tmp/a_file.txt") + @resource.owner("toor") + @resource.group("wheel") + @resource.mode("0400") @events = Chef::EventDispatch::Dispatcher.new @run_context = Chef::RunContext.new(@node, {}, @events) - @current_resource = Chef::Resource::File.new('/tmp/different_file.txt') + @current_resource = Chef::Resource::File.new("/tmp/different_file.txt") @provider_requirements = Chef::Provider::ResourceRequirements.new(@resource, @run_context) @provider = double("File provider", :requirements => @provider_requirements, :manage_symlink_access? => false) @@ -42,7 +42,7 @@ describe Chef::FileAccessControl do end end - describe 'class methods' do + describe "class methods" do it 'responds to #writable?' do expect(Chef::FileAccessControl).to respond_to(:writable?) end @@ -53,7 +53,7 @@ describe Chef::FileAccessControl do end it "has a file to manage" do - expect(@fac.file).to eq('/tmp/different_file.txt') + expect(@fac.file).to eq("/tmp/different_file.txt") end it "is not modified yet" do @@ -61,12 +61,12 @@ describe Chef::FileAccessControl do end it "determines the uid of the owner specified by the resource" do - expect(Etc).to receive(:getpwnam).with('toor').and_return(OpenStruct.new(:uid => 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 - expect(Etc).to receive(:getpwnam).with('toor').and_raise(ArgumentError) + 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 @@ -98,16 +98,16 @@ describe Chef::FileAccessControl do # complement (i.e., it wraps around the maximum size of C unsigned int) of these # uids. So we have to get ruby and negative uids to smoke the peace pipe # with each other. - @resource.owner('nobody') - expect(Etc).to receive(:getpwnam).with('nobody').and_return(OpenStruct.new(:uid => (4294967294))) + @resource.owner("nobody") + 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') - expect(Etc).to receive(:getpwnam).with('bigdude').and_return(OpenStruct.new(:uid => (4294967286))) + @resource.owner("bigdude") + expect(Etc).to receive(:getpwnam).with("bigdude").and_return(OpenStruct.new(:uid => (4294967286))) expect(@fac.target_uid).to eq(4294967286) end @@ -133,7 +133,7 @@ describe Chef::FileAccessControl do it "sets the file's owner as specified in the resource when the current owner is incorrect" do @resource.owner(2342) - expect(File).to receive(:chown).with(2342, nil, '/tmp/different_file.txt') + expect(File).to receive(:chown).with(2342, nil, "/tmp/different_file.txt") @fac.set_owner expect(@fac).to be_modified end @@ -153,7 +153,7 @@ describe Chef::FileAccessControl do end it "determines the gid of the group specified by the resource" do - expect(Etc).to receive(:getgrnam).with('wheel').and_return(OpenStruct.new(:gid => 2342)) + expect(Etc).to receive(:getgrnam).with("wheel").and_return(OpenStruct.new(:gid => 2342)) expect(@fac.target_gid).to eq(2342) end @@ -163,18 +163,18 @@ describe Chef::FileAccessControl do end it "raises a Chef::Exceptions::GroupIDNotFound error when Etc can't find the user's name" do - expect(Etc).to receive(:getgrnam).with('wheel').and_raise(ArgumentError) + 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') + resource = Chef::Resource::File.new("crab") fac = Chef::FileAccessControl.new(@current_resource, resource, @provider) 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') + resource = Chef::Resource::File.new("crab") fac = Chef::FileAccessControl.new(@current_resource, resource, @provider) expect(fac.should_update_group?).to be_falsey end @@ -197,7 +197,7 @@ describe Chef::FileAccessControl do end it "includes updating the group in the list of changes" do - resource = Chef::Resource::File.new('crab') + resource = Chef::Resource::File.new("crab") resource.group(2342) @current_resource.group(815) fac = Chef::FileAccessControl.new(@current_resource, resource, @provider) @@ -208,7 +208,7 @@ describe Chef::FileAccessControl do @resource.group(2342) @current_resource.group(815) - expect(File).to receive(:chown).with(nil, 2342, '/tmp/different_file.txt') + expect(File).to receive(:chown).with(nil, 2342, "/tmp/different_file.txt") @fac.set_group expect(@fac).to be_modified end @@ -230,7 +230,7 @@ describe Chef::FileAccessControl do end it "uses the supplied mode as octal when it's a string" do - @resource.mode('444') + @resource.mode("444") expect(@fac.target_mode).to eq(292) # octal 444 => decimal 292 end @@ -240,13 +240,13 @@ describe Chef::FileAccessControl do end it "does not try to determine the mode when none is given" do - resource = Chef::Resource::File.new('blahblah') + resource = Chef::Resource::File.new("blahblah") fac = Chef::FileAccessControl.new(@current_resource, resource, @provider) 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') + resource = Chef::Resource::File.new("blahblah") fac = Chef::FileAccessControl.new(@current_resource, resource, @provider) expect(fac.should_update_mode?).to be_falsey end @@ -264,7 +264,7 @@ describe Chef::FileAccessControl do end it "includes changing the mode in the list of desired changes" do - resource = Chef::Resource::File.new('blahblah') + resource = Chef::Resource::File.new("blahblah") resource.mode("0750") @current_resource.mode("0444") fac = Chef::FileAccessControl.new(@current_resource, resource, @provider) @@ -275,7 +275,7 @@ describe Chef::FileAccessControl do # stat returns modes like 0100644 (octal) => 33188 (decimal) #@fac.stub(:stat).and_return(OpenStruct.new(:mode => 33188)) @current_resource.mode("0644") - expect(File).to receive(:chmod).with(256, '/tmp/different_file.txt') + expect(File).to receive(:chmod).with(256, "/tmp/different_file.txt") @fac.set_mode expect(@fac).to be_modified end @@ -298,9 +298,9 @@ describe Chef::FileAccessControl do @resource.mode(0400) @resource.owner(0) @resource.group(0) - 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') + 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 expect(@fac).to be_modified end |