Skip to content

Commit

Permalink
support for caveats
Browse files Browse the repository at this point in the history
i.e. custom messages printed after installing a cask

refs Homebrew#218
  • Loading branch information
phinze committed Apr 28, 2013
1 parent 021c6af commit 7a1a6a9
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 4 deletions.
8 changes: 5 additions & 3 deletions Casks/adobe-air.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions lib/cask/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def sums; self.class.sums || []; end

def linkables; self.class.linkables || {}; end

def caveats; ''; end

module ClassMethods
def homepage(homepage=nil)
@homepage ||= homepage
Expand Down
4 changes: 4 additions & 0 deletions lib/cask/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def install(cask)
end

ohai "Success! #{cask} installed to #{cask.destination_path}"

unless cask.caveats.empty?
ohai 'Caveats', cask.caveats
end
end

def uninstall(cask)
Expand Down
20 changes: 20 additions & 0 deletions test/cask/dsl_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,24 @@
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
8 changes: 8 additions & 0 deletions test/cask/installer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@
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
Expand Down
11 changes: 11 additions & 0 deletions test/support/Casks/with-caveats.rb
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ def self.must_output(test, lambda, expected)
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)
Expand Down

0 comments on commit 7a1a6a9

Please sign in to comment.