Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
a41698bc
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,发现更多精彩内容 >>
提交
a41698bc
编写于
7月 08, 2015
作者:
K
Kasper Timm Hansen
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #20784 from kaspth/great-expectations
Add method call assertions for internal use.
上级
ef2d7a69
53f64c0f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
121 addition
and
0 deletion
+121
-0
activesupport/lib/active_support/testing/method_call_assertions.rb
...port/lib/active_support/testing/method_call_assertions.rb
+30
-0
activesupport/test/testing/method_call_assertions_test.rb
activesupport/test/testing/method_call_assertions_test.rb
+91
-0
未找到文件。
activesupport/lib/active_support/testing/method_call_assertions.rb
0 → 100644
浏览文件 @
a41698bc
module
ActiveSupport
module
Testing
module
MethodCallAssertions
# :nodoc:
private
def
assert_called
(
object
,
method_name
,
message
=
nil
,
times:
1
)
times_called
=
0
object
.
stub
(
method_name
,
->
{
times_called
+=
1
})
{
yield
}
error
=
"Expected
#{
method_name
}
to be called
#{
times
}
times, "
\
"but was called
#{
times_called
}
times"
error
=
"
#{
message
}
.
\n
#{
error
}
"
if
message
assert_equal
times
,
times_called
,
error
end
def
assert_called_with
(
object
,
method_name
,
args
=
[],
returns:
nil
)
mock
=
Minitest
::
Mock
.
new
mock
.
expect
(
:call
,
returns
,
args
)
object
.
stub
(
method_name
,
mock
)
{
yield
}
mock
.
verify
end
def
assert_not_called
(
object
,
method_name
,
message
=
nil
,
&
block
)
assert_called
(
object
,
method_name
,
message
,
times:
0
,
&
block
)
end
end
end
end
\ No newline at end of file
activesupport/test/testing/method_call_assertions_test.rb
0 → 100644
浏览文件 @
a41698bc
require
'abstract_unit'
require
'active_support/testing/method_call_assertions'
class
MethodCallAssertionsTest
<
ActiveSupport
::
TestCase
include
ActiveSupport
::
Testing
::
MethodCallAssertions
class
Level
def
increment
;
1
;
end
def
decrement
;
end
def
<<
(
arg
);
end
end
setup
do
@object
=
Level
.
new
end
def
test_assert_called_with_defaults_to_expect_once
assert_called
@object
,
:increment
do
@object
.
increment
end
end
def
test_assert_called_more_than_once
assert_called
(
@object
,
:increment
,
times:
2
)
do
@object
.
increment
@object
.
increment
end
end
def
test_assert_called_failure
error
=
assert_raises
(
Minitest
::
Assertion
)
do
assert_called
(
@object
,
:increment
)
do
# Call nothing...
end
end
assert_equal
"Expected increment to be called 1 times, but was called 0 times.
\n
Expected: 1
\n
Actual: 0"
,
error
.
message
end
def
test_assert_called_with_message
error
=
assert_raises
(
Minitest
::
Assertion
)
do
assert_called
(
@object
,
:increment
,
'dang it'
)
do
# Call nothing...
end
end
assert_match
(
/dang it.\nExpected increment/
,
error
.
message
)
end
def
test_assert_called_with
assert_called_with
(
@object
,
:increment
)
do
@object
.
increment
end
end
def
test_assert_called_with_arguments
assert_called_with
(
@object
,
:<<
,
[
2
])
do
@object
<<
2
end
end
def
test_assert_called_with_failure
assert_raises
(
MockExpectationError
)
do
assert_called_with
(
@object
,
:<<
,
[
4567
])
do
@object
<<
2
end
end
end
def
test_assert_called_with_returns
assert_called_with
(
@object
,
:increment
,
returns:
1
)
do
@object
.
increment
end
end
def
test_assert_not_called
assert_not_called
(
@object
,
:decrement
)
do
@object
.
increment
end
end
def
test_assert_not_called_failure
error
=
assert_raises
(
Minitest
::
Assertion
)
do
assert_not_called
(
@object
,
:increment
)
do
@object
.
increment
end
end
assert_equal
"Expected increment to be called 0 times, but was called 1 times.
\n
Expected: 0
\n
Actual: 1"
,
error
.
message
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录