diff options
Diffstat (limited to 'spec/support/shared/unit/provider/file.rb')
-rw-r--r-- | spec/support/shared/unit/provider/file.rb | 419 |
1 files changed, 209 insertions, 210 deletions
diff --git a/spec/support/shared/unit/provider/file.rb b/spec/support/shared/unit/provider/file.rb index 85c8e2fb34..25c2b52b1b 100644 --- a/spec/support/shared/unit/provider/file.rb +++ b/spec/support/shared/unit/provider/file.rb @@ -43,67 +43,67 @@ end # this is all getting a bit stupid, CHEF-4802 cut to remove all this def setup_normal_file [ resource_path, normalized_path, windows_path].each do |path| - File.stub(:file?).with(path).and_return(true) - File.stub(:exists?).with(path).and_return(true) - File.stub(:exist?).with(path).and_return(true) - File.stub(:directory?).with(path).and_return(false) - File.stub(:writable?).with(path).and_return(true) - file_symlink_class.stub(:symlink?).with(path).and_return(false) - File.stub(:realpath?).with(path).and_return(normalized_path) + allow(File).to receive(:file?).with(path).and_return(true) + allow(File).to receive(:exists?).with(path).and_return(true) + allow(File).to receive(:exist?).with(path).and_return(true) + allow(File).to receive(:directory?).with(path).and_return(false) + allow(File).to receive(:writable?).with(path).and_return(true) + allow(file_symlink_class).to receive(:symlink?).with(path).and_return(false) + allow(File).to receive(:realpath?).with(path).and_return(normalized_path) end - File.stub(:directory?).with(enclosing_directory).and_return(true) + allow(File).to receive(:directory?).with(enclosing_directory).and_return(true) end def setup_missing_file [ resource_path, normalized_path, windows_path].each do |path| - File.stub(:file?).with(path).and_return(false) - File.stub(:realpath?).with(path).and_return(resource_path) - File.stub(:exists?).with(path).and_return(false) - File.stub(:exist?).with(path).and_return(false) - File.stub(:directory?).with(path).and_return(false) - File.stub(:writable?).with(path).and_return(false) - file_symlink_class.stub(:symlink?).with(path).and_return(false) + allow(File).to receive(:file?).with(path).and_return(false) + allow(File).to receive(:realpath?).with(path).and_return(resource_path) + allow(File).to receive(:exists?).with(path).and_return(false) + allow(File).to receive(:exist?).with(path).and_return(false) + allow(File).to receive(:directory?).with(path).and_return(false) + allow(File).to receive(:writable?).with(path).and_return(false) + allow(file_symlink_class).to receive(:symlink?).with(path).and_return(false) end - File.stub(:directory?).with(enclosing_directory).and_return(true) + allow(File).to receive(:directory?).with(enclosing_directory).and_return(true) end def setup_symlink [ resource_path, normalized_path, windows_path].each do |path| - File.stub(:file?).with(path).and_return(true) - File.stub(:realpath?).with(path).and_return(normalized_path) - File.stub(:exists?).with(path).and_return(true) - File.stub(:exist?).with(path).and_return(true) - File.stub(:directory?).with(path).and_return(false) - File.stub(:writable?).with(path).and_return(true) - file_symlink_class.stub(:symlink?).with(path).and_return(true) + allow(File).to receive(:file?).with(path).and_return(true) + allow(File).to receive(:realpath?).with(path).and_return(normalized_path) + allow(File).to receive(:exists?).with(path).and_return(true) + allow(File).to receive(:exist?).with(path).and_return(true) + allow(File).to receive(:directory?).with(path).and_return(false) + allow(File).to receive(:writable?).with(path).and_return(true) + allow(file_symlink_class).to receive(:symlink?).with(path).and_return(true) end - File.stub(:directory?).with(enclosing_directory).and_return(true) + allow(File).to receive(:directory?).with(enclosing_directory).and_return(true) end def setup_unwritable_file [ resource_path, normalized_path, windows_path].each do |path| - File.stub(:file?).with(path).and_return(false) - File.stub(:realpath?).with(path).and_raise(Errno::ENOENT) - File.stub(:exists?).with(path).and_return(true) - File.stub(:exist?).with(path).and_return(true) - File.stub(:directory?).with(path).and_return(false) - File.stub(:writable?).with(path).and_return(false) - file_symlink_class.stub(:symlink?).with(path).and_return(false) + allow(File).to receive(:file?).with(path).and_return(false) + allow(File).to receive(:realpath?).with(path).and_raise(Errno::ENOENT) + allow(File).to receive(:exists?).with(path).and_return(true) + allow(File).to receive(:exist?).with(path).and_return(true) + allow(File).to receive(:directory?).with(path).and_return(false) + allow(File).to receive(:writable?).with(path).and_return(false) + allow(file_symlink_class).to receive(:symlink?).with(path).and_return(false) end - File.stub(:directory?).with(enclosing_directory).and_return(true) + allow(File).to receive(:directory?).with(enclosing_directory).and_return(true) end def setup_missing_enclosing_directory [ resource_path, normalized_path, windows_path].each do |path| - File.stub(:file?).with(path).and_return(false) - File.stub(:realpath?).with(path).and_raise(Errno::ENOENT) - File.stub(:exists?).with(path).and_return(false) - File.stub(:exist?).with(path).and_return(false) - File.stub(:directory?).with(path).and_return(false) - File.stub(:writable?).with(path).and_return(false) - file_symlink_class.stub(:symlink?).with(path).and_return(false) + allow(File).to receive(:file?).with(path).and_return(false) + allow(File).to receive(:realpath?).with(path).and_raise(Errno::ENOENT) + allow(File).to receive(:exists?).with(path).and_return(false) + allow(File).to receive(:exist?).with(path).and_return(false) + allow(File).to receive(:directory?).with(path).and_return(false) + allow(File).to receive(:writable?).with(path).and_return(false) + allow(file_symlink_class).to receive(:symlink?).with(path).and_return(false) end - File.stub(:directory?).with(enclosing_directory).and_return(false) + allow(File).to receive(:directory?).with(enclosing_directory).and_return(false) end # A File subclass that we use as a replacement for Tempfile. Some versions of @@ -136,9 +136,9 @@ shared_examples_for Chef::Provider::File do end before(:each) do - content.stub(:tempfile).and_return(tempfile) - File.stub(:exist?).with(tempfile.path).and_call_original - File.stub(:exists?).with(tempfile.path).and_call_original + allow(content).to receive(:tempfile).and_return(tempfile) + allow(File).to receive(:exist?).with(tempfile.path).and_call_original + allow(File).to receive(:exists?).with(tempfile.path).and_call_original end after do @@ -147,15 +147,15 @@ shared_examples_for Chef::Provider::File do end it "should return a #{described_class}" do - provider.should be_a_kind_of(described_class) + expect(provider).to be_a_kind_of(described_class) end it "should store the resource passed to new as new_resource" do - provider.new_resource.should eql(resource) + expect(provider.new_resource).to eql(resource) end it "should store the node passed to new as node" do - provider.node.should eql(node) + expect(provider.node).to eql(node) end context "when loading the current resource" do @@ -167,15 +167,15 @@ shared_examples_for Chef::Provider::File do # it "should not try to load the content when the file is present" do setup_normal_file - provider.should_not_receive(:tempfile) - provider.should_not_receive(:content) + expect(provider).not_to receive(:tempfile) + expect(provider).not_to receive(:content) provider.load_current_resource end it "should not try to load the content when the file is missing" do setup_missing_file - provider.should_not_receive(:tempfile) - provider.should_not_receive(:content) + expect(provider).not_to receive(:tempfile) + expect(provider).not_to receive(:content) provider.load_current_resource end end @@ -189,33 +189,33 @@ shared_examples_for Chef::Provider::File do it "should load a current resource based on the one specified at construction" do provider.load_current_resource - provider.current_resource.should be_a_kind_of(Chef::Resource::File) + expect(provider.current_resource).to be_a_kind_of(Chef::Resource::File) end it "the loaded current_resource name should be the same as the resource name" do provider.load_current_resource - provider.current_resource.name.should eql(resource.name) + expect(provider.current_resource.name).to eql(resource.name) end it "the loaded current_resource path should be the same as the resoure path" do provider.load_current_resource - provider.current_resource.path.should eql(resource.path) + expect(provider.current_resource.path).to eql(resource.path) end it "the loaded current_resource content should be nil" do provider.load_current_resource - provider.current_resource.content.should eql(nil) + expect(provider.current_resource.content).to eql(nil) end it "it should call checksum if we are managing content" do - provider.should_receive(:managing_content?).at_least(:once).and_return(true) - provider.should_receive(:checksum).with(resource.path).and_return(tempfile_sha256) + expect(provider).to receive(:managing_content?).at_least(:once).and_return(true) + expect(provider).to receive(:checksum).with(resource.path).and_return(tempfile_sha256) provider.load_current_resource end it "it should not call checksum if we are not managing content" do - provider.should_receive(:managing_content?).at_least(:once).and_return(false) - provider.should_not_receive(:checksum) + expect(provider).to receive(:managing_content?).at_least(:once).and_return(false) + expect(provider).not_to receive(:checksum) provider.load_current_resource end end @@ -227,27 +227,27 @@ shared_examples_for Chef::Provider::File do it "the current_resource should be a Chef::Resource::File" do provider.load_current_resource - provider.current_resource.should be_a_kind_of(Chef::Resource::File) + expect(provider.current_resource).to be_a_kind_of(Chef::Resource::File) end it "the current_resource name should be the same as the resource name" do provider.load_current_resource - provider.current_resource.name.should eql(resource.name) + expect(provider.current_resource.name).to eql(resource.name) end it "the current_resource path should be the same as the resource path" do provider.load_current_resource - provider.current_resource.path.should eql(resource.path) + expect(provider.current_resource.path).to eql(resource.path) end it "the loaded current_resource content should be nil" do provider.load_current_resource - provider.current_resource.content.should eql(nil) + expect(provider.current_resource.content).to eql(nil) end it "it should not call checksum if we are not managing content" do - provider.should_not_receive(:managing_content?) - provider.should_not_receive(:checksum) + expect(provider).not_to receive(:managing_content?) + expect(provider).not_to receive(:checksum) provider.load_current_resource end end @@ -255,14 +255,14 @@ shared_examples_for Chef::Provider::File do context "examining file security metadata on Unix with a file that exists" do before do # fake that we're on unix even if we're on windows - Chef::Platform.stub(:windows?).and_return(false) + allow(Chef::Platform).to receive(:windows?).and_return(false) # mock up the filesystem to behave like unix setup_normal_file stat_struct = double("::File.stat", :mode => 0600, :uid => 0, :gid => 0, :mtime => 10000) resource_real_path = File.realpath(resource.path) - File.should_receive(:stat).with(resource_real_path).at_least(:once).and_return(stat_struct) - Etc.stub(:getgrgid).with(0).and_return(double("Group Ent", :name => "wheel")) - Etc.stub(:getpwuid).with(0).and_return(double("User Ent", :name => "root")) + expect(File).to receive(:stat).with(resource_real_path).at_least(:once).and_return(stat_struct) + allow(Etc).to receive(:getgrgid).with(0).and_return(double("Group Ent", :name => "wheel")) + allow(Etc).to receive(:getpwuid).with(0).and_return(double("User Ent", :name => "root")) end context "when the new_resource does not specify any state" do @@ -271,15 +271,15 @@ shared_examples_for Chef::Provider::File do end it "should load the permissions into the current_resource" do - provider.current_resource.mode.should == "0600" - provider.current_resource.owner.should == "root" - provider.current_resource.group.should == "wheel" + expect(provider.current_resource.mode).to eq("0600") + expect(provider.current_resource.owner).to eq("root") + expect(provider.current_resource.group).to eq("wheel") end it "should not set the new_resource permissions" do - provider.new_resource.group.should be_nil - provider.new_resource.owner.should be_nil - provider.new_resource.mode.should be_nil + expect(provider.new_resource.group).to be_nil + expect(provider.new_resource.owner).to be_nil + expect(provider.new_resource.mode).to be_nil end end @@ -293,15 +293,15 @@ shared_examples_for Chef::Provider::File do it "should load the permissions into the current_resource as numbers" do # Mode is always loaded as string for reporting purposes. - provider.current_resource.mode.should == "0600" - provider.current_resource.owner.should == 0 - provider.current_resource.group.should == 0 + expect(provider.current_resource.mode).to eq("0600") + expect(provider.current_resource.owner).to eq(0) + expect(provider.current_resource.group).to eq(0) end it "should not set the new_resource permissions" do - provider.new_resource.group.should == 1 - provider.new_resource.owner.should == 1 - provider.new_resource.mode.should == 0644 + expect(provider.new_resource.group).to eq(1) + expect(provider.new_resource.owner).to eq(1) + expect(provider.new_resource.mode).to eq(0644) end end @@ -314,15 +314,15 @@ shared_examples_for Chef::Provider::File do end it "should load the permissions into the current_resource as symbols" do - provider.current_resource.mode.should == "0600" - provider.current_resource.owner.should == "root" - provider.current_resource.group.should == "wheel" + expect(provider.current_resource.mode).to eq("0600") + expect(provider.current_resource.owner).to eq("root") + expect(provider.current_resource.group).to eq("wheel") end it "should not set the new_resource permissions" do - provider.new_resource.group.should == "seattlehiphop" - provider.new_resource.owner.should == "macklemore" - provider.new_resource.mode.should == "0321" + expect(provider.new_resource.group).to eq("seattlehiphop") + expect(provider.new_resource.owner).to eq("macklemore") + expect(provider.new_resource.mode).to eq("0321") end end @@ -331,7 +331,7 @@ shared_examples_for Chef::Provider::File do context "examining file security metadata on Unix with a file that does not exist" do before do # fake that we're on unix even if we're on windows - Chef::Platform.stub(:windows?).and_return(false) + allow(Chef::Platform).to receive(:windows?).and_return(false) setup_missing_file end @@ -341,15 +341,15 @@ shared_examples_for Chef::Provider::File do end it "the current_resource permissions should be nil" do - provider.current_resource.mode.should be_nil - provider.current_resource.owner.should be_nil - provider.current_resource.group.should be_nil + expect(provider.current_resource.mode).to be_nil + expect(provider.current_resource.owner).to be_nil + expect(provider.current_resource.group).to be_nil end it "should not set the new_resource permissions" do - provider.new_resource.group.should be_nil - provider.new_resource.owner.should be_nil - provider.new_resource.mode.should be_nil + expect(provider.new_resource.group).to be_nil + expect(provider.new_resource.owner).to be_nil + expect(provider.new_resource.mode).to be_nil end end @@ -362,15 +362,15 @@ shared_examples_for Chef::Provider::File do end it "the current_resource permissions should be nil" do - provider.current_resource.mode.should be_nil - provider.current_resource.owner.should be_nil - provider.current_resource.group.should be_nil + expect(provider.current_resource.mode).to be_nil + expect(provider.current_resource.owner).to be_nil + expect(provider.current_resource.group).to be_nil end it "should not set the new_resource permissions" do - provider.new_resource.group.should == 51948 - provider.new_resource.owner.should == 63945 - provider.new_resource.mode.should == 0123 + expect(provider.new_resource.group).to eq(51948) + expect(provider.new_resource.owner).to eq(63945) + expect(provider.new_resource.mode).to eq(0123) end end end @@ -380,35 +380,35 @@ shared_examples_for Chef::Provider::File do before do # fake that we're on unix even if we're on windows - Chef::Platform.stub(:windows?).and_return(false) + allow(Chef::Platform).to receive(:windows?).and_return(false) # mock up the filesystem to behave like unix setup_normal_file stat_struct = double("::File.stat", :mode => 0600, :uid => 0, :gid => 0, :mtime => 10000) resource_real_path = File.realpath(resource.path) - File.stub(:stat).with(resource_real_path).and_return(stat_struct) - Etc.stub(:getgrgid).with(0).and_return(double("Group Ent", :name => "wheel")) - Etc.stub(:getpwuid).with(0).and_return(double("User Ent", :name => "root")) + allow(File).to receive(:stat).with(resource_real_path).and_return(stat_struct) + allow(Etc).to receive(:getgrgid).with(0).and_return(double("Group Ent", :name => "wheel")) + allow(Etc).to receive(:getpwuid).with(0).and_return(double("User Ent", :name => "root")) provider.send(:load_resource_attributes_from_file, resource) end it "new_resource should record the new permission information" do - provider.new_resource.group.should == "wheel" - provider.new_resource.owner.should == "root" - provider.new_resource.mode.should == "0600" + expect(provider.new_resource.group).to eq("wheel") + expect(provider.new_resource.owner).to eq("root") + expect(provider.new_resource.mode).to eq("0600") end end context "when reporting security metadata on windows" do it "records the file owner" do - pending + skip end it "records rights for each user in the ACL" do - pending + skip end it "records deny_rights for each user in the ACL" do - pending + skip end end @@ -419,12 +419,12 @@ shared_examples_for Chef::Provider::File do [:create, :create_if_missing, :touch].each do |action| context "action #{action}" do it "raises EnclosingDirectoryDoesNotExist" do - lambda {provider.run_action(action)}.should raise_error(Chef::Exceptions::EnclosingDirectoryDoesNotExist) + expect {provider.run_action(action)}.to raise_error(Chef::Exceptions::EnclosingDirectoryDoesNotExist) end it "does not raise an exception in why-run mode" do Chef::Config[:why_run] = true - lambda {provider.run_action(action)}.should_not raise_error + expect {provider.run_action(action)}.not_to raise_error Chef::Config[:why_run] = false end end @@ -435,12 +435,12 @@ shared_examples_for Chef::Provider::File do before { setup_unwritable_file } it "action delete raises InsufficientPermissions" do - lambda {provider.run_action(:delete)}.should raise_error(Chef::Exceptions::InsufficientPermissions) + expect {provider.run_action(:delete)}.to raise_error(Chef::Exceptions::InsufficientPermissions) end it "action delete also raises InsufficientPermissions in why-run mode" do Chef::Config[:why_run] = true - lambda {provider.run_action(:delete)}.should raise_error(Chef::Exceptions::InsufficientPermissions) + expect {provider.run_action(:delete)}.to raise_error(Chef::Exceptions::InsufficientPermissions) Chef::Config[:why_run] = false end end @@ -449,10 +449,10 @@ shared_examples_for Chef::Provider::File do context "action create" do it "should create the file, update its contents and then set the acls on the file" do setup_missing_file - provider.should_receive(:do_create_file) - provider.should_receive(:do_contents_changes) - provider.should_receive(:do_acl_changes) - provider.should_receive(:load_resource_attributes_from_file) + expect(provider).to receive(:do_create_file) + expect(provider).to receive(:do_contents_changes) + expect(provider).to receive(:do_acl_changes) + expect(provider).to receive(:load_resource_attributes_from_file) provider.run_action(:create) end @@ -461,18 +461,18 @@ shared_examples_for Chef::Provider::File do before { setup_normal_file } it "should not create the file" do provider.load_current_resource - provider.deployment_strategy.should_not_receive(:create).with(resource_path) + expect(provider.deployment_strategy).not_to receive(:create).with(resource_path) provider.send(:do_create_file) - provider.send(:needs_creating?).should == false + expect(provider.send(:needs_creating?)).to eq(false) end end context "when the file does not exist" do before { setup_missing_file } it "should create the file" do provider.load_current_resource - provider.deployment_strategy.should_receive(:create).with(resource_path) + expect(provider.deployment_strategy).to receive(:create).with(resource_path) provider.send(:do_create_file) - provider.send(:needs_creating?).should == true + expect(provider.send(:needs_creating?)).to eq(true) end end end @@ -483,10 +483,10 @@ shared_examples_for Chef::Provider::File do setup_normal_file provider.load_current_resource tempfile = double('Tempfile', :path => "/tmp/foo-bar-baz") - content.stub(:tempfile).and_return(tempfile) - File.should_receive(:exists?).with("/tmp/foo-bar-baz").and_return(true) - tempfile.should_receive(:close).once - tempfile.should_receive(:unlink).once + allow(content).to receive(:tempfile).and_return(tempfile) + expect(File).to receive(:exists?).with("/tmp/foo-bar-baz").and_return(true) + expect(tempfile).to receive(:close).once + expect(tempfile).to receive(:unlink).once end context "when the contents have changed" do @@ -494,64 +494,64 @@ shared_examples_for Chef::Provider::File do let(:tempfile_sha256) { "42971f0ddce0cb20cf7660a123ffa1a1543beb2f1e7cd9d65858764a27f3201d" } let(:diff_for_reporting) { "+++\n---\n+foo\n-bar\n" } before do - provider.stub(:contents_changed?).and_return(true) + allow(provider).to receive(:contents_changed?).and_return(true) diff = double('Diff', :for_output => ['+++','---','+foo','-bar'], :for_reporting => diff_for_reporting ) - diff.stub(:diff).with(resource_path, tempfile_path).and_return(true) - provider.should_receive(:diff).at_least(:once).and_return(diff) - provider.should_receive(:managing_content?).at_least(:once).and_return(true) - provider.should_receive(:checksum).with(tempfile_path).and_return(tempfile_sha256) - provider.should_receive(:checksum).with(resource_path).and_return(tempfile_sha256) - provider.deployment_strategy.should_receive(:deploy).with(tempfile_path, normalized_path) + allow(diff).to receive(:diff).with(resource_path, tempfile_path).and_return(true) + expect(provider).to receive(:diff).at_least(:once).and_return(diff) + expect(provider).to receive(:managing_content?).at_least(:once).and_return(true) + expect(provider).to receive(:checksum).with(tempfile_path).and_return(tempfile_sha256) + expect(provider).to receive(:checksum).with(resource_path).and_return(tempfile_sha256) + expect(provider.deployment_strategy).to receive(:deploy).with(tempfile_path, normalized_path) end context "when the file was created" do - before { provider.should_receive(:needs_creating?).at_least(:once).and_return(true) } + before { expect(provider).to receive(:needs_creating?).at_least(:once).and_return(true) } it "does not backup the file and does not produce a diff for reporting" do - provider.should_not_receive(:do_backup) + expect(provider).not_to receive(:do_backup) provider.send(:do_contents_changes) - resource.diff.should be_nil + expect(resource.diff).to be_nil end end context "when the file was not created" do - before { provider.should_receive(:needs_creating?).at_least(:once).and_return(false) } + before { expect(provider).to receive(:needs_creating?).at_least(:once).and_return(false) } it "backs up the file and produces a diff for reporting" do - provider.should_receive(:do_backup) + expect(provider).to receive(:do_backup) provider.send(:do_contents_changes) - resource.diff.should == diff_for_reporting + expect(resource.diff).to eq(diff_for_reporting) end end end it "does nothing when the contents have not changed" do - provider.stub(:contents_changed?).and_return(false) - provider.should_not_receive(:diff) + allow(provider).to receive(:contents_changed?).and_return(false) + expect(provider).not_to receive(:diff) provider.send(:do_contents_changes) end end it "does nothing when there is no content to deploy (tempfile returned from contents is nil)" do - provider.send(:content).should_receive(:tempfile).at_least(:once).and_return(nil) - provider.should_not_receive(:diff) - lambda{ provider.send(:do_contents_changes) }.should_not raise_error + expect(provider.send(:content)).to receive(:tempfile).at_least(:once).and_return(nil) + expect(provider).not_to receive(:diff) + expect{ provider.send(:do_contents_changes) }.not_to raise_error end it "raises an exception when the content object returns a tempfile with a nil path" do tempfile = double('Tempfile', :path => nil) - provider.send(:content).should_receive(:tempfile).at_least(:once).and_return(tempfile) - lambda{ provider.send(:do_contents_changes) }.should raise_error + expect(provider.send(:content)).to receive(:tempfile).at_least(:once).and_return(tempfile) + expect{ provider.send(:do_contents_changes) }.to raise_error end it "raises an exception when the content object returns a tempfile that does not exist" do tempfile = double('Tempfile', :path => "/tmp/foo-bar-baz") - provider.send(:content).should_receive(:tempfile).at_least(:once).and_return(tempfile) - File.should_receive(:exists?).with("/tmp/foo-bar-baz").and_return(false) - lambda{ provider.send(:do_contents_changes) }.should raise_error + expect(provider.send(:content)).to receive(:tempfile).at_least(:once).and_return(tempfile) + expect(File).to receive(:exists?).with("/tmp/foo-bar-baz").and_return(false) + expect{ provider.send(:do_contents_changes) }.to raise_error end end context "do_acl_changes" do it "needs tests" do - pending + skip end end @@ -560,11 +560,11 @@ shared_examples_for Chef::Provider::File do before do setup_normal_file provider.load_current_resource - provider.stub(:resource_updated?).and_return(true) + allow(provider).to receive(:resource_updated?).and_return(true) end it "should check for selinux_enabled? by default" do - provider.should_receive(:selinux_enabled?) + expect(provider).to receive(:selinux_enabled?) provider.send(:do_selinux) end @@ -580,27 +580,27 @@ shared_examples_for Chef::Provider::File do context "when selinux is enabled on the system" do before do - provider.should_receive(:selinux_enabled?).and_return(true) + expect(provider).to receive(:selinux_enabled?).and_return(true) end it "restores security context on the file" do - provider.should_receive(:restore_security_context).with(normalized_path, false) + expect(provider).to receive(:restore_security_context).with(normalized_path, false) provider.send(:do_selinux) end it "restores security context recursively when told so" do - provider.should_receive(:restore_security_context).with(normalized_path, true) + expect(provider).to receive(:restore_security_context).with(normalized_path, true) provider.send(:do_selinux, true) end end context "when selinux is disabled on the system" do before do - provider.should_receive(:selinux_enabled?).and_return(false) + expect(provider).to receive(:selinux_enabled?).and_return(false) end it "should not restore security context" do - provider.should_not_receive(:restore_security_context) + expect(provider).not_to receive(:restore_security_context) provider.send(:do_selinux) end end @@ -617,7 +617,7 @@ shared_examples_for Chef::Provider::File do end it "should not check for selinux_enabled?" do - provider.should_not_receive(:selinux_enabled?) + expect(provider).not_to receive(:selinux_enabled?) provider.send(:do_selinux) end end @@ -625,11 +625,11 @@ shared_examples_for Chef::Provider::File do context "when resource is not updated" do before do - provider.stub(:resource_updated?).and_return(false) + allow(provider).to receive(:resource_updated?).and_return(false) end it "should not check for selinux_enabled?" do - provider.should_not_receive(:selinux_enabled?) + expect(provider).not_to receive(:selinux_enabled?) provider.send(:do_selinux) end end @@ -643,29 +643,29 @@ shared_examples_for Chef::Provider::File do context "when the file is not a symlink" do before { setup_normal_file } it "should backup and delete the file and be updated by the last action" do - provider.should_receive(:do_backup).at_least(:once).and_return(true) - File.should_receive(:delete).with(resource_path).and_return(true) + expect(provider).to receive(:do_backup).at_least(:once).and_return(true) + expect(File).to receive(:delete).with(resource_path).and_return(true) provider.run_action(:delete) - resource.should be_updated_by_last_action + expect(resource).to be_updated_by_last_action end end context "when the file is a symlink" do before { setup_symlink } it "should not backup the symlink" do - provider.should_not_receive(:do_backup) - File.should_receive(:delete).with(resource_path).and_return(true) + expect(provider).not_to receive(:do_backup) + expect(File).to receive(:delete).with(resource_path).and_return(true) provider.run_action(:delete) - resource.should be_updated_by_last_action + expect(resource).to be_updated_by_last_action end end end context "when the file is not writable" do before { setup_unwritable_file } it "should not try to backup or delete the file, and should not be updated by last action" do - provider.should_not_receive(:do_backup) - File.should_not_receive(:delete) - lambda { provider.run_action(:delete) }.should raise_error() - resource.should_not be_updated_by_last_action + expect(provider).not_to receive(:do_backup) + expect(File).not_to receive(:delete) + expect { provider.run_action(:delete) }.to raise_error() + expect(resource).not_to be_updated_by_last_action end end end @@ -674,10 +674,10 @@ shared_examples_for Chef::Provider::File do before { setup_missing_file } it "should not try to backup or delete the file, and should not be updated by last action" do - provider.should_not_receive(:do_backup) - File.should_not_receive(:delete) - lambda { provider.run_action(:delete) }.should_not raise_error - resource.should_not be_updated_by_last_action + expect(provider).not_to receive(:do_backup) + expect(File).not_to receive(:delete) + expect { provider.run_action(:delete) }.not_to raise_error + expect(resource).not_to be_updated_by_last_action end end end @@ -686,19 +686,19 @@ shared_examples_for Chef::Provider::File do context "when the file does not exist" do before { setup_missing_file } it "should update the atime/mtime on action_touch" do - File.should_receive(:utime).once - provider.should_receive(:action_create) + expect(File).to receive(:utime).once + expect(provider).to receive(:action_create) provider.run_action(:touch) - resource.should be_updated_by_last_action + expect(resource).to be_updated_by_last_action end end context "when the file exists" do before { setup_normal_file } it "should update the atime/mtime on action_touch" do - File.should_receive(:utime).once - provider.should_receive(:action_create) + expect(File).to receive(:utime).once + expect(provider).to receive(:action_create) provider.run_action(:touch) - resource.should be_updated_by_last_action + expect(resource).to be_updated_by_last_action end end end @@ -707,7 +707,7 @@ shared_examples_for Chef::Provider::File do context "when the file does not exist" do before { setup_missing_file } it "should call action_create" do - provider.should_receive(:action_create) + expect(provider).to receive(:action_create) provider.run_action(:create_if_missing) end end @@ -715,7 +715,7 @@ shared_examples_for Chef::Provider::File do context "when the file exists" do before { setup_normal_file } it "should not call action_create" do - provider.should_not_receive(:action_create) + expect(provider).not_to receive(:action_create) provider.run_action(:create_if_missing) end end @@ -728,27 +728,27 @@ shared_examples_for "a file provider with content field" do context "when testing managing_content?" do it "should be false when creating a file without content" do provider.action = :create - resource.stub(:content).and_return(nil) - resource.stub(:checksum).and_return(nil) - expect(provider.send(:managing_content?)).to be_false + allow(resource).to receive(:content).and_return(nil) + allow(resource).to receive(:checksum).and_return(nil) + expect(provider.send(:managing_content?)).to be_falsey end it "should be true when creating a file with content" do provider.action = :create - resource.stub(:content).and_return("flurbleblobbleblooble") - resource.stub(:checksum).and_return(nil) - expect(provider.send(:managing_content?)).to be_true + allow(resource).to receive(:content).and_return("flurbleblobbleblooble") + allow(resource).to receive(:checksum).and_return(nil) + expect(provider.send(:managing_content?)).to be_truthy end it "should be true when checksum is set on the content (no matter how crazy)" do provider.action = :create_if_missing - resource.stub(:checksum).and_return("1234123234234234") - resource.stub(:content).and_return(nil) - expect(provider.send(:managing_content?)).to be_true + allow(resource).to receive(:checksum).and_return("1234123234234234") + allow(resource).to receive(:content).and_return(nil) + expect(provider.send(:managing_content?)).to be_truthy end it "should be false when action is create_if_missing" do provider.action = :create_if_missing - resource.stub(:content).and_return("flurbleblobbleblooble") - resource.stub(:checksum).and_return(nil) - expect(provider.send(:managing_content?)).to be_false + allow(resource).to receive(:content).and_return("flurbleblobbleblooble") + allow(resource).to receive(:checksum).and_return(nil) + expect(provider.send(:managing_content?)).to be_falsey end end end @@ -757,32 +757,31 @@ shared_examples_for "a file provider with source field" do context "when testing managing_content?" do it "should be false when creating a file without content" do provider.action = :create - resource.stub(:content).and_return(nil) - resource.stub(:source).and_return(nil) - resource.stub(:checksum).and_return(nil) - expect(provider.send(:managing_content?)).to be_false + allow(resource).to receive(:content).and_return(nil) + allow(resource).to receive(:source).and_return(nil) + allow(resource).to receive(:checksum).and_return(nil) + expect(provider.send(:managing_content?)).to be_falsey end it "should be true when creating a file with content" do provider.action = :create - resource.stub(:content).and_return(nil) - resource.stub(:source).and_return("http://somewhere.com/something.php") - resource.stub(:checksum).and_return(nil) - expect(provider.send(:managing_content?)).to be_true + allow(resource).to receive(:content).and_return(nil) + allow(resource).to receive(:source).and_return("http://somewhere.com/something.php") + allow(resource).to receive(:checksum).and_return(nil) + expect(provider.send(:managing_content?)).to be_truthy end it "should be true when checksum is set on the content (no matter how crazy)" do provider.action = :create_if_missing - resource.stub(:content).and_return(nil) - resource.stub(:source).and_return(nil) - resource.stub(:checksum).and_return("1234123234234234") - expect(provider.send(:managing_content?)).to be_true + allow(resource).to receive(:content).and_return(nil) + allow(resource).to receive(:source).and_return(nil) + allow(resource).to receive(:checksum).and_return("1234123234234234") + expect(provider.send(:managing_content?)).to be_truthy end it "should be false when action is create_if_missing" do provider.action = :create_if_missing - resource.stub(:content).and_return(nil) - resource.stub(:source).and_return("http://somewhere.com/something.php") - resource.stub(:checksum).and_return(nil) - expect(provider.send(:managing_content?)).to be_false + allow(resource).to receive(:content).and_return(nil) + allow(resource).to receive(:source).and_return("http://somewhere.com/something.php") + allow(resource).to receive(:checksum).and_return(nil) + expect(provider.send(:managing_content?)).to be_falsey end end end - |