diff options
| author | Markus Reiter | 2017-05-19 20:27:25 +0200 |
|---|---|---|
| committer | Markus Reiter | 2017-05-22 02:51:16 +0200 |
| commit | b7347dcc445fe1b3a61a79152c09c0d52fc4ea28 (patch) | |
| tree | 6e97b2d7df2baa15f1b18b50219fd4acf8acc31d /Library/Homebrew/test | |
| parent | 58db95c1d23b8269dffd654afb0b8b12b46a51ce (diff) | |
| download | brew-b7347dcc445fe1b3a61a79152c09c0d52fc4ea28.tar.bz2 | |
Refactor `CLI::Cleanup`.
Diffstat (limited to 'Library/Homebrew/test')
| -rw-r--r-- | Library/Homebrew/test/cask/cli/cleanup_spec.rb | 90 |
1 files changed, 36 insertions, 54 deletions
diff --git a/Library/Homebrew/test/cask/cli/cleanup_spec.rb b/Library/Homebrew/test/cask/cli/cleanup_spec.rb index c7ef356c0..037fa1bd4 100644 --- a/Library/Homebrew/test/cask/cli/cleanup_spec.rb +++ b/Library/Homebrew/test/cask/cli/cleanup_spec.rb @@ -1,19 +1,20 @@ describe Hbc::CLI::Cleanup, :cask do let(:cache_location) { Pathname.new(Dir.mktmpdir).realpath } - let(:cleanup_outdated) { false } + let(:outdated_only) { false } - subject { described_class.new(cache_location, cleanup_outdated) } + subject { described_class.new(*cask_tokens, cache_location: cache_location, outdated_only: outdated_only) } after do cache_location.rmtree end describe "cleanup" do - it "removes cached downloads of given casks" do - cleaned_up_cached_download = "caffeine" + let(:cask_token) { "caffeine" } + let(:cask_tokens) { [cask_token] } + it "removes cached downloads of given casks" do cached_downloads = [ - cache_location.join("#{cleaned_up_cached_download}--latest.zip"), + cache_location.join("#{cask_token}--latest.zip"), cache_location.join("transmission--2.61.dmg"), ] @@ -22,9 +23,9 @@ describe Hbc::CLI::Cleanup, :cask do cleanup_size = cached_downloads[0].disk_usage expect { - subject.cleanup(cleaned_up_cached_download) + subject.run }.to output(<<-EOS.undent).to_stdout - ==> Removing cached downloads for #{cleaned_up_cached_download} + ==> Removing cached downloads for #{cask_token} #{cached_downloads[0]} ==> This operation has freed approximately #{disk_usage_readable(cleanup_size)} of disk space. EOS @@ -32,61 +33,42 @@ describe Hbc::CLI::Cleanup, :cask do expect(cached_downloads[0].exist?).to eq(false) expect(cached_downloads[1].exist?).to eq(true) end - end - - describe "cleanup!" do - it "removes cached downloads" do - cached_download = cache_location.join("SomeDownload.dmg") - FileUtils.touch(cached_download) - cleanup_size = subject.disk_cleanup_size - expect { - subject.cleanup! - }.to output(<<-EOS.undent).to_stdout - ==> Removing cached downloads - #{cached_download} - ==> This operation has freed approximately #{disk_usage_readable(cleanup_size)} of disk space. - EOS + context "when no argument is given" do + let(:cask_tokens) { [] } - expect(cached_download.exist?).to eq(false) - end - - # TODO: uncomment when unflaky. - # it "does not removed locked files" do - # cached_download = cache_location.join("SomeDownload.dmg") - # FileUtils.touch(cached_download) - # cleanup_size = subject.disk_cleanup_size - # - # File.new(cached_download).flock(File::LOCK_EX) - # - # expect(Hbc::Utils).to be_file_locked(cached_download) - # - # expect { - # subject.cleanup! - # }.to output(<<-EOS.undent).to_stdout - # ==> Removing cached downloads - # skipping: #{cached_download} is locked - # ==> This operation has freed approximately #{disk_usage_readable(cleanup_size)} of disk space. - # EOS - # - # expect(cached_download.exist?).to eq(true) - # end - - context "when cleanup_outdated is specified" do - let(:cleanup_outdated) { true } - - it "does not remove cache files newer than 10 days old" do - cached_download = cache_location.join("SomeNewDownload.dmg") + it "removes all cached downloads" do + cached_download = cache_location.join("SomeDownload.dmg") FileUtils.touch(cached_download) + cleanup_size = subject.disk_cleanup_size expect { - subject.cleanup! + subject.run }.to output(<<-EOS.undent).to_stdout - ==> Removing cached downloads older than 10 days old - Nothing to do + ==> Removing cached downloads + #{cached_download} + ==> This operation has freed approximately #{disk_usage_readable(cleanup_size)} of disk space. EOS - expect(cached_download.exist?).to eq(true) + expect(cached_download.exist?).to eq(false) + end + + context "and :outdated_only is specified" do + let(:outdated_only) { true } + + it "does not remove cache files newer than 10 days old" do + cached_download = cache_location.join("SomeNewDownload.dmg") + FileUtils.touch(cached_download) + + expect { + subject.run + }.to output(<<-EOS.undent).to_stdout + ==> Removing cached downloads older than 10 days old + Nothing to do + EOS + + expect(cached_download.exist?).to eq(true) + end end end end |
