From 3585155f1b1150a027af26434ab96aedd686ca66 Mon Sep 17 00:00:00 2001 From: kenta-s Date: Sat, 28 Jan 2017 00:53:21 +0900 Subject: Raise an error if FileUpdateChecker#execute is called with no block --- activesupport/lib/active_support/evented_file_update_checker.rb | 6 +++++- activesupport/lib/active_support/file_update_checker.rb | 6 +++++- activesupport/test/file_update_checker_shared_tests.rb | 7 +++++++ 3 files changed, 17 insertions(+), 2 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/evented_file_update_checker.rb b/activesupport/lib/active_support/evented_file_update_checker.rb index f54f88eb0a..4b09206e59 100644 --- a/activesupport/lib/active_support/evented_file_update_checker.rb +++ b/activesupport/lib/active_support/evented_file_update_checker.rb @@ -74,7 +74,11 @@ module ActiveSupport 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 diff --git a/activesupport/lib/active_support/file_update_checker.rb b/activesupport/lib/active_support/file_update_checker.rb index 2dbbfadac1..1af18541e3 100644 --- a/activesupport/lib/active_support/file_update_checker.rb +++ b/activesupport/lib/active_support/file_update_checker.rb @@ -74,7 +74,11 @@ module ActiveSupport 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 diff --git a/activesupport/test/file_update_checker_shared_tests.rb b/activesupport/test/file_update_checker_shared_tests.rb index 48cd387196..de8796bf06 100644 --- a/activesupport/test/file_update_checker_shared_tests.rb +++ b/activesupport/test/file_update_checker_shared_tests.rb @@ -273,4 +273,11 @@ module FileUpdateCheckerSharedTests 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 -- cgit v1.2.3