Raise an error if FileUpdateChecker#execute is called with no block

This commit is contained in:
kenta-s 2017-01-28 00:53:21 +09:00
parent d506f3def1
commit 3585155f1b
3 changed files with 17 additions and 2 deletions

@ -74,7 +74,11 @@ def updated?
def execute
@updated.make_false
@block.call
if @block.nil?
raise ArgumentError, "no block given: #{self.inspect}, please pass a block when you initialize #{self.class}"
else
@block.call
end
end
def execute_if_updated

@ -74,7 +74,11 @@ def updated?
def execute
@last_watched = watched
@last_update_at = updated_at(@last_watched)
@block.call
if @block.nil?
raise ArgumentError, "no block given: #{self.inspect}, please pass a block when you initialize #{self.class}"
else
@block.call
end
ensure
@watched = nil
@updated_at = nil

@ -273,4 +273,11 @@ def run(*args)
assert checker.execute_if_updated
assert_equal 2, i
end
test "execute raises an ArgumentError if no block given" do
checker = new_checker([])
assert_raise ArgumentError do
checker.execute
end
end
end