Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
3f17fbd6
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 搜索 >>
提交
3f17fbd6
编写于
1月 08, 2015
作者:
G
George Claghorn
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add assert_enqueued_emails and assert_no_enqueued_emails
上级
91e31e82
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
115 addition
and
0 deletion
+115
-0
actionmailer/CHANGELOG.md
actionmailer/CHANGELOG.md
+17
-0
actionmailer/lib/action_mailer/test_helper.rb
actionmailer/lib/action_mailer/test_helper.rb
+51
-0
actionmailer/test/test_helper_test.rb
actionmailer/test/test_helper_test.rb
+47
-0
未找到文件。
actionmailer/CHANGELOG.md
浏览文件 @
3f17fbd6
*
Add
`assert_enqueued_emails`
and
`assert_no_enqueued_emails`
.
def test_emails
assert_enqueued_emails 2 do
ContactMailer.welcome.deliver_later
ContactMailer.welcome.deliver_later
end
end
def test_no_emails
assert_no_enqueued_emails do
# No emails enqueued here
end
end
*George Claghorn*
*
Add
`_mailer`
suffix to mailers created via generator, following the same
naming convention used in controllers and jobs.
...
...
actionmailer/lib/action_mailer/test_helper.rb
浏览文件 @
3f17fbd6
require
'active_job'
module
ActionMailer
# Provides helper methods for testing Action Mailer, including #assert_emails
# and #assert_no_emails
module
TestHelper
include
ActiveJob
::
TestHelper
# Asserts that the number of emails sent matches the given number.
#
# def test_emails
...
...
@@ -58,5 +62,52 @@ def assert_emails(number)
def
assert_no_emails
(
&
block
)
assert_emails
0
,
&
block
end
# Asserts that the number of emails enqueued for later delivery matches
# the given number.
#
# def test_emails
# assert_enqueued_emails 0
# ContactMailer.welcome.deliver_later
# assert_enqueued_emails 1
# ContactMailer.welcome.deliver_later
# assert_enqueued_emails 2
# end
#
# If a block is passed, that block should cause the specified number of
# emails to be enqueued.
#
# def test_emails_again
# assert_enqueued_emails 1 do
# ContactMailer.welcome.deliver_later
# end
#
# assert_enqueued_emails 2 do
# ContactMailer.welcome.deliver_later
# ContactMailer.welcome.deliver_later
# end
# end
def
assert_enqueued_emails
(
number
,
&
block
)
assert_enqueued_jobs
number
,
only:
ActionMailer
::
DeliveryJob
,
&
block
end
# Asserts that no emails are enqueued for later delivery.
#
# def test_no_emails
# assert_no_enqueued_emails
# ContactMailer.welcome.deliver_later
# assert_enqueued_emails 1
# end
#
# If a block is provided, it should not cause any emails to be enqueued.
#
# def test_no_emails
# assert_no_enqueued_emails do
# # No emails should be enqueued from this block
# end
# end
def
assert_no_enqueued_emails
(
&
block
)
assert_no_enqueued_jobs
only:
ActionMailer
::
DeliveryJob
,
&
block
end
end
end
actionmailer/test/test_helper_test.rb
浏览文件 @
3f17fbd6
...
...
@@ -119,6 +119,53 @@ def test_assert_no_emails_failure
assert_match
(
/0 .* but 1/
,
error
.
message
)
end
def
test_assert_enqueued_emails
assert_nothing_raised
do
assert_enqueued_emails
1
do
TestHelperMailer
.
test
.
deliver_later
end
end
end
def
test_assert_enqueued_emails_too_few_sent
error
=
assert_raise
ActiveSupport
::
TestCase
::
Assertion
do
assert_enqueued_emails
2
do
TestHelperMailer
.
test
.
deliver_later
end
end
assert_match
(
/2 .* but 1/
,
error
.
message
)
end
def
test_assert_enqueued_emails_too_many_sent
error
=
assert_raise
ActiveSupport
::
TestCase
::
Assertion
do
assert_enqueued_emails
1
do
TestHelperMailer
.
test
.
deliver_later
TestHelperMailer
.
test
.
deliver_later
end
end
assert_match
(
/1 .* but 2/
,
error
.
message
)
end
def
test_assert_no_enqueued_emails
assert_nothing_raised
do
assert_no_enqueued_emails
do
TestHelperMailer
.
test
.
deliver_now
end
end
end
def
test_assert_no_enqueued_emails_failure
error
=
assert_raise
ActiveSupport
::
TestCase
::
Assertion
do
assert_no_enqueued_emails
do
TestHelperMailer
.
test
.
deliver_later
end
end
assert_match
(
/0 .* but 1/
,
error
.
message
)
end
end
class
AnotherTestHelperMailerTest
<
ActionMailer
::
TestCase
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录