From c96ea203171ba7ab5efe0077817e4b9593538919 Mon Sep 17 00:00:00 2001 From: phinze Date: Sun, 25 Nov 2012 15:05:54 -0600 Subject: [PATCH] get linkapps tests de-mockified --- lib/cask.rb | 4 ++++ test/cli/linkapps_test.rb | 34 +++++++++++++++++++++++----------- test/support/fake_appdir.rb | 19 +++++++++++++++++++ test/support/fake_fetcher.rb | 16 ++++++++++++++++ test/test_helper.rb | 21 ++++----------------- 5 files changed, 66 insertions(+), 28 deletions(-) create mode 100644 test/support/fake_appdir.rb diff --git a/lib/cask.rb b/lib/cask.rb index 55e685a83..8219358fb 100644 --- a/lib/cask.rb +++ b/lib/cask.rb @@ -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? diff --git a/test/cli/linkapps_test.rb b/test/cli/linkapps_test.rb index e8b07e6eb..adcea0855 100644 --- a/test/cli/linkapps_test.rb +++ b/test/cli/linkapps_test.rb @@ -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') + + shutup do + Cask::Installer.install caffeine + Cask::Installer.install transmission - Cask.expects(:installed).returns(['mock1', 'mock2', 'mock3']) + Cask::CLI::Linkapps.run + end - Cask::CLI::Linkapps.run + (Cask.appdir/"Transmission.app").must_be :symlink? + (Cask.appdir/"Caffeine.app").must_be :symlink? end end diff --git a/test/support/fake_appdir.rb b/test/support/fake_appdir.rb new file mode 100644 index 000000000..59cfd7b3a --- /dev/null +++ b/test/support/fake_appdir.rb @@ -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 diff --git a/test/support/fake_fetcher.rb b/test/support/fake_fetcher.rb index b7047c8da..a81b41f36 100644 --- a/test/support/fake_fetcher.rb +++ b/test/support/fake_fetcher.rb @@ -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 diff --git a/test/test_helper.rb b/test/test_helper.rb index 7ae8b1966..9b576bdea 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -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__)}/../"))