Browse Source

make the Cask DSL resilient to unexpected methods

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 #179
phinze 12 years ago
parent
commit
2427fd6dd5
  1. 8
      lib/cask/dsl.rb
  2. 21
      test/cask/dsl_test.rb

8
lib/cask/dsl.rb

@ -14,10 +14,6 @@ module Cask::DSL
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
@ -50,5 +46,9 @@ module Cask::DSL
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
test/cask/dsl_test.rb

@ -26,11 +26,28 @@ describe Cask::DSL do
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

Loading…
Cancel
Save