diff --git a/lib/clockwork/event.rb b/lib/clockwork/event.rb index 7e6538f..6f7a4b0 100644 --- a/lib/clockwork/event.rb +++ b/lib/clockwork/event.rb @@ -74,8 +74,9 @@ def run_if?(t) end def validate_if_option(if_option) - if if_option && !if_option.respond_to?(:call) - raise ArgumentError.new(':if expects a callable object, but #{if_option} does not respond to call') + return unless if_option + unless if_option.respond_to?(:call) && if_option.respond_to?(:arity) && if_option.arity == 1 + raise ArgumentError.new(':if expects a callable object that accepts a single argument, but #{if_option} is not') end end end diff --git a/test/manager_test.rb b/test/manager_test.rb index c102c43..fe6a5df 100644 --- a/test/manager_test.rb +++ b/test/manager_test.rb @@ -260,6 +260,22 @@ def assert_wont_run(t) @manager.every(1.second, 'myjob', :if => true) end end + + it ":if does not respond to arity then raise ArgumentError" do + assert_raises(ArgumentError) do + callable = Class.new do + def call; end + end + + @manager.every(1.second, 'myjob', :if => callable.new) + end + end + + it ":if does not have an arity of 1 then raise ArgumentError" do + assert_raises(ArgumentError) do + @manager.every(1.second, 'myjob', :if => lambda {}) + end + end end describe "max_threads" do