提交 a22d431d 编写于 作者: X Xavier Noria

improves waiting in the file monitors suite

上级 9a59beac
......@@ -19,6 +19,16 @@ def teardown
def wait
sleep 1
end
def touch(files)
super
wait # wait for the events to fire
end
def rm_f(files)
super
wait
end
end
class FileEventedUpdateCheckerPathHelperTest < ActiveSupport::TestCase
......
......@@ -7,4 +7,13 @@ class FileUpdateCheckerTest < ActiveSupport::TestCase
def new_checker(files=[], dirs={}, &block)
ActiveSupport::FileUpdateChecker.new(files, dirs, &block)
end
def wait
# noop
end
def touch(files)
sleep 1 # let's wait a bit to ensure there's a new mtime
super
end
end
......@@ -3,15 +3,6 @@
module FileUpdateCheckerWithEnumerableTestCases
include FileUtils
def wait
# noop
end
def touch(files)
sleep 1
super
end
def setup
@tmpdir = Dir.mktmpdir(nil, __dir__)
......@@ -20,7 +11,7 @@ def setup
end
def teardown
rm_rf(@tmpdir)
FileUtils.rm_rf(@tmpdir)
end
def test_should_not_execute_the_block_if_no_paths_are_given
......@@ -47,7 +38,6 @@ def test_should_invoke_the_block_if_a_file_has_changed
checker = new_checker(@files) { i += 1 }
touch(@files)
wait
assert checker.execute_if_updated
assert_equal 1, i
......@@ -60,18 +50,16 @@ def test_updated_should_become_true_when_watched_files_are_deleted
assert !checker.updated?
rm_f(@files)
wait
assert checker.updated?
end
def test_should_be_robust_enough_to_handle_deleted_files
def test_should_detect_deleted_files
i = 0
checker = new_checker(@files) { i += 1 }
rm_f(@files)
wait
assert checker.execute_if_updated
assert_equal 1, i
......@@ -87,7 +75,6 @@ def test_should_be_robust_to_handle_files_with_wrong_modified_time
checker = new_checker(@files) { i += 1 }
touch(@files[1..-1])
wait
assert checker.execute_if_updated
assert_equal 1, i
......@@ -100,7 +87,6 @@ def test_should_cache_updated_result_until_execute
assert !checker.updated?
touch(@files)
wait
assert checker.updated?
checker.execute
......@@ -113,7 +99,6 @@ def test_should_invoke_the_block_if_a_watched_dir_changes
checker = new_checker([], @tmpdir => :rb) { i += 1 }
touch(@files)
wait
assert checker.execute_if_updated
assert_equal 1, i
......@@ -125,7 +110,6 @@ def test_should_not_invoke_the_block_if_a_watched_dir_does_not_change
checker = new_checker([], @tmpdir => :txt) { i += 1 }
touch(@files)
wait
assert !checker.execute_if_updated
assert_equal 0, i
......@@ -138,7 +122,6 @@ def test_does_not_assume_files_exist_on_instantiation
checker = new_checker([non_existing]) { i += 1 }
touch(non_existing)
wait
assert checker.execute_if_updated
assert_equal 1, i
......@@ -157,7 +140,6 @@ def test_detects_files_in_new_subdirectories
assert_equal 0, i
touch("#{subdir}/nested.rb")
wait
assert checker.execute_if_updated
assert_equal 1, i
......@@ -172,20 +154,17 @@ def test_looked_up_extensions_are_inherited_in_subdirectories_not_listening_to_t
checker = new_checker([], @tmpdir => :rb, subdir => :txt) { i += 1 }
touch("#{@tmpdir}/new.txt")
wait
assert !checker.execute_if_updated
assert_equal 0, i
# subdir does not look for Ruby files, but its parent @tmpdir does.
touch("#{subdir}/nested.rb")
wait
assert checker.execute_if_updated
assert_equal 1, i
touch("#{subdir}/nested.txt")
wait
assert checker.execute_if_updated
assert_equal 2, i
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册