Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
3121412c
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,发现更多精彩内容 >>
提交
3121412c
编写于
7月 15, 2014
作者:
R
Rafael Mendonça França
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Keep quietly and capture undeprecated on your suite
上级
af2ffa8c
变更
10
显示空白变更内容
内联
并排
Showing
10 changed file
with
140 addition
and
21 deletion
+140
-21
activerecord/test/cases/migration_test.rb
activerecord/test/cases/migration_test.rb
+10
-0
activerecord/test/cases/tasks/mysql_rake_test.rb
activerecord/test/cases/tasks/mysql_rake_test.rb
+19
-0
activesupport/test/core_ext/kernel_test.rb
activesupport/test/core_ext/kernel_test.rb
+17
-19
activesupport/test/deprecation_test.rb
activesupport/test/deprecation_test.rb
+17
-0
railties/lib/rails/generators/testing/behaviour.rb
railties/lib/rails/generators/testing/behaviour.rb
+17
-0
railties/test/abstract_unit.rb
railties/test/abstract_unit.rb
+23
-0
railties/test/generators/actions_test.rb
railties/test/generators/actions_test.rb
+1
-1
railties/test/generators/app_generator_test.rb
railties/test/generators/app_generator_test.rb
+1
-1
railties/test/generators/generators_test_helper.rb
railties/test/generators/generators_test_helper.rb
+8
-0
railties/test/isolation/abstract_unit.rb
railties/test/isolation/abstract_unit.rb
+27
-0
未找到文件。
activerecord/test/cases/migration_test.rb
浏览文件 @
3121412c
...
...
@@ -895,4 +895,14 @@ def test_check_pending_with_stdlib_logger
ensure
ActiveRecord
::
Base
.
logger
=
old
end
private
def
quietly
silence_stream
(
STDOUT
)
do
silence_stream
(
STDERR
)
do
yield
end
end
end
end
activerecord/test/cases/tasks/mysql_rake_test.rb
浏览文件 @
3121412c
...
...
@@ -288,6 +288,25 @@ def test_structure_dump_with_port_number
@configuration
.
merge
(
'port'
=>
10000
),
filename
)
end
private
def
capture
(
stream
)
stream
=
stream
.
to_s
captured_stream
=
Tempfile
.
new
(
stream
)
stream_io
=
eval
(
"$
#{
stream
}
"
)
origin_stream
=
stream_io
.
dup
stream_io
.
reopen
(
captured_stream
)
yield
stream_io
.
rewind
return
captured_stream
.
read
ensure
captured_stream
.
close
captured_stream
.
unlink
stream_io
.
reopen
(
origin_stream
)
end
end
class
MySQLStructureLoadTest
<
ActiveRecord
::
TestCase
...
...
activesupport/test/core_ext/kernel_test.rb
浏览文件 @
3121412c
...
...
@@ -30,14 +30,6 @@ def test_enable_warnings_verbose_invariant
end
def
test_silence_stderr
old_stderr_position
=
STDERR
.
tell
silence_stderr
{
STDERR
.
puts
'hello world'
}
assert_equal
old_stderr_position
,
STDERR
.
tell
rescue
Errno
::
ESPIPE
# Skip if we can't STDERR.tell
end
def
test_silence_stream
old_stream_position
=
STDOUT
.
tell
silence_stream
(
STDOUT
)
{
STDOUT
.
puts
'hello world'
}
...
...
@@ -56,20 +48,18 @@ def test_silence_stream_closes_file_descriptors
def
test_quietly
old_stdout_position
,
old_stderr_position
=
STDOUT
.
tell
,
STDERR
.
tell
assert_deprecated
do
quietly
do
puts
'see me, feel me'
STDERR
.
puts
'touch me, heal me'
end
end
assert_equal
old_stdout_position
,
STDOUT
.
tell
assert_equal
old_stderr_position
,
STDERR
.
tell
rescue
Errno
::
ESPIPE
# Skip if we can't STDERR.tell
end
def
test_silence_stderr_with_return_value
assert_equal
1
,
silence_stderr
{
1
}
end
def
test_class_eval
o
=
Object
.
new
class
<<
o
;
@x
=
1
;
end
...
...
@@ -77,11 +67,19 @@ class << o; @x = 1; end
end
def
test_capture
assert_deprecated
do
assert_equal
'STDERR'
,
capture
(
:stderr
)
{
$stderr
.
print
'STDERR'
}
end
assert_deprecated
do
assert_equal
'STDOUT'
,
capture
(
:stdout
)
{
print
'STDOUT'
}
end
assert_deprecated
do
assert_equal
"STDERR
\n
"
,
capture
(
:stderr
)
{
system
(
'echo STDERR 1>&2'
)
}
end
assert_deprecated
do
assert_equal
"STDOUT
\n
"
,
capture
(
:stdout
)
{
system
(
'echo STDOUT'
)
}
end
end
end
class
KernelSuppressTest
<
ActiveSupport
::
TestCase
...
...
activesupport/test/deprecation_test.rb
浏览文件 @
3121412c
...
...
@@ -355,4 +355,21 @@ def deprecator.messages
end
deprecator
end
def
capture
(
stream
)
stream
=
stream
.
to_s
captured_stream
=
Tempfile
.
new
(
stream
)
stream_io
=
eval
(
"$
#{
stream
}
"
)
origin_stream
=
stream_io
.
dup
stream_io
.
reopen
(
captured_stream
)
yield
stream_io
.
rewind
return
captured_stream
.
read
ensure
captured_stream
.
close
captured_stream
.
unlink
stream_io
.
reopen
(
origin_stream
)
end
end
railties/lib/rails/generators/testing/behaviour.rb
浏览文件 @
3121412c
...
...
@@ -100,6 +100,23 @@ def migration_file_name(relative) # :nodoc:
dirname
,
file_name
=
File
.
dirname
(
absolute
),
File
.
basename
(
absolute
).
sub
(
/\.rb$/
,
''
)
Dir
.
glob
(
"
#{
dirname
}
/[0-9]*_*.rb"
).
grep
(
/\d+_
#{
file_name
}
.rb$/
).
first
end
def
capture
(
stream
)
stream
=
stream
.
to_s
captured_stream
=
Tempfile
.
new
(
stream
)
stream_io
=
eval
(
"$
#{
stream
}
"
)
origin_stream
=
stream_io
.
dup
stream_io
.
reopen
(
captured_stream
)
yield
stream_io
.
rewind
return
captured_stream
.
read
ensure
captured_stream
.
close
captured_stream
.
unlink
stream_io
.
reopen
(
origin_stream
)
end
end
end
end
...
...
railties/test/abstract_unit.rb
浏览文件 @
3121412c
...
...
@@ -26,3 +26,26 @@ def rubinius_skip(message = '')
def
jruby_skip
(
message
=
''
)
skip
message
if
defined?
(
JRUBY_VERSION
)
end
class
ActiveSupport::TestCase
private
unless
defined?
(
:capture
)
def
capture
(
stream
)
stream
=
stream
.
to_s
captured_stream
=
Tempfile
.
new
(
stream
)
stream_io
=
eval
(
"$
#{
stream
}
"
)
origin_stream
=
stream_io
.
dup
stream_io
.
reopen
(
captured_stream
)
yield
stream_io
.
rewind
return
captured_stream
.
read
ensure
captured_stream
.
close
captured_stream
.
unlink
stream_io
.
reopen
(
origin_stream
)
end
end
end
railties/test/generators/actions_test.rb
浏览文件 @
3121412c
...
...
@@ -242,7 +242,7 @@ def test_log_with_status_with_quiet
protected
def
action
(
*
args
,
&
block
)
silenc
e
(
:stdout
){
generator
.
send
(
*
args
,
&
block
)
}
captur
e
(
:stdout
){
generator
.
send
(
*
args
,
&
block
)
}
end
end
railties/test/generators/app_generator_test.rb
浏览文件 @
3121412c
...
...
@@ -490,7 +490,7 @@ def test_gitignore_when_non_sqlite3_db
protected
def
action
(
*
args
,
&
block
)
silenc
e
(
:stdout
)
{
generator
.
send
(
*
args
,
&
block
)
}
captur
e
(
:stdout
)
{
generator
.
send
(
*
args
,
&
block
)
}
end
def
assert_gem
(
gem
)
...
...
railties/test/generators/generators_test_helper.rb
浏览文件 @
3121412c
...
...
@@ -41,4 +41,12 @@ def copy_routes
FileUtils
.
mkdir_p
(
destination
)
FileUtils
.
cp
routes
,
destination
end
def
quietly
silence_stream
(
STDOUT
)
do
silence_stream
(
STDERR
)
do
yield
end
end
end
end
railties/test/isolation/abstract_unit.rb
浏览文件 @
3121412c
...
...
@@ -291,6 +291,33 @@ class ActiveSupport::TestCase
include
TestHelpers
::
Paths
include
TestHelpers
::
Rack
include
TestHelpers
::
Generation
private
def
capture
(
stream
)
stream
=
stream
.
to_s
captured_stream
=
Tempfile
.
new
(
stream
)
stream_io
=
eval
(
"$
#{
stream
}
"
)
origin_stream
=
stream_io
.
dup
stream_io
.
reopen
(
captured_stream
)
yield
stream_io
.
rewind
return
captured_stream
.
read
ensure
captured_stream
.
close
captured_stream
.
unlink
stream_io
.
reopen
(
origin_stream
)
end
def
quietly
silence_stream
(
STDOUT
)
do
silence_stream
(
STDERR
)
do
yield
end
end
end
end
# Create a scope and build a fixture rails app
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录