Skip to content

Commit

Permalink
make the Cask DSL resilient to unexpected methods
Browse files Browse the repository at this point in the history
will help with introducing and removing features, since the Cask
definitions move with every `brew update` and track master but the code
to handle them requires an explicit release and a `brew upgrade brew-cask`

relates to Homebrew#179
  • Loading branch information
phinze committed Apr 7, 2013
1 parent 6c3dd49 commit 2427fd6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
8 changes: 4 additions & 4 deletions lib/cask/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ def version; self.class.version; end
def sums; self.class.sums || []; end

module ClassMethods
def content_length(content_length=nil)
# deprecated, but retained for backwards compatibility
end

def homepage(homepage=nil)
@homepage ||= homepage
end
Expand Down Expand Up @@ -50,5 +46,9 @@ def sha256(sha2=nil)
def no_checksum
@sums = 0
end

def method_missing(method, *args)
opoo "Unexpected method #{method} called on #{self}. Running `brew update; brew upgrade brew-cask` will likely fix it."
end
end
end
21 changes: 19 additions & 2 deletions test/cask/dsl_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,28 @@
it "still lets you set content_length even though it is deprecated" do
OldContentLengthCask = Class.new(Cask)
begin
OldContentLengthCask.class_eval do
content_length '12345'
shutup do
OldContentLengthCask.class_eval do
content_length '12345'
end
end
rescue Exception => e
flunk("expected content_length to work, but got exception #{e}")
end
end

it "prevents the entire world from crashing when a cask includes an unknown method" do
UnexpectedMethodCask = Class.new(Cask)
begin
lambda {
UnexpectedMethodCask.class_eval do
future_feature :not_yet_on_your_machine
end
}.must_output(
"Warning: Unexpected method future_feature called on UnexpectedMethodCask. Running `brew update; brew upgrade brew-cask` will likely fix it.\n"
)
rescue Exception => e
flunk("Wanted unexpected method to simply warn, but got exception #{e}")
end
end
end

0 comments on commit 2427fd6

Please sign in to comment.