Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
a6e2d16b
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,发现更多精彩内容 >>
提交
a6e2d16b
编写于
12月 30, 2009
作者:
J
José Valim
提交者:
Carl Lerche
12月 30, 2009
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Setup and teardown now use new callbacks.
上级
bb153f42
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
52 addition
and
32 deletion
+52
-32
activesupport/lib/active_support/callbacks.rb
activesupport/lib/active_support/callbacks.rb
+1
-1
activesupport/lib/active_support/testing/setup_and_teardown.rb
...esupport/lib/active_support/testing/setup_and_teardown.rb
+46
-27
activesupport/test/test_test.rb
activesupport/test/test_test.rb
+5
-4
未找到文件。
activesupport/lib/active_support/callbacks.rb
浏览文件 @
a6e2d16b
...
...
@@ -90,7 +90,7 @@ def run_callbacks(kind, *args, &block)
class
Callback
@@_callback_sequence
=
0
attr_accessor
:chain
,
:filter
,
:kind
,
:options
,
:per_key
,
:klass
attr_accessor
:chain
,
:filter
,
:kind
,
:options
,
:per_key
,
:klass
,
:raw_filter
def
initialize
(
chain
,
filter
,
kind
,
options
,
klass
)
@chain
,
@kind
,
@klass
=
chain
,
kind
,
klass
...
...
activesupport/lib/active_support/testing/setup_and_teardown.rb
浏览文件 @
a6e2d16b
module
ActiveSupport
module
Testing
module
SetupAndTeardown
def
self
.
included
(
base
)
base
.
class_eval
do
include
ActiveSupport
::
DeprecatedCallbacks
define_callbacks
:setup
,
:teardown
extend
ActiveSupport
::
Concern
if
defined?
(
MiniTest
::
Assertions
)
&&
TestCase
<
MiniTest
::
Assertions
include
ForMiniTest
else
include
ForClassicTestUnit
end
included
do
include
ActiveSupport
::
Callbacks
define_callbacks
:setup
,
:teardown
if
defined?
(
MiniTest
::
Assertions
)
&&
TestCase
<
MiniTest
::
Assertions
include
ForMiniTest
else
include
ForClassicTestUnit
end
end
module
ClassMethods
def
setup
(
*
args
,
&
block
)
set_callback
(
:setup
,
:before
,
*
args
,
&
block
)
end
def
teardown
(
*
args
,
&
block
)
set_callback
(
:teardown
,
:after
,
*
args
,
&
block
)
end
end
...
...
@@ -18,13 +28,14 @@ module ForMiniTest
def
run
(
runner
)
result
=
'.'
begin
run_callbacks
:setup
result
=
super
_run_setup_callbacks
do
result
=
super
end
rescue
Exception
=>
e
result
=
runner
.
puke
(
self
.
class
,
method_name
,
e
)
ensure
begin
run_callbacks
:teardown
,
:enumerator
=>
:reverse_each
_run_teardown_callbacks
rescue
Exception
=>
e
result
=
runner
.
puke
(
self
.
class
,
method_name
,
e
)
end
...
...
@@ -42,23 +53,17 @@ module ForClassicTestUnit
def
run
(
result
)
return
if
@method_name
.
to_s
==
"default_test"
if
using_mocha
=
respond_to?
(
:mocha_verify
)
assertion_counter_klass
=
if
defined?
(
Mocha
::
TestCaseAdapter
::
AssertionCounter
)
Mocha
::
TestCaseAdapter
::
AssertionCounter
else
Mocha
::
Integration
::
TestUnit
::
AssertionCounter
end
assertion_counter
=
assertion_counter_klass
.
new
(
result
)
end
mocha_counter
=
retrieve_mocha_counter
(
result
)
yield
(
Test
::
Unit
::
TestCase
::
STARTED
,
name
)
@_result
=
result
begin
begin
run_callbacks
:setup
setup
__send__
(
@method_name
)
mocha_verify
(
assertion_counter
)
if
using_mocha
_run_setup_callbacks
do
setup
__send__
(
@method_name
)
mocha_verify
(
mocha_counter
)
if
mocha_counter
end
rescue
Mocha
::
ExpectationError
=>
e
add_failure
(
e
.
message
,
e
.
backtrace
)
rescue
Test
::
Unit
::
AssertionFailedError
=>
e
...
...
@@ -69,7 +74,7 @@ def run(result)
ensure
begin
teardown
run_callbacks
:teardown
,
:enumerator
=>
:reverse_each
_run_teardown_callbacks
rescue
Test
::
Unit
::
AssertionFailedError
=>
e
add_failure
(
e
.
message
,
e
.
backtrace
)
rescue
Exception
=>
e
...
...
@@ -78,12 +83,26 @@ def run(result)
end
end
ensure
mocha_teardown
if
using_mocha
mocha_teardown
if
mocha_counter
end
result
.
add_run
yield
(
Test
::
Unit
::
TestCase
::
FINISHED
,
name
)
end
protected
def
retrieve_mocha_counter
(
result
)
#:nodoc:
if
using_mocha
=
respond_to?
(
:mocha_verify
)
if
defined?
(
Mocha
::
TestCaseAdapter
::
AssertionCounter
)
Mocha
::
TestCaseAdapter
::
AssertionCounter
.
new
(
result
)
else
Mocha
::
Integration
::
TestUnit
::
AssertionCounter
.
new
(
result
)
end
end
end
end
end
end
end
activesupport/test/test_test.rb
浏览文件 @
a6e2d16b
...
...
@@ -102,9 +102,9 @@ class SetupAndTeardownTest < ActiveSupport::TestCase
teardown
:foo
,
:sentinel
,
:foo
def
test_inherited_setup_callbacks
assert_equal
[
:reset_callback_record
,
:foo
],
self
.
class
.
setup_callback_chain
.
map
(
&
:method
)
assert_equal
[
:reset_callback_record
,
:foo
],
self
.
class
.
_setup_callbacks
.
map
(
&
:raw_filter
)
assert_equal
[
:foo
],
@called_back
assert_equal
[
:foo
,
:sentinel
,
:foo
],
self
.
class
.
teardown_callback_chain
.
map
(
&
:method
)
assert_equal
[
:foo
,
:sentinel
,
:foo
],
self
.
class
.
_teardown_callbacks
.
map
(
&
:raw_filter
)
end
def
setup
...
...
@@ -114,6 +114,7 @@ def teardown
end
protected
def
reset_callback_record
@called_back
=
[]
end
...
...
@@ -133,9 +134,9 @@ class SubclassSetupAndTeardownTest < SetupAndTeardownTest
teardown
:bar
def
test_inherited_setup_callbacks
assert_equal
[
:reset_callback_record
,
:foo
,
:bar
],
self
.
class
.
setup_callback_chain
.
map
(
&
:method
)
assert_equal
[
:reset_callback_record
,
:foo
,
:bar
],
self
.
class
.
_setup_callbacks
.
map
(
&
:raw_filter
)
assert_equal
[
:foo
,
:bar
],
@called_back
assert_equal
[
:foo
,
:sentinel
,
:foo
,
:bar
],
self
.
class
.
teardown_callback_chain
.
map
(
&
:method
)
assert_equal
[
:foo
,
:sentinel
,
:foo
,
:bar
],
self
.
class
.
_teardown_callbacks
.
map
(
&
:raw_filter
)
end
protected
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录