Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
087a79ab
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
087a79ab
编写于
10月 12, 2015
作者:
X
Xavier Noria
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
initial edit pass over the evented file checker patch
上级
785adabc
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
67 addition
and
41 deletion
+67
-41
activesupport/test/file_evented_update_checker_test.rb
activesupport/test/file_evented_update_checker_test.rb
+4
-11
activesupport/test/file_update_checker_test.rb
activesupport/test/file_update_checker_test.rb
+3
-2
activesupport/test/file_update_checker_with_enumerable_test_cases.rb
...rt/test/file_update_checker_with_enumerable_test_cases.rb
+60
-28
未找到文件。
activesupport/test/file_evented_update_checker_test.rb
浏览文件 @
087a79ab
...
...
@@ -3,19 +3,12 @@
require
'thread'
require
'file_update_checker_with_enumerable_test_cases'
MTIME_FIXTURES_PATH
=
File
.
expand_path
(
"../fixtures"
,
__FILE__
)
MTIME_FIXTURES_PATH
=
File
.
expand_path
(
'fixtures'
,
__dir__
)
class
FileEventedUpdateCheckerTest
<
ActiveSupport
::
TestCase
include
FileUpdateCheckerWithEnumerableTestCases
class
FileEventedUpdateCheckerWithEnumerableTest
<
ActiveSupport
::
TestCase
include
FileUpdateCheckerWithEnumerableTestCases
def
build_new_watcher
(
files
,
dirs
=
{},
&
block
)
ActiveSupport
::
FileEventedUpdateChecker
.
new
(
files
,
dirs
,
&
block
)
end
def
test_modified_should_become_true_when_watched_file_is_updated
watcher
=
ActiveSupport
::
FileEventedUpdateChecker
.
new
(
FILES
){
i
+=
1
}
assert_equal
watcher
.
updated?
,
false
FileUtils
.
rm
(
FILES
)
sleep
1
assert_equal
watcher
.
updated?
,
true
end
end
activesupport/test/file_update_checker_test.rb
浏览文件 @
087a79ab
...
...
@@ -3,10 +3,11 @@
require
'thread'
require
'file_update_checker_with_enumerable_test_cases'
MTIME_FIXTURES_PATH
=
File
.
expand_path
(
"../fixtures"
,
__FILE
__
)
MTIME_FIXTURES_PATH
=
File
.
expand_path
(
'fixtures'
,
__dir
__
)
class
FileUpdateChecker
WithEnumerable
Test
<
ActiveSupport
::
TestCase
class
FileUpdateCheckerTest
<
ActiveSupport
::
TestCase
include
FileUpdateCheckerWithEnumerableTestCases
def
build_new_watcher
(
files
,
dirs
=
{},
&
block
)
ActiveSupport
::
FileUpdateChecker
.
new
(
files
,
dirs
,
&
block
)
end
...
...
activesupport/test/file_update_checker_with_enumerable_test_cases.rb
浏览文件 @
087a79ab
...
...
@@ -2,71 +2,95 @@ module FileUpdateCheckerWithEnumerableTestCases
FILES
=
%w(1.txt 2.txt 3.txt)
def
setup
FileUtils
.
mkdir_p
(
"tmp_watcher"
)
FileUtils
.
mkdir_p
(
'tmp_watcher'
)
FileUtils
.
touch
(
FILES
)
end
def
teardown
FileUtils
.
rm_rf
(
"tmp_watcher"
)
FileUtils
.
rm_rf
(
'tmp_watcher'
)
FileUtils
.
rm_rf
(
FILES
)
end
def
test_should_not_execute_the_block_if_no_paths_are_given
i
=
0
checker
=
build_new_watcher
([]){
i
+=
1
}
checker
=
build_new_watcher
([])
{
i
+=
1
}
checker
.
execute_if_updated
assert_equal
0
,
i
end
def
test_should_not_invoke_the_block_if_no_file_has_changed
i
=
0
checker
=
build_new_watcher
(
FILES
){
i
+=
1
}
5
.
times
{
assert
!
checker
.
execute_if_updated
}
checker
=
build_new_watcher
(
FILES
)
{
i
+=
1
}
assert
!
checker
.
execute_if_updated
assert_equal
0
,
i
end
def
test_should_invoke_the_block_if_a_file_has_changed
i
=
0
checker
=
build_new_watcher
(
FILES
){
i
+=
1
}
sleep
(
1
)
checker
=
build_new_watcher
(
FILES
)
{
i
+=
1
}
sleep
1
FileUtils
.
touch
(
FILES
)
sleep
(
1
)
#extra
sleep
1
assert
checker
.
execute_if_updated
assert_equal
1
,
i
end
def
test_updated_should_become_true_when_watched_files_are_deleted
watcher
=
build_new_watcher
(
FILES
)
{
i
+=
1
}
assert
!
watcher
.
updated?
FileUtils
.
rm
(
FILES
)
sleep
1
assert
watcher
.
updated?
end
def
test_should_be_robust_enough_to_handle_deleted_files
i
=
0
checker
=
build_new_watcher
(
FILES
){
i
+=
1
}
FileUtils
.
rm
(
FILES
)
sleep
(
1
)
#extra
checker
=
build_new_watcher
(
FILES
)
{
i
+=
1
}
FileUtils
.
rm_f
(
FILES
)
sleep
1
assert
checker
.
execute_if_updated
assert_equal
1
,
i
end
def
test_should_be_robust_to_handle_files_with_wrong_modified_time
i
=
0
now
=
Time
.
now
time
=
Time
.
mktime
(
now
.
year
+
1
,
now
.
month
,
now
.
day
)
# wrong mtime from the future
File
.
utime
time
,
time
,
FILES
[
2
]
File
.
utime
(
time
,
time
,
FILES
[
2
])
checker
=
build_new_watcher
(
FILES
){
i
+=
1
}
checker
=
build_new_watcher
(
FILES
)
{
i
+=
1
}
sleep
1
sleep
(
1
)
FileUtils
.
touch
(
FILES
[
0
..
1
])
sleep
(
1
)
#extra
sleep
1
assert
checker
.
execute_if_updated
assert_equal
1
,
i
end
def
test_should_cache_updated_result_until_execute
i
=
0
checker
=
build_new_watcher
(
FILES
){
i
+=
1
}
checker
=
build_new_watcher
(
FILES
)
{
i
+=
1
}
assert
!
checker
.
updated?
sleep
1
sleep
(
1
)
FileUtils
.
touch
(
FILES
)
sleep
(
1
)
#extra
sleep
1
assert
checker
.
updated?
checker
.
execute
assert
!
checker
.
updated?
...
...
@@ -74,34 +98,42 @@ def test_should_cache_updated_result_until_execute
def
test_should_invoke_the_block_if_a_watched_dir_changed_its_glob
i
=
0
checker
=
build_new_watcher
([],
"tmp_watcher"
=>
[
:txt
]){
i
+=
1
}
FileUtils
.
cd
"tmp_watcher"
do
checker
=
build_new_watcher
([],
'tmp_watcher'
=>
[
:txt
])
{
i
+=
1
}
FileUtils
.
cd
'tmp_watcher'
do
FileUtils
.
touch
(
FILES
)
end
sleep
(
1
)
#extra
sleep
1
assert
checker
.
execute_if_updated
assert_equal
1
,
i
end
def
test_should_not_invoke_the_block_if_a_watched_dir_changed_its_glob
i
=
0
checker
=
build_new_watcher
([],
"tmp_watcher"
=>
:rb
){
i
+=
1
}
FileUtils
.
cd
"tmp_watcher"
do
checker
=
build_new_watcher
([],
'tmp_watcher'
=>
:rb
)
{
i
+=
1
}
FileUtils
.
cd
'tmp_watcher'
do
FileUtils
.
touch
(
FILES
)
end
sleep
(
1
)
#extra
sleep
1
assert
!
checker
.
execute_if_updated
assert_equal
0
,
i
end
def
test_should_not_block_if_a_strange_filename_used
FileUtils
.
mkdir_p
(
"tmp_watcher/valid,yetstrange,path,"
)
FileUtils
.
touch
(
FILES
.
map
{
|
file_name
|
"tmp_watcher/valid,yetstrange,path,/
#{
file_name
}
"
})
def
test_should_not_block_with_unusual_file_names
unusual_dirname
=
'tmp_watcher/valid,yetstrange,path,'
FileUtils
.
mkdir_p
(
unusual_dirname
)
FileUtils
.
touch
(
FILES
.
map
{
|
file_name
|
"
#{
unusual_dirname
}
/
#{
file_name
}
"
})
test
=
Thread
.
new
do
build_new_watcher
([],
"tmp_watcher/valid,yetstrange,path,"
=>
:txt
)
{
i
+=
1
}
build_new_watcher
([],
unusual_dirname
=>
:txt
)
{
i
+=
1
}
Thread
.
exit
end
test
.
priority
=
-
1
test
.
join
(
5
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录