Browse Source

Verify appdir after reading command line opts

Helps prevent default appdir from being created regardless of whether
the user configured it or not.

Closes #496
Keith Smiley 12 years ago
committed by phinze
parent
commit
6404f82d09
  1. 5
      lib/cask.rb
  2. 2
      lib/cask/cli.rb
  3. 32
      test/cask/cli_test.rb
  4. 2
      test/support/fake_appdir.rb
  5. 1
      test/test_helper.rb

5
lib/cask.rb

@ -47,8 +47,9 @@ class Cask
ohai "We need to make Caskroom for the first time at #{caskroom}"
ohai "We'll set permissions properly so we won't need sudo in the future"
current_user = ENV['USER']
system "sudo mkdir -p #{caskroom}"
system "sudo chown -R #{current_user}:staff #{caskroom.parent}"
sudo = 'sudo' unless caskroom.parent.writable?
system "#{sudo} mkdir -p #{caskroom}"
system "#{sudo} chown -R #{current_user}:staff #{caskroom.parent}"
end
appdir.mkpath unless appdir.exist?
end

2
lib/cask/cli.rb

@ -15,9 +15,9 @@ class Cask::CLI
end
def self.process(arguments)
Cask.init
command, *rest = *arguments
rest = process_options(rest)
Cask.init
lookup_command(command).run(*rest)
end

32
test/cask/cli_test.rb

@ -12,4 +12,36 @@ describe Cask::CLI do
phinze-cask/adium
])
end
describe "process" do
it "creates the appdir if it does not exist" do
Cask.appdir.rmdir
shutup {
Cask::CLI.process('list')
}
Cask.appdir.directory?.must_equal true
end
it "respects the env variable when choosing what appdir to create, not touching the default appdir" do
default_applications_dir = Cask.appdir
default_applications_dir.rmdir
custom_applications_dir = Pathname(Dir.mktmpdir('custom_app_dir'))
custom_applications_dir.rmdir
default_applications_dir.directory?.must_equal false
custom_applications_dir.directory?.must_equal false
begin
ENV['HOMEBREW_CASK_OPTS'] = "--appdir=#{custom_applications_dir}"
shutup {
Cask::CLI.process('list')
}
ensure
ENV.delete 'HOMEBREW_CASK_OPTS'
end
default_applications_dir.directory?.must_equal false
custom_applications_dir.directory?.must_equal true
end
end
end

2
test/support/fake_appdir.rb

@ -9,7 +9,7 @@ module FakeAppdirHooks
def after_teardown
super
@canned_appdir.rmtree
@canned_appdir.rmtree if @canned_appdir.exist?
end
end

1
test/test_helper.rb

@ -73,6 +73,7 @@ require 'support/fake_fetcher'
require 'support/fake_appdir'
require 'support/fake_system_command'
require 'support/cleanup'
require 'tmpdir'
# pretend like we installed the cask tap
project_root = Pathname.new(File.expand_path("#{File.dirname(__FILE__)}/../"))

Loading…
Cancel
Save