From c1799bb49712b9362b54e8bccae1e721ce6542e0 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Wed, 31 May 2017 02:00:27 +0530 Subject: [PATCH 01/11] Added tests for disk_cleanup and unremovable kegs --- Library/Homebrew/test/cleanup_spec.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Library/Homebrew/test/cleanup_spec.rb b/Library/Homebrew/test/cleanup_spec.rb index 4e5e42efac..81cd631474 100644 --- a/Library/Homebrew/test/cleanup_spec.rb +++ b/Library/Homebrew/test/cleanup_spec.rb @@ -63,6 +63,28 @@ describe Homebrew::Cleanup do end end + specify "::update_disk_cleanup_size" do + shutup do + described_class.instance_eval("@disk_cleanup_size = 0") + described_class.update_disk_cleanup_size(128) + end + expect(described_class.instance_variable_get("@disk_cleanup_size")).to eq(128) + end + + specify "::disk_cleanup_size" do + shutup do + described_class.instance_eval("@disk_cleanup_size = 0") + end + expect(described_class.disk_cleanup_size).to eq(described_class.instance_variable_get("@disk_cleanup_size")) + end + + specify "::unremovable_kegs" do + shutup do + described_class.unremovable_kegs + end + expect(described_class.instance_variable_get("@unremovable_kegs")).to eq([]) + end + specify "::cleanup_formula" do f1 = Class.new(Testball) do version "1.0" From 5e17d63010c74dd23f02222feb61b76f515908d4 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Wed, 19 Jul 2017 02:46:45 +0530 Subject: [PATCH 02/11] Added tests for ARGV prune 'all' --- Library/Homebrew/test/cleanup_spec.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Library/Homebrew/test/cleanup_spec.rb b/Library/Homebrew/test/cleanup_spec.rb index 81cd631474..f1a6e770ec 100644 --- a/Library/Homebrew/test/cleanup_spec.rb +++ b/Library/Homebrew/test/cleanup_spec.rb @@ -163,5 +163,21 @@ describe Homebrew::Cleanup do expect(npm_cache).not_to exist end + + it "cleans up files and directories with name containing -- if ARGV prune is all" do + a = (HOMEBREW_CACHE/"--a") + b = (HOMEBREW_CACHE/"b") + c = (HOMEBREW_CACHE/"c") + a.mkpath + b.mkpath + FileUtils.touch c + allow(ARGV).to receive(:value).with("prune").and_return("all") + shutup do + described_class.cleanup_cache + end + expect(a).not_to exist + expect(b).to exist + expect(c).not_to exist + end end end From 265d43444bcd09d5d54963161f2fe77cdef35ef9 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Fri, 4 Aug 2017 05:47:05 +0530 Subject: [PATCH 03/11] improved prune all test --- Library/Homebrew/test/cleanup_spec.rb | 41 +++++++++++++++++++-------- 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/Library/Homebrew/test/cleanup_spec.rb b/Library/Homebrew/test/cleanup_spec.rb index f1a6e770ec..da6796d5f3 100644 --- a/Library/Homebrew/test/cleanup_spec.rb +++ b/Library/Homebrew/test/cleanup_spec.rb @@ -164,20 +164,37 @@ describe Homebrew::Cleanup do expect(npm_cache).not_to exist end - it "cleans up files and directories with name containing -- if ARGV prune is all" do - a = (HOMEBREW_CACHE/"--a") - b = (HOMEBREW_CACHE/"b") - c = (HOMEBREW_CACHE/"c") - a.mkpath - b.mkpath - FileUtils.touch c + it "cleans up all files and directories" do + git = (HOMEBREW_CACHE/"gist--git") + gist = (HOMEBREW_CACHE/"gist") + svn = (HOMEBREW_CACHE/"gist--svn") + git.mkpath + gist.mkpath + FileUtils.touch svn allow(ARGV).to receive(:value).with("prune").and_return("all") - shutup do - described_class.cleanup_cache + begin + shutup do + described_class.cleanup_cache + end + expect(git).not_to exist + expect(gist).to exist + expect(svn).not_to exist + ensure + FileUtils.rm_rf(git) + FileUtils.rm_rf(gist) + FileUtils.rm_rf(svn) + end + end + + it "raises error when formula name is ambiguous" do + bottle = (HOMEBREW_CACHE/"foo-0.2.bottle.gz") + FileUtils.touch bottle + (HOMEBREW_CELLAR/"foo/foo-0.2").mkpath + begin + described_class.cleanup_cache + ensure + FileUtils.rm_rf(bottle) end - expect(a).not_to exist - expect(b).to exist - expect(c).not_to exist end end end From 134539aa55af17be779bc05fc18e1fabceaeb3d0 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Sat, 5 Aug 2017 06:06:33 +0530 Subject: [PATCH 04/11] Added tests for cleaning up old files in HOMEBREW_CACHE --- Library/Homebrew/test/cleanup_spec.rb | 61 ++++++++++++++++++--------- 1 file changed, 40 insertions(+), 21 deletions(-) diff --git a/Library/Homebrew/test/cleanup_spec.rb b/Library/Homebrew/test/cleanup_spec.rb index da6796d5f3..32ffbd3573 100644 --- a/Library/Homebrew/test/cleanup_spec.rb +++ b/Library/Homebrew/test/cleanup_spec.rb @@ -64,24 +64,18 @@ describe Homebrew::Cleanup do end specify "::update_disk_cleanup_size" do - shutup do - described_class.instance_eval("@disk_cleanup_size = 0") - described_class.update_disk_cleanup_size(128) - end + described_class.instance_eval("@disk_cleanup_size = 0") + described_class.update_disk_cleanup_size(128) expect(described_class.instance_variable_get("@disk_cleanup_size")).to eq(128) end specify "::disk_cleanup_size" do - shutup do - described_class.instance_eval("@disk_cleanup_size = 0") - end + described_class.instance_eval("@disk_cleanup_size = 0") expect(described_class.disk_cleanup_size).to eq(described_class.instance_variable_get("@disk_cleanup_size")) end specify "::unremovable_kegs" do - shutup do - described_class.unremovable_kegs - end + described_class.unremovable_kegs expect(described_class.instance_variable_get("@unremovable_kegs")).to eq([]) end @@ -173,9 +167,7 @@ describe Homebrew::Cleanup do FileUtils.touch svn allow(ARGV).to receive(:value).with("prune").and_return("all") begin - shutup do - described_class.cleanup_cache - end + described_class.cleanup_cache expect(git).not_to exist expect(gist).to exist expect(svn).not_to exist @@ -186,14 +178,41 @@ describe Homebrew::Cleanup do end end - it "raises error when formula name is ambiguous" do - bottle = (HOMEBREW_CACHE/"foo-0.2.bottle.gz") - FileUtils.touch bottle - (HOMEBREW_CELLAR/"foo/foo-0.2").mkpath - begin - described_class.cleanup_cache - ensure - FileUtils.rm_rf(bottle) + context "cleaning old files in HOMEBREW_CACHE" do + before(:each) do + @bottle = (HOMEBREW_CACHE/"testball-0.0.1.bottle.tar.gz") + @testball = (HOMEBREW_CACHE/"testball-0.0.1") + FileUtils.touch(@bottle) + FileUtils.touch(@testball) + (HOMEBREW_CELLAR/"testball"/"0.0.1").mkpath + FileUtils.touch(CoreTap.instance.formula_dir/"testball.rb") + end + + after(:each) do + FileUtils.rm_rf(@bottle) + FileUtils.rm_rf(@testball) + FileUtils.rm_rf(HOMEBREW_CELLAR/"testball") + FileUtils.rm_rf(CoreTap.instance.formula_dir/"testball.rb") + end + + it "cleans up file if outdated" do + allow(Utils::Bottles).to receive(:file_outdated?).with(any_args).and_return(true) + described_class.cleanup_cache + expect(@bottle).not_to exist + expect(@testball).not_to exist + end + + it "cleans up file if ARGV has -s and formula not installed" do + ARGV << "-s" + described_class.cleanup_cache + expect(@bottle).not_to exist + expect(@testball).not_to exist + end + + it "cleans up file if stale" do + puts described_class.cleanup_cache + expect(@bottle).not_to exist + expect(@testball).not_to exist end end end From 86f7d208d09c4ebb6e4ca3b4cbf82b563307d65d Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Sat, 5 Aug 2017 19:36:35 +0530 Subject: [PATCH 05/11] Added tests for prune? --- Library/Homebrew/test/cleanup_spec.rb | 37 ++++++++++++++++++--------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/Library/Homebrew/test/cleanup_spec.rb b/Library/Homebrew/test/cleanup_spec.rb index 32ffbd3573..a66157976e 100644 --- a/Library/Homebrew/test/cleanup_spec.rb +++ b/Library/Homebrew/test/cleanup_spec.rb @@ -63,22 +63,11 @@ describe Homebrew::Cleanup do end end - specify "::update_disk_cleanup_size" do - described_class.instance_eval("@disk_cleanup_size = 0") - described_class.update_disk_cleanup_size(128) - expect(described_class.instance_variable_get("@disk_cleanup_size")).to eq(128) - end - specify "::disk_cleanup_size" do described_class.instance_eval("@disk_cleanup_size = 0") expect(described_class.disk_cleanup_size).to eq(described_class.instance_variable_get("@disk_cleanup_size")) end - specify "::unremovable_kegs" do - described_class.unremovable_kegs - expect(described_class.instance_variable_get("@unremovable_kegs")).to eq([]) - end - specify "::cleanup_formula" do f1 = Class.new(Testball) do version "1.0" @@ -178,7 +167,20 @@ describe Homebrew::Cleanup do end end - context "cleaning old files in HOMEBREW_CACHE" do + it "cleans up VCS checkout directories with modified time < prune time" do + foo = (HOMEBREW_CACHE/"--foo") + foo.mkpath + allow(ARGV).to receive(:value).with("prune").and_return("1") + allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - 60 * 60 * 24 * 2) + begin + described_class.cleanup_cache + expect(foo).not_to exist + ensure + FileUtils.rm_rf(foo) + end + end + + context "cleans old files in HOMEBREW_CACHE" do before(:each) do @bottle = (HOMEBREW_CACHE/"testball-0.0.1.bottle.tar.gz") @testball = (HOMEBREW_CACHE/"testball-0.0.1") @@ -216,4 +218,15 @@ describe Homebrew::Cleanup do end end end + + specify "::prune?" do + foo = mktmpdir/"foo.rb" + foo.mkpath + allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - 60 * 60 * 24 * 2) + begin + expect(described_class.prune?(foo, days_default: "1")).to be_truthy + ensure + FileUtils.rm_rf(foo) + end + end end From 6b5e4bb938c38bf97e9fd31fde1813bf93fe1b4d Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Tue, 8 Aug 2017 00:25:01 +0530 Subject: [PATCH 06/11] Use let over instance_var --- Library/Homebrew/test/cleanup_spec.rb | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/Library/Homebrew/test/cleanup_spec.rb b/Library/Homebrew/test/cleanup_spec.rb index a66157976e..98cdb9bd07 100644 --- a/Library/Homebrew/test/cleanup_spec.rb +++ b/Library/Homebrew/test/cleanup_spec.rb @@ -181,18 +181,19 @@ describe Homebrew::Cleanup do end context "cleans old files in HOMEBREW_CACHE" do + let(:bottle) { (HOMEBREW_CACHE/"testball-0.0.1.bottle.tar.gz") } + let(:testball) { (HOMEBREW_CACHE/"testball-0.0.1") } + before(:each) do - @bottle = (HOMEBREW_CACHE/"testball-0.0.1.bottle.tar.gz") - @testball = (HOMEBREW_CACHE/"testball-0.0.1") - FileUtils.touch(@bottle) - FileUtils.touch(@testball) + FileUtils.touch(bottle) + FileUtils.touch(testball) (HOMEBREW_CELLAR/"testball"/"0.0.1").mkpath FileUtils.touch(CoreTap.instance.formula_dir/"testball.rb") end after(:each) do - FileUtils.rm_rf(@bottle) - FileUtils.rm_rf(@testball) + FileUtils.rm_rf(bottle) + FileUtils.rm_rf(testball) FileUtils.rm_rf(HOMEBREW_CELLAR/"testball") FileUtils.rm_rf(CoreTap.instance.formula_dir/"testball.rb") end @@ -200,21 +201,21 @@ describe Homebrew::Cleanup do it "cleans up file if outdated" do allow(Utils::Bottles).to receive(:file_outdated?).with(any_args).and_return(true) described_class.cleanup_cache - expect(@bottle).not_to exist - expect(@testball).not_to exist + expect(bottle).not_to exist + expect(testball).not_to exist end it "cleans up file if ARGV has -s and formula not installed" do ARGV << "-s" described_class.cleanup_cache - expect(@bottle).not_to exist - expect(@testball).not_to exist + expect(bottle).not_to exist + expect(testball).not_to exist end it "cleans up file if stale" do puts described_class.cleanup_cache - expect(@bottle).not_to exist - expect(@testball).not_to exist + expect(bottle).not_to exist + expect(testball).not_to exist end end end From e7c2efa42fbf1846ef32e86eb3bcd57482e399b4 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Tue, 8 Aug 2017 00:45:29 +0530 Subject: [PATCH 07/11] Corrected disk_cleanup_size test --- Library/Homebrew/test/cleanup_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/test/cleanup_spec.rb b/Library/Homebrew/test/cleanup_spec.rb index 98cdb9bd07..b1bf3fb18d 100644 --- a/Library/Homebrew/test/cleanup_spec.rb +++ b/Library/Homebrew/test/cleanup_spec.rb @@ -64,8 +64,8 @@ describe Homebrew::Cleanup do end specify "::disk_cleanup_size" do - described_class.instance_eval("@disk_cleanup_size = 0") - expect(described_class.disk_cleanup_size).to eq(described_class.instance_variable_get("@disk_cleanup_size")) + disk_cleanup_size = described_class.instance_variable_get(:@disk_cleanup_size) + expect(described_class.disk_cleanup_size).to eq(disk_cleanup_size) end specify "::cleanup_formula" do From 9a83856a4920e5e382df5025361bc405643d90f5 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Sun, 13 Aug 2017 04:21:07 +0530 Subject: [PATCH 08/11] Added attr_reader disk_cleanup_size --- Library/Homebrew/cleanup.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/cleanup.rb b/Library/Homebrew/cleanup.rb index d1f0b25163..3401612043 100644 --- a/Library/Homebrew/cleanup.rb +++ b/Library/Homebrew/cleanup.rb @@ -6,6 +6,10 @@ module Homebrew module Cleanup @disk_cleanup_size = 0 + class << self + attr_reader :disk_cleanup_size + end + module_function def cleanup @@ -21,10 +25,6 @@ module Homebrew @disk_cleanup_size += path_size end - def disk_cleanup_size - @disk_cleanup_size - end - def unremovable_kegs @unremovable_kegs ||= [] end From ec30de69c3b3e1c3afb3638e0e13d3518148871d Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Sun, 13 Aug 2017 04:21:26 +0530 Subject: [PATCH 09/11] Added tests for existence of files --- Library/Homebrew/test/cleanup_spec.rb | 108 +++++++++++++++++--------- 1 file changed, 73 insertions(+), 35 deletions(-) diff --git a/Library/Homebrew/test/cleanup_spec.rb b/Library/Homebrew/test/cleanup_spec.rb index b1bf3fb18d..cf3af5d352 100644 --- a/Library/Homebrew/test/cleanup_spec.rb +++ b/Library/Homebrew/test/cleanup_spec.rb @@ -63,11 +63,6 @@ describe Homebrew::Cleanup do end end - specify "::disk_cleanup_size" do - disk_cleanup_size = described_class.instance_variable_get(:@disk_cleanup_size) - expect(described_class.disk_cleanup_size).to eq(disk_cleanup_size) - end - specify "::cleanup_formula" do f1 = Class.new(Testball) do version "1.0" @@ -109,14 +104,30 @@ describe Homebrew::Cleanup do expect(f4).to be_installed end - specify "::cleanup_logs" do - path = (HOMEBREW_LOGS/"delete_me") - path.mkpath - ARGV << "--prune=all" + describe "::cleanup_logs" do + before do + path.mkpath + end - described_class.cleanup_logs + let(:path) { (HOMEBREW_LOGS/"delete_me") } - expect(path).not_to exist + it "cleans all logs if prune all" do + ARGV << "--prune=all" + described_class.cleanup_logs + expect(path).not_to exist + end + + it "cleans up logs if older than 14 days" do + allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - 60 * 60 * 24 * 15) + described_class.cleanup_logs + expect(path).not_to exist + end + + it "does not clean up logs less than 14 days old" do + allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - 60 * 60 * 24 * 2) + described_class.cleanup_logs + expect(path).to exist + end end describe "::cleanup_cache" do @@ -129,6 +140,15 @@ describe Homebrew::Cleanup do expect(incomplete).not_to exist end + it "cleans up 'glide_home'" do + glide_home = (HOMEBREW_CACHE/"glide_home") + glide_home.mkpath + + described_class.cleanup_cache + + expect(glide_home).not_to exist + end + it "cleans up 'java_cache'" do java_cache = (HOMEBREW_CACHE/"java_cache") java_cache.mkpath @@ -151,20 +171,28 @@ describe Homebrew::Cleanup do git = (HOMEBREW_CACHE/"gist--git") gist = (HOMEBREW_CACHE/"gist") svn = (HOMEBREW_CACHE/"gist--svn") + git.mkpath gist.mkpath FileUtils.touch svn + allow(ARGV).to receive(:value).with("prune").and_return("all") - begin - described_class.cleanup_cache - expect(git).not_to exist - expect(gist).to exist - expect(svn).not_to exist - ensure - FileUtils.rm_rf(git) - FileUtils.rm_rf(gist) - FileUtils.rm_rf(svn) - end + + described_class.cleanup_cache + + expect(git).not_to exist + expect(gist).to exist + expect(svn).not_to exist + end + + it "does not clean up directories that are not VCS checkouts" do + git = (HOMEBREW_CACHE/"git") + git.mkpath + allow(ARGV).to receive(:value).with("prune").and_return("all") + + described_class.cleanup_cache + + expect(git).to exist end it "cleans up VCS checkout directories with modified time < prune time" do @@ -172,12 +200,16 @@ describe Homebrew::Cleanup do foo.mkpath allow(ARGV).to receive(:value).with("prune").and_return("1") allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - 60 * 60 * 24 * 2) - begin - described_class.cleanup_cache - expect(foo).not_to exist - ensure - FileUtils.rm_rf(foo) - end + described_class.cleanup_cache + expect(foo).not_to exist + end + + it "does not clean up VCS checkout directories with modified time >= prune time" do + foo = (HOMEBREW_CACHE/"--foo") + foo.mkpath + allow(ARGV).to receive(:value).with("prune").and_return("1") + described_class.cleanup_cache + expect(foo).to exist end context "cleans old files in HOMEBREW_CACHE" do @@ -213,21 +245,27 @@ describe Homebrew::Cleanup do end it "cleans up file if stale" do - puts described_class.cleanup_cache + described_class.cleanup_cache expect(bottle).not_to exist expect(testball).not_to exist end end end - specify "::prune?" do - foo = mktmpdir/"foo.rb" - foo.mkpath - allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - 60 * 60 * 24 * 2) - begin + describe "::prune?" do + before do + foo.mkpath + end + + let(:foo) { mktmpdir/"foo.rb" } + + it "returns true when path_modified_time < days_default" do + allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - 60 * 60 * 24 * 2) expect(described_class.prune?(foo, days_default: "1")).to be_truthy - ensure - FileUtils.rm_rf(foo) + end + + it "returns true when path_modified_time >= days_default" do + expect(described_class.prune?(foo, days_default: "2")).to be_falsey end end end From 5f7a93bcebf2f18f4740f0fd5e676555880c5d71 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Sat, 19 Aug 2017 17:17:38 +0530 Subject: [PATCH 10/11] Corrected test name --- Library/Homebrew/test/cleanup_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/test/cleanup_spec.rb b/Library/Homebrew/test/cleanup_spec.rb index cf3af5d352..3e9cdc79cc 100644 --- a/Library/Homebrew/test/cleanup_spec.rb +++ b/Library/Homebrew/test/cleanup_spec.rb @@ -105,12 +105,12 @@ describe Homebrew::Cleanup do end describe "::cleanup_logs" do + let(:path) { (HOMEBREW_LOGS/"delete_me") } + before do path.mkpath end - let(:path) { (HOMEBREW_LOGS/"delete_me") } - it "cleans all logs if prune all" do ARGV << "--prune=all" described_class.cleanup_logs @@ -264,7 +264,7 @@ describe Homebrew::Cleanup do expect(described_class.prune?(foo, days_default: "1")).to be_truthy end - it "returns true when path_modified_time >= days_default" do + it "returns false when path_modified_time >= days_default" do expect(described_class.prune?(foo, days_default: "2")).to be_falsey end end From 01714b17ee4abd08082ef5a37810a7b21ec80d6a Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Sat, 26 Aug 2017 02:01:45 +0530 Subject: [PATCH 11/11] Used let for sec_in_a_day and removed redundant after(:each) block --- Library/Homebrew/test/cleanup_spec.rb | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/Library/Homebrew/test/cleanup_spec.rb b/Library/Homebrew/test/cleanup_spec.rb index 3e9cdc79cc..da262c5ca0 100644 --- a/Library/Homebrew/test/cleanup_spec.rb +++ b/Library/Homebrew/test/cleanup_spec.rb @@ -5,6 +5,7 @@ require "pathname" describe Homebrew::Cleanup do let(:ds_store) { Pathname.new("#{HOMEBREW_PREFIX}/Library/.DS_Store") } + let(:sec_in_a_day) { 60 * 60 * 24 } around(:each) do |example| begin @@ -118,13 +119,13 @@ describe Homebrew::Cleanup do end it "cleans up logs if older than 14 days" do - allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - 60 * 60 * 24 * 15) + allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - sec_in_a_day * 15) described_class.cleanup_logs expect(path).not_to exist end it "does not clean up logs less than 14 days old" do - allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - 60 * 60 * 24 * 2) + allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - sec_in_a_day * 2) described_class.cleanup_logs expect(path).to exist end @@ -199,7 +200,7 @@ describe Homebrew::Cleanup do foo = (HOMEBREW_CACHE/"--foo") foo.mkpath allow(ARGV).to receive(:value).with("prune").and_return("1") - allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - 60 * 60 * 24 * 2) + allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - sec_in_a_day * 2) described_class.cleanup_cache expect(foo).not_to exist end @@ -223,13 +224,6 @@ describe Homebrew::Cleanup do FileUtils.touch(CoreTap.instance.formula_dir/"testball.rb") end - after(:each) do - FileUtils.rm_rf(bottle) - FileUtils.rm_rf(testball) - FileUtils.rm_rf(HOMEBREW_CELLAR/"testball") - FileUtils.rm_rf(CoreTap.instance.formula_dir/"testball.rb") - end - it "cleans up file if outdated" do allow(Utils::Bottles).to receive(:file_outdated?).with(any_args).and_return(true) described_class.cleanup_cache @@ -257,10 +251,10 @@ describe Homebrew::Cleanup do foo.mkpath end - let(:foo) { mktmpdir/"foo.rb" } + let(:foo) { HOMEBREW_CACHE/"foo" } it "returns true when path_modified_time < days_default" do - allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - 60 * 60 * 24 * 2) + allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - sec_in_a_day * 2) expect(described_class.prune?(foo, days_default: "1")).to be_truthy end