From 2427fd6dd5dd487604e85a4bd9639bcb62f7aa44 Mon Sep 17 00:00:00 2001 From: phinze Date: Sun, 7 Apr 2013 11:56:14 -0500 Subject: [PATCH] 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 --- lib/cask/dsl.rb | 8 ++++---- test/cask/dsl_test.rb | 21 +++++++++++++++++++-- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/lib/cask/dsl.rb b/lib/cask/dsl.rb index 394358756..de29abb96 100644 --- a/lib/cask/dsl.rb +++ b/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 diff --git a/test/cask/dsl_test.rb b/test/cask/dsl_test.rb index 74d356c47..aba44c7c5 100644 --- a/test/cask/dsl_test.rb +++ b/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