Skip to content

Commit

Permalink
Raise an error if FileUpdateChecker#execute is called with no block
Browse files Browse the repository at this point in the history
  • Loading branch information
kenta-s committed Jan 27, 2017
1 parent d506f3d commit 3585155
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion activesupport/lib/active_support/file_update_checker.rb
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions activesupport/test/file_update_checker_shared_tests.rb
Expand Up @@ -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

0 comments on commit 3585155

Please sign in to comment.