Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
f7e91c72
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,发现更多精彩内容 >>
提交
f7e91c72
编写于
8月 02, 2019
作者:
A
Akira Matsuda
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Lazily evaluate FileUpdateCheckerSharedTests when being included
To avoid "uninitialized constant ActiveSupport::Testing (NameError)"
上级
dd779c96
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
199 addition
and
195 deletion
+199
-195
activesupport/test/file_update_checker_shared_tests.rb
activesupport/test/file_update_checker_shared_tests.rb
+199
-195
未找到文件。
activesupport/test/file_update_checker_shared_tests.rb
浏览文件 @
f7e91c72
...
@@ -3,294 +3,298 @@
...
@@ -3,294 +3,298 @@
require
"fileutils"
require
"fileutils"
module
FileUpdateCheckerSharedTests
module
FileUpdateCheckerSharedTests
extend
ActiveSupport
::
Testing
::
Declarative
def
self
.
included
(
kls
)
include
FileUtils
kls
.
class_eval
do
extend
ActiveSupport
::
Testing
::
Declarative
include
FileUtils
def
tmpdir
def
tmpdir
@tmpdir
@tmpdir
end
end
def
tmpfile
(
name
)
def
tmpfile
(
name
)
File
.
join
(
tmpdir
,
name
)
File
.
join
(
tmpdir
,
name
)
end
end
def
tmpfiles
def
tmpfiles
@tmpfiles
||=
%w(foo.rb bar.rb baz.rb)
.
map
{
|
f
|
tmpfile
(
f
)
}
@tmpfiles
||=
%w(foo.rb bar.rb baz.rb)
.
map
{
|
f
|
tmpfile
(
f
)
}
end
end
def
run
(
*
args
)
def
run
(
*
args
)
capture_exceptions
do
capture_exceptions
do
Dir
.
mktmpdir
(
nil
,
__dir__
)
{
|
dir
|
@tmpdir
=
dir
;
super
}
Dir
.
mktmpdir
(
nil
,
__dir__
)
{
|
dir
|
@tmpdir
=
dir
;
super
}
end
end
end
end
test
"should not execute the block if no paths are given"
do
test
"should not execute the block if no paths are given"
do
silence_warnings
{
require
"listen"
}
silence_warnings
{
require
"listen"
}
i
=
0
i
=
0
checker
=
new_checker
{
i
+=
1
}
checker
=
new_checker
{
i
+=
1
}
assert_not
checker
.
execute_if_updated
assert_not
checker
.
execute_if_updated
assert_equal
0
,
i
assert_equal
0
,
i
end
end
test
"should not execute the block if no files change"
do
test
"should not execute the block if no files change"
do
i
=
0
i
=
0
FileUtils
.
touch
(
tmpfiles
)
FileUtils
.
touch
(
tmpfiles
)
checker
=
new_checker
(
tmpfiles
)
{
i
+=
1
}
checker
=
new_checker
(
tmpfiles
)
{
i
+=
1
}
assert_not
checker
.
execute_if_updated
assert_not
checker
.
execute_if_updated
assert_equal
0
,
i
assert_equal
0
,
i
end
end
test
"should execute the block once when files are created"
do
test
"should execute the block once when files are created"
do
i
=
0
i
=
0
checker
=
new_checker
(
tmpfiles
)
{
i
+=
1
}
checker
=
new_checker
(
tmpfiles
)
{
i
+=
1
}
touch
(
tmpfiles
)
touch
(
tmpfiles
)
wait
wait
assert
checker
.
execute_if_updated
assert
checker
.
execute_if_updated
assert_equal
1
,
i
assert_equal
1
,
i
end
end
test
"should execute the block once when files are modified"
do
test
"should execute the block once when files are modified"
do
i
=
0
i
=
0
FileUtils
.
touch
(
tmpfiles
)
FileUtils
.
touch
(
tmpfiles
)
checker
=
new_checker
(
tmpfiles
)
{
i
+=
1
}
checker
=
new_checker
(
tmpfiles
)
{
i
+=
1
}
touch
(
tmpfiles
)
touch
(
tmpfiles
)
wait
wait
assert
checker
.
execute_if_updated
assert
checker
.
execute_if_updated
assert_equal
1
,
i
assert_equal
1
,
i
end
end
test
"should execute the block once when files are deleted"
do
test
"should execute the block once when files are deleted"
do
i
=
0
i
=
0
FileUtils
.
touch
(
tmpfiles
)
FileUtils
.
touch
(
tmpfiles
)
checker
=
new_checker
(
tmpfiles
)
{
i
+=
1
}
checker
=
new_checker
(
tmpfiles
)
{
i
+=
1
}
rm_f
(
tmpfiles
)
rm_f
(
tmpfiles
)
wait
wait
assert
checker
.
execute_if_updated
assert
checker
.
execute_if_updated
assert_equal
1
,
i
assert_equal
1
,
i
end
end
test
"updated should become true when watched files are created"
do
test
"updated should become true when watched files are created"
do
i
=
0
i
=
0
checker
=
new_checker
(
tmpfiles
)
{
i
+=
1
}
checker
=
new_checker
(
tmpfiles
)
{
i
+=
1
}
assert_not_predicate
checker
,
:updated?
assert_not_predicate
checker
,
:updated?
touch
(
tmpfiles
)
touch
(
tmpfiles
)
wait
wait
assert_predicate
checker
,
:updated?
assert_predicate
checker
,
:updated?
end
end
test
"updated should become true when watched files are modified"
do
test
"updated should become true when watched files are modified"
do
i
=
0
i
=
0
FileUtils
.
touch
(
tmpfiles
)
FileUtils
.
touch
(
tmpfiles
)
checker
=
new_checker
(
tmpfiles
)
{
i
+=
1
}
checker
=
new_checker
(
tmpfiles
)
{
i
+=
1
}
assert_not_predicate
checker
,
:updated?
assert_not_predicate
checker
,
:updated?
touch
(
tmpfiles
)
touch
(
tmpfiles
)
wait
wait
assert_predicate
checker
,
:updated?
assert_predicate
checker
,
:updated?
end
end
test
"updated should become true when watched files are deleted"
do
test
"updated should become true when watched files are deleted"
do
i
=
0
i
=
0
FileUtils
.
touch
(
tmpfiles
)
FileUtils
.
touch
(
tmpfiles
)
checker
=
new_checker
(
tmpfiles
)
{
i
+=
1
}
checker
=
new_checker
(
tmpfiles
)
{
i
+=
1
}
assert_not_predicate
checker
,
:updated?
assert_not_predicate
checker
,
:updated?
rm_f
(
tmpfiles
)
rm_f
(
tmpfiles
)
wait
wait
assert_predicate
checker
,
:updated?
assert_predicate
checker
,
:updated?
end
end
test
"should be robust to handle files with wrong modified time"
do
test
"should be robust to handle files with wrong modified time"
do
i
=
0
i
=
0
FileUtils
.
touch
(
tmpfiles
)
FileUtils
.
touch
(
tmpfiles
)
now
=
Time
.
now
now
=
Time
.
now
time
=
Time
.
mktime
(
now
.
year
+
1
,
now
.
month
,
now
.
day
)
# wrong mtime from the future
time
=
Time
.
mktime
(
now
.
year
+
1
,
now
.
month
,
now
.
day
)
# wrong mtime from the future
File
.
utime
(
time
,
time
,
tmpfiles
[
0
])
File
.
utime
(
time
,
time
,
tmpfiles
[
0
])
checker
=
new_checker
(
tmpfiles
)
{
i
+=
1
}
checker
=
new_checker
(
tmpfiles
)
{
i
+=
1
}
touch
(
tmpfiles
[
1
..-
1
])
touch
(
tmpfiles
[
1
..-
1
])
wait
wait
assert
checker
.
execute_if_updated
assert
checker
.
execute_if_updated
assert_equal
1
,
i
assert_equal
1
,
i
end
end
test
"should return max_time for files with mtime = Time.at(0)"
do
test
"should return max_time for files with mtime = Time.at(0)"
do
i
=
0
i
=
0
FileUtils
.
touch
(
tmpfiles
)
FileUtils
.
touch
(
tmpfiles
)
time
=
Time
.
at
(
0
)
# wrong mtime from the future
time
=
Time
.
at
(
0
)
# wrong mtime from the future
File
.
utime
(
time
,
time
,
tmpfiles
[
0
])
File
.
utime
(
time
,
time
,
tmpfiles
[
0
])
checker
=
new_checker
(
tmpfiles
)
{
i
+=
1
}
checker
=
new_checker
(
tmpfiles
)
{
i
+=
1
}
touch
(
tmpfiles
[
1
..-
1
])
touch
(
tmpfiles
[
1
..-
1
])
wait
wait
assert
checker
.
execute_if_updated
assert
checker
.
execute_if_updated
assert_equal
1
,
i
assert_equal
1
,
i
end
end
test
"should cache updated result until execute"
do
test
"should cache updated result until execute"
do
i
=
0
i
=
0
checker
=
new_checker
(
tmpfiles
)
{
i
+=
1
}
checker
=
new_checker
(
tmpfiles
)
{
i
+=
1
}
assert_not_predicate
checker
,
:updated?
assert_not_predicate
checker
,
:updated?
touch
(
tmpfiles
)
touch
(
tmpfiles
)
wait
wait
assert_predicate
checker
,
:updated?
assert_predicate
checker
,
:updated?
checker
.
execute
checker
.
execute
assert_not_predicate
checker
,
:updated?
assert_not_predicate
checker
,
:updated?
end
end
test
"should execute the block if files change in a watched directory one extension"
do
test
"should execute the block if files change in a watched directory one extension"
do
i
=
0
i
=
0
checker
=
new_checker
([],
tmpdir
=>
:rb
)
{
i
+=
1
}
checker
=
new_checker
([],
tmpdir
=>
:rb
)
{
i
+=
1
}
touch
(
tmpfile
(
"foo.rb"
))
touch
(
tmpfile
(
"foo.rb"
))
wait
wait
assert
checker
.
execute_if_updated
assert
checker
.
execute_if_updated
assert_equal
1
,
i
assert_equal
1
,
i
end
end
test
"should execute the block if files change in a watched directory any extensions"
do
test
"should execute the block if files change in a watched directory any extensions"
do
i
=
0
i
=
0
checker
=
new_checker
([],
tmpdir
=>
[])
{
i
+=
1
}
checker
=
new_checker
([],
tmpdir
=>
[])
{
i
+=
1
}
touch
(
tmpfile
(
"foo.rb"
))
touch
(
tmpfile
(
"foo.rb"
))
wait
wait
assert
checker
.
execute_if_updated
assert
checker
.
execute_if_updated
assert_equal
1
,
i
assert_equal
1
,
i
end
end
test
"should execute the block if files change in a watched directory several extensions"
do
test
"should execute the block if files change in a watched directory several extensions"
do
i
=
0
i
=
0
checker
=
new_checker
([],
tmpdir
=>
[
:rb
,
:txt
])
{
i
+=
1
}
checker
=
new_checker
([],
tmpdir
=>
[
:rb
,
:txt
])
{
i
+=
1
}
touch
(
tmpfile
(
"foo.rb"
))
touch
(
tmpfile
(
"foo.rb"
))
wait
wait
assert
checker
.
execute_if_updated
assert
checker
.
execute_if_updated
assert_equal
1
,
i
assert_equal
1
,
i
touch
(
tmpfile
(
"foo.txt"
))
touch
(
tmpfile
(
"foo.txt"
))
wait
wait
assert
checker
.
execute_if_updated
assert
checker
.
execute_if_updated
assert_equal
2
,
i
assert_equal
2
,
i
end
end
test
"should not execute the block if the file extension is not watched"
do
test
"should not execute the block if the file extension is not watched"
do
i
=
0
i
=
0
checker
=
new_checker
([],
tmpdir
=>
:txt
)
{
i
+=
1
}
checker
=
new_checker
([],
tmpdir
=>
:txt
)
{
i
+=
1
}
touch
(
tmpfile
(
"foo.rb"
))
touch
(
tmpfile
(
"foo.rb"
))
wait
wait
assert_not
checker
.
execute_if_updated
assert_not
checker
.
execute_if_updated
assert_equal
0
,
i
assert_equal
0
,
i
end
end
test
"does not assume files exist on instantiation"
do
test
"does not assume files exist on instantiation"
do
i
=
0
i
=
0
non_existing
=
tmpfile
(
"non_existing.rb"
)
non_existing
=
tmpfile
(
"non_existing.rb"
)
checker
=
new_checker
([
non_existing
])
{
i
+=
1
}
checker
=
new_checker
([
non_existing
])
{
i
+=
1
}
touch
(
non_existing
)
touch
(
non_existing
)
wait
wait
assert
checker
.
execute_if_updated
assert
checker
.
execute_if_updated
assert_equal
1
,
i
assert_equal
1
,
i
end
end
test
"detects files in new subdirectories"
do
test
"detects files in new subdirectories"
do
i
=
0
i
=
0
checker
=
new_checker
([],
tmpdir
=>
:rb
)
{
i
+=
1
}
checker
=
new_checker
([],
tmpdir
=>
:rb
)
{
i
+=
1
}
subdir
=
tmpfile
(
"subdir"
)
subdir
=
tmpfile
(
"subdir"
)
mkdir
(
subdir
)
mkdir
(
subdir
)
wait
wait
assert_not
checker
.
execute_if_updated
assert_not
checker
.
execute_if_updated
assert_equal
0
,
i
assert_equal
0
,
i
touch
(
File
.
join
(
subdir
,
"nested.rb"
))
touch
(
File
.
join
(
subdir
,
"nested.rb"
))
wait
wait
assert
checker
.
execute_if_updated
assert
checker
.
execute_if_updated
assert_equal
1
,
i
assert_equal
1
,
i
end
end
test
"looked up extensions are inherited in subdirectories not listening to them"
do
test
"looked up extensions are inherited in subdirectories not listening to them"
do
i
=
0
i
=
0
subdir
=
tmpfile
(
"subdir"
)
subdir
=
tmpfile
(
"subdir"
)
mkdir
(
subdir
)
mkdir
(
subdir
)
checker
=
new_checker
([],
tmpdir
=>
:rb
,
subdir
=>
:txt
)
{
i
+=
1
}
checker
=
new_checker
([],
tmpdir
=>
:rb
,
subdir
=>
:txt
)
{
i
+=
1
}
touch
(
tmpfile
(
"new.txt"
))
touch
(
tmpfile
(
"new.txt"
))
wait
wait
assert_not
checker
.
execute_if_updated
assert_not
checker
.
execute_if_updated
assert_equal
0
,
i
assert_equal
0
,
i
# subdir does not look for Ruby files, but its parent tmpdir does.
# subdir does not look for Ruby files, but its parent tmpdir does.
touch
(
File
.
join
(
subdir
,
"nested.rb"
))
touch
(
File
.
join
(
subdir
,
"nested.rb"
))
wait
wait
assert
checker
.
execute_if_updated
assert
checker
.
execute_if_updated
assert_equal
1
,
i
assert_equal
1
,
i
touch
(
File
.
join
(
subdir
,
"nested.txt"
))
touch
(
File
.
join
(
subdir
,
"nested.txt"
))
wait
wait
assert
checker
.
execute_if_updated
assert
checker
.
execute_if_updated
assert_equal
2
,
i
assert_equal
2
,
i
end
end
test
"initialize raises an ArgumentError if no block given"
do
test
"initialize raises an ArgumentError if no block given"
do
assert_raise
ArgumentError
do
assert_raise
ArgumentError
do
new_checker
([])
new_checker
([])
end
end
end
end
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录