我正在写一些rspec测试,我注意到它在访问我的Mailer类时变慢了。有没有办法完全模拟出ActionMailer::Base类,这样我就可以在发送电子邮件之前和之后测试我的控制器的其他组件?
下面是我的mailer类定义
class OrganisationMailer < ActionMailer::Base
# code to send emails
end下面是我写的一个测试
require 'spec_helper'
describe OrganisationsController do
describe "#email_single" do
context "With email address" do
let(:org) {Organisation.make!}
it "redirects to listing" do
get :email_single, :id => org.id
response.should redirect_to(organisations_path)
end
end
end
end发布于 2012-12-30 15:34:22
这很难用您包含的小代码片段来回答,但是您应该能够清除控制器发送给OrganisationMailer的任何消息,以便它们在rspec示例中是无操作的,而您并不关心执行该逻辑。
或者,您可以考虑使用stub_const将OrganisationMailer替换为测试替身
stub_const("OrganisationMailer", my_test_double)然后,您可以完全控制控制器和邮件程序之间的交互。
https://stackoverflow.com/questions/14078946
复制相似问题