使用水豚和delayed_job测试电子邮件
受到 Railscast (http://railscasts.com/episodes/275-how-i-test) 剧集的启发,我尝试向我的应用程序添加一些请求规范。
使用delayed_job发送电子邮件,我没有找到一种简单的方法来在水豚测试中测试电子邮件的发送。我尝试过:
it "emails user when requesting password reset" do
...(some user action that triggers sending an email)...
Delayed::Worker.new.work_off
ActionMailer::Base.deliveries.last.to.should include(user.email)
end
感谢您的任何提示或帮助!
inspired by the episode of railscast (http://railscasts.com/episodes/275-how-i-test) i tried to add some request specs to my app.
using delayed_job for sending my emails, i did not found an easy way to test the sending of emails within my capybara test. i tried:
it "emails user when requesting password reset" do
...(some user action that triggers sending an email)...
Delayed::Worker.new.work_off
ActionMailer::Base.deliveries.last.to.should include(user.email)
end
thanks for any hints or help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更简单的解决方案:只需在 config/initializers 中创建一个初始化程序,例如delayed_job_config.rb
在实际测试中,您甚至不需要知道已部署delayed_job 来发送邮件,这使它们保持干净和简单。
Much easier solution: Just create an initializer in config/initializers, e.g. delayed_job_config.rb
In your actual test you do not even need to know that delayed_job is deployed to send the mails, which keeps them clean and simple.
嗯,应该可以。我在我的应用程序中发现了一些错误配置。
检查你的测试环境。你应该设置:
我在railscast的邮件宏模块中添加了一行来处理Delayed::Job:
现在你可以检查:
你的最后一封电子邮件。
很容易!
附:如果您安装了很棒的
mail_safe
gem,您应该确保它不在测试环境中!well, it should work. i found some misconfigurations in my app.
check you test env. you should set:
i added a line in the mailer macros module from the railscast to work off the Delayed::Job:
now you can check with:
your last email.
pretty easy!
ps. if you have the awesome
mail_safe
gem installed you should make sure it's not in the test env.!