[英]Using Resque and resque_mailer to send emails raises Routing error
[英]How to write tests for emails using ActionMailer and resque_mailer in Rails
我正在作为Rails控制器操作的一部分发送邮件,并且正在使用ActionMailer以及Resque :: Mailer。
我使用什么后台作业库(已经使用Resque做其他事情)并不重要,但是我如何编写集成请求规范以发出应该触发这些电子邮件的请求?
还是我可以编写其他测试?
我不确定100%是否能正确理解您的问题,但我相信您可以使用should_receive和email-spec来测试是否在特定控制器中发送了电子邮件以及这些电子邮件的内容。
例:
describe "POST /signup (#signup)" do
it "should deliver the signup email" do
# expect
UserMailer.should_receive(:deliver_signup).with("email@example.com", "Jimmy Bean")
# when
post :signup, "Email" => "email@example.com", "Name" => "Jimmy Bean"
end
end
范例2:
describe "Signup Email" do
include EmailSpec::Helpers
include EmailSpec::Matchers
# include ActionController::UrlWriter - old rails
include Rails.application.routes.url_helpers
before(:all) do
@email = UserMailer.create_signup("jojo@yahoo.com", "Jojo Binks")
end
it "should be set to be delivered to the email passed in" do
@email.should deliver_to("jojo@yahoo.com")
end
it "should contain the user's message in the mail body" do
@email.should have_body_text(/Jojo Binks/)
end
it "should contain a link to the confirmation link" do
@email.should have_body_text(/#{confirm_account_url}/)
end
it "should have the correct subject" do
@email.should have_subject(/Account confirmation/)
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.