Browse Source

have linkapps recognizes apps in subdirs

should address #33

includes cleanup and tests

i'm not crazy about leaning on installing/uninstalling caffeine in the
tests. it makes for some unnecessarily heavy tests and downloads. but
i'd rather get tests in place first then fix the warts.
phinze 13 years ago
parent
commit
96cff81979
  1. 6
      lib/cask.rb
  2. 26
      lib/cask/actions.rb
  3. 49
      test/cask/actions_test.rb
  4. 0
      test/cask/dsl_test.rb

6
lib/cask.rb

@ -3,8 +3,6 @@ require 'formula_support'
require 'plist/parser'
require 'uri'
HOME_APPS = Pathname.new(File.expand_path("~/Applications"))
class Cask; end
require 'cask/cli'
@ -32,6 +30,10 @@ class Cask
def self.cellarpath
HOMEBREW_CELLAR
end
def self.appdir
Pathname.new(File.expand_path("~/Applications"))
end
def self.init
HOMEBREW_CACHE.mkpath

26
lib/cask/actions.rb

@ -4,19 +4,21 @@ module Cask::Actions
end
def linkapps
destination_path.entries.select { |f| f.basename.to_s =~ /.app$/ }.each do |app|
symlink_destination = HOME_APPS.join(app.basename)
symlink_target = destination_path.join(app)
if symlink_destination.symlink?
puts "#{symlink_destination} exists but is symlink; removing and relinking"
puts "#{symlink_destination} -> #{symlink_target}"
symlink_destination.delete
symlink_destination.make_symlink(symlink_target)
elsif symlink_destination.directory? || symlink_destination.file?
puts "#{symlink_destination} already exists and is not a symlink, not linking #{self}"
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.delete
destination.make_symlink(target)
elsif destination.directory? || destination.file?
puts "#{destination} already exists and is not a symlink, not linking #{self}"
else
puts "#{symlink_destination} -> #{symlink_target}"
symlink_destination.make_symlink(symlink_target)
puts "#{destination} -> #{target}"
destination.make_symlink(target)
end
end
end

49
test/cask/actions_test.rb

@ -0,0 +1,49 @@
require 'test_helper'
require 'cmd/uninstall'
describe Cask::Actions do
describe 'linkapps' do
before do
fake_appdir = HOMEBREW_PREFIX/"Applications"
fake_appdir.mkpath
Cask.stubs(:appdir).returns(fake_appdir)
@caffeine = Cask.load('caffeine')
shutup { @caffeine.install }
@appdir = HOMEBREW_CELLAR/'caffeine'/@caffeine.version
@app = @appdir/'Caffeine.app'
end
after do
ARGV.replace ['caffeine']
shutup { Homebrew.uninstall }
end
it "works with an applistion in the root directory" do
shutup do
@caffeine.linkapps
end
expected_symlink = Cask.appdir/'Caffeine.app'
expected_symlink.must_be :exist?
expected_symlink.must_be :symlink?
expected_symlink.readlink.must_equal @app
end
it "works with an application in a subdir" do
appsubdir = @appdir/'subdir'
appsubdir.mkpath
FileUtils.mv @app, appsubdir
appinsubdir = appsubdir/'Caffeine.app'
shutup do
@caffeine.linkapps
end
expected_symlink = Cask.appdir/'Caffeine.app'
expected_symlink.must_be :exist?
expected_symlink.must_be :symlink?
expected_symlink.readlink.must_equal appinsubdir
end
end
end

0
test/dsl_test.rb → test/cask/dsl_test.rb

Loading…
Cancel
Save