get linkapps tests de-mockified

This commit is contained in:
phinze 2012-11-25 15:05:54 -06:00
parent 3ad61a5d56
commit c96ea20317
5 changed files with 66 additions and 28 deletions

View File

@ -25,6 +25,10 @@ class Cask
def self.appdir
@appdir ||= Pathname.new(File.expand_path("~/Applications"))
end
def self.set_appdir(canned_appdir)
@appdir = canned_appdir
end
def self.init
HOMEBREW_CACHE.mkpath unless HOMEBREW_CACHE.exist?

View File

@ -1,21 +1,33 @@
require 'test_helper'
describe Cask::CLI::Linkapps do
it "only links casks provided in arguments" 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')
it "only links casks mentioned when arguments are provided" do
caffeine = Cask.load('local-caffeine')
transmission = Cask.load('local-transmission')
shutup do
Cask::Installer.install caffeine
Cask::Installer.install transmission
Cask::CLI::Linkapps.run('local-transmission')
end
(Cask.appdir/"Transmission.app").must_be :symlink?
(Cask.appdir/"Caffeine.app").wont_be :symlink?
end
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)
caffeine = Cask.load('local-caffeine')
transmission = Cask.load('local-transmission')
Cask.expects(:installed).returns(['mock1', 'mock2', 'mock3'])
shutup do
Cask::Installer.install caffeine
Cask::Installer.install transmission
Cask::CLI::Linkapps.run
Cask::CLI::Linkapps.run
end
(Cask.appdir/"Transmission.app").must_be :symlink?
(Cask.appdir/"Caffeine.app").must_be :symlink?
end
end

View File

@ -0,0 +1,19 @@
# wire in a fake appdir for linkapps
CANNED_APPDIR = (HOMEBREW_REPOSITORY/"Applications")
Cask.set_appdir(CANNED_APPDIR)
module FakeAppdirHooks
def before_setup
super
CANNED_APPDIR.mkdir
end
def after_teardown
super
CANNED_APPDIR.rm_rf
end
end
class MiniTest::Spec
include FakeFetcherHooks
end

View File

@ -19,3 +19,19 @@ class Cask::FakeFetcher
@responses = {}
end
end
module FakeFetcherHooks
def before_setup
super
Cask::FakeFetcher.init
end
def after_teardown
super
Cask::FakeFetcher.clear
end
end
class MiniTest::Spec
include FakeFetcherHooks
end

View File

@ -21,7 +21,6 @@ HOMEBREW_LIBRARY = HOMEBREW_REPOSITORY/"Library"
# making homebrew's cache dir allows us to actually download casks in tests
HOMEBREW_CACHE.mkpath
# must be called after testing_env so at_exit hooks are in proper order
require 'minitest/spec'
require 'minitest/autorun'
@ -51,23 +50,11 @@ class TestHelper
end
require 'support/fake_fetcher'
require 'support/fake_appdir'
module FakeFetcherHooks
def before_setup
super
Cask::FakeFetcher.init
end
def after_teardown
super
Cask::FakeFetcher.clear
end
end
class MiniTest::Spec
include FakeFetcherHooks
end
# wire in a fake linkapps destination
canned_appdir = (HOMEBREW_REPOSITORY/"Applications").tap(&:mkdir)
Cask.set_appdir(canned_appdir)
# pretend like we installed the cask tap
project_root = Pathname.new(File.expand_path("#{File.dirname(__FILE__)}/../"))