From 7a1a6a9308eefca86f7ad750838086e78de84077 Mon Sep 17 00:00:00 2001 From: phinze Date: Sun, 28 Apr 2013 11:08:54 -0500 Subject: [PATCH] support for caveats i.e. custom messages printed after installing a cask refs #218 --- Casks/adobe-air.rb | 8 +++++--- lib/cask/dsl.rb | 2 ++ lib/cask/installer.rb | 4 ++++ test/cask/dsl_test.rb | 20 ++++++++++++++++++++ test/cask/installer_test.rb | 8 ++++++++ test/support/Casks/with-caveats.rb | 11 +++++++++++ test/test_helper.rb | 6 +++++- 7 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 test/support/Casks/with-caveats.rb diff --git a/Casks/adobe-air.rb b/Casks/adobe-air.rb index bf5e9af93..74720017b 100644 --- a/Casks/adobe-air.rb +++ b/Casks/adobe-air.rb @@ -2,10 +2,12 @@ class AdobeAir < Cask url 'http://airdownload.adobe.com/air/mac/download/3.5/AdobeAIR.dmg' homepage 'https://get.adobe.com/air/' version '3.5' - - #caveat 'You need to run {{install_path}}/AdobeAIRInstaller.app to actually install Adobe AIR' - sha1 '8fbd2dffc20442903d8b51e7362a3191f39752b4' link :app, :none + + def caveats; <<-EOS.undent + You need to run #{destination_path/'AdobeAIRInstaller.app'} to actually install Adobe AIR + EOS + end end diff --git a/lib/cask/dsl.rb b/lib/cask/dsl.rb index 1cb438fc6..cb124021f 100644 --- a/lib/cask/dsl.rb +++ b/lib/cask/dsl.rb @@ -16,6 +16,8 @@ module Cask::DSL def linkables; self.class.linkables || {}; end + def caveats; ''; end + module ClassMethods def homepage(homepage=nil) @homepage ||= homepage diff --git a/lib/cask/installer.rb b/lib/cask/installer.rb index 59deca2dc..97f12827f 100644 --- a/lib/cask/installer.rb +++ b/lib/cask/installer.rb @@ -17,6 +17,10 @@ class Cask::Installer end ohai "Success! #{cask} installed to #{cask.destination_path}" + + unless cask.caveats.empty? + ohai 'Caveats', cask.caveats + end end def uninstall(cask) diff --git a/test/cask/dsl_test.rb b/test/cask/dsl_test.rb index aaeb8034a..87b3f6e92 100644 --- a/test/cask/dsl_test.rb +++ b/test/cask/dsl_test.rb @@ -69,4 +69,24 @@ describe Cask::DSL do instance = CaskWithNoLinkables.new Array(instance.linkable_apps).must_equal %w[] end + + it "allows caveats to be specified via a method define" do + PlainCask = Class.new(Cask) + + instance = PlainCask.new + + instance.caveats.must_be :empty? + + CaskWithCaveats = Class.new(Cask) + CaskWithCaveats.class_eval do + def caveats; <<-EOS.undent + When you install this cask, you probably want to know this. + EOS + end + end + + instance = CaskWithCaveats.new + + instance.caveats.must_equal "When you install this cask, you probably want to know this.\n" + end end diff --git a/test/cask/installer_test.rb b/test/cask/installer_test.rb index 086025386..afd735a91 100644 --- a/test/cask/installer_test.rb +++ b/test/cask/installer_test.rb @@ -53,6 +53,14 @@ describe Cask::Installer do end no_checksum.must_be :installed? end + + it "prints caveats if they're present" do + with_caveats = Cask.load('with-caveats') + TestHelper.must_output(self, lambda { + Cask::Installer.install(with_caveats) + }, /Here are some things you might want to know/) + with_caveats.must_be :installed? + end end describe "uninstall" do diff --git a/test/support/Casks/with-caveats.rb b/test/support/Casks/with-caveats.rb new file mode 100644 index 000000000..c4a4fe6f4 --- /dev/null +++ b/test/support/Casks/with-caveats.rb @@ -0,0 +1,11 @@ +class WithCaveats < TestCask + url TestHelper.local_binary('caffeine.zip') + homepage 'http://example.com/local-caffeine' + version '1.2.3' + sha1 'd2fbdad1619934313026fc831e6c6e3dd97ac030' + + def caveats; <<-EOS.undent + Here are some things you might want to know. + EOS + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index 88c06476a..cb4bf18e6 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -58,7 +58,11 @@ class TestHelper lambda.call end - (out+err).chomp.must_equal expected.gsub(/^ */, '') + if expected.is_a? Regexp + (out+err).chomp.must_match expected + else + (out+err).chomp.must_equal expected.gsub(/^ */, '') + end end def self.valid_alias?(candidate)