如何使用Rspec测试电子邮件发送?

mar*_*cgg 26 ruby tdd rspec ruby-on-rails

使用Rails使用rspec测试电子邮件发送的最佳实践和工具是什么?

例如,我如何测试已发送电子邮件或我应该测试什么以进行有效测试和可接受的覆盖范围.

如果你们需要一个例子,我将如何测试:

class UserMailer < ActionMailer::Base

 def jobdesc_has_been_reviewed(user, title)
    @body[:title]  = title
    @body[:jobdesc]  = jobdesc
    @body[:url]  = "http://" + user.account.subdomain + "." + Constants::SITE_URL + "/jobdescs/#{jobdesc.id}"
 end

end
Run Code Online (Sandbox Code Playgroud)

nic*_*des 24

email-spec看起来像一个很好的库

http://github.com/bmabey/email-spec