From fc739bf82e263b54dca30713388f3ffd712aba6a Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 16 Jun 2017 16:14:17 +0200 Subject: Add `trash` util. --- Library/Homebrew/test/utils/trash_spec.rb | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Library/Homebrew/test/utils/trash_spec.rb (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/utils/trash_spec.rb b/Library/Homebrew/test/utils/trash_spec.rb new file mode 100644 index 000000000..9f2f7df15 --- /dev/null +++ b/Library/Homebrew/test/utils/trash_spec.rb @@ -0,0 +1,32 @@ +require "open3" + +describe "trash", :needs_macos do + let(:executable) { HOMEBREW_LIBRARY_PATH/"utils/trash.swift" } + let(:dir) { mktmpdir } + let(:file) { dir/"new_file" } + + it "moves existing files to the trash" do + FileUtils.touch file + + expect(file).to exist + + out, err, status = Open3.capture3(executable, file) + + expect(out).to match %r{moved #{file} to .*/\.Trash/\.*} + expect(err).to be_empty + expect(status).to be_a_success + + expect(file).not_to exist + + trashed_path = out.sub(/^moved #{Regexp.escape(file.to_s)} to (.*)\n$/, '\1') + FileUtils.rm_f trashed_path + end + + it "fails when files don't exist" do + out, err, status = Open3.capture3(executable, file) + + expect(out).to be_empty + expect(err).to eq "could not move #{file} to trash\n" + expect(status).to be_a_failure + end +end -- cgit v1.2.3