ruby-on-rails - 问:如何使用 Turnip、capybara 和 Gherkin 测试 ActionMailer Deliver_later
问题描述
def deliver_mail
ServiceMailer.activation().deliver_later
end
从某个控制器调用deliver_mail 方法。
我想像下面这样进行测试 - 使用黄瓜和水豚进行功能测试。
step 'push next button' do find("input.submit").click end
Feature: Sending a mail to user
Scenario: mail to a user
When I push next button
Then mail should be sent to a user
实际上,当按下'push next button'时,邮件是通过deliver_mail方法发送的。
当我使用deliver_now 而不是deliver_later 时,我可以测试上面的代码。
但是在我将deliver_now 更改为deliver_later 后,我无法测试。
所以我在下面引用。
我试图在规范文件中包含 'ActiveJob::TestHelper' 之类的 'include ActiveJob::TestHelper'。
我修改了这样的步骤文件。
step 'push next button' do
perform_enqueued_jobs do
find("input.submit").click
end
end
但仍然无法正常工作。
请提供任何提示和建议。
解决方案
I am using Delayed::Job for sending emails in a background, so when I test sending emails, I have two separate kinds of tests:
1) rspec
- to check email body (in general, the method inside mailer) and sending the email itself
2) cucumber
- to check if the email job was queued
In cucumber, I have the following code:
Then(/^A welcome email will be sent$/) do
expect(Delayed::Job.count).to eq(1)
end
I think there is no need to check anything else from the cucumber.
推荐阅读
- html - 无法设置溢出-x 可见和溢出-y 自动
- node.js - 如何使用玉将数据从 URL/API 转换为 node.js express 中的表?
- c# - 当数据库中没有这样的行时,我返回什么?
- java - 在 solr 中使用 facet 搜索时出现未定义的异常
- uml - EA14.0 中的“Override Attribute Initializers”行为改变了 EA12.5 中的“Set Run State”
- asp.net - 如何在我正在处理的 ASP.net 中打开特定网页或在 Visual Studio 2017 中查找引用它的页面
- aws-lambda - 带有nodejs的ibmmq-无法使其与aws lambda一起使用
- android - 创建不需要额外时间来启动应用程序的启动画面
- netsuite - 在suitescript 2.0中创建子列表并添加数据
- php - PHP - 合并两个值匹配的关联数组