fix linkapps and cleanup output

damn i'm getting burned by mocking in my tests - going to have to fix
something here
This commit is contained in:
phinze 2012-11-21 17:53:15 -06:00
parent 05192e534d
commit 3ac3ae6360
4 changed files with 10 additions and 12 deletions

View File

@ -1,19 +1,17 @@
module Cask::Actions
def linkapps
puts "looking in #{destination_path}/**/*.app"
puts "found #{Pathname.glob("#{destination_path}/**/*.app").inspect}"
Pathname.glob("#{destination_path}/**/*.app").each do |app|
destination = Cask.appdir.join(app.basename)
target = destination_path.join(app)
if destination.symlink?
puts "#{destination} exists but is symlink; removing and relinking"
puts "#{destination} -> #{target}"
# destination exists but is symlink; removing and relinking
puts "[#{self}] linking #{File.basename(destination)}"
destination.delete
destination.make_symlink(target)
elsif destination.directory? || destination.file?
puts "#{destination} already exists and is not a symlink, not linking #{self}"
puts "[#{self}] NOT linking #{File.basename(destination)} - already exists"
else
puts "#{destination} -> #{target}"
puts "[#{self}] linking #{File.basename(destination)}"
destination.make_symlink(target)
end
end

View File

@ -1,8 +1,8 @@
class Cask::CLI::Linkapps
def self.run(*args)
casks_to_link = args.empty? ? Cask.installed : args.map { |arg| Cask.load(arg) }
casks_to_link.each do |cask|
cask.linkapps
casks_to_link = args.empty? ? Cask.installed : args
casks_to_link.each do |cask_name|
Cask.load(cask_name).linkapps
end
end

View File

@ -18,7 +18,7 @@ describe Cask::Actions do
Cask::Installer.uninstall(@caffeine)
end
it "works with an applistion in the root directory" do
it "works with an application in the root directory" do
shutup do
@caffeine.linkapps
end

View File

@ -5,7 +5,6 @@ describe Cask::CLI::Linkapps do
mock_cask = mock()
mock_cask.expects(:linkapps).twice
Cask.expects(:load).with('adium').returns(mock_cask)
Cask.expects(:load).with('google-chrome').returns(mock_cask)
Cask::CLI::Linkapps.run('adium', 'google-chrome')
end
@ -13,8 +12,9 @@ describe Cask::CLI::Linkapps do
it "links all installed casks when no arguments supplied" do
mock_cask = mock()
mock_cask.expects(:linkapps).times(3)
Cask.expects(:load).times(3).returns(mock_cask)
Cask.expects(:installed).returns([mock_cask, mock_cask, mock_cask])
Cask.expects(:installed).returns(['mock1', 'mock2', 'mock3'])
Cask::CLI::Linkapps.run
end