我有一个create
看起来UsersController
像这样的动作
def create
@user = User.new(params[:user])
if @user.save
sign_in_as(@user)
Resque.enqueue(MailWorker, @user.email)
redirect_to root_url, notice: "Thanks"
else
render "new"
end
end
在添加reqsue
到此操作之前,我一直在测试这样的电子邮件确认
it "creates a new user account" do
# code for creating a new account...
ActionMailer::Base.deliveries.size.should == 1
mail = ActionMailer::Base.deliveries.last
mail.to.should == [user[:email]]
mail.body.encoded.should match(/Thank you for registration/)
end
但是现在,由于我添加了 resque worker 来传递消息,我猜它不会立即传递消息,因此我得到这个测试失败并显示消息
Failure/Error: ActionMailer::Base.deliveries.size.should == 1
expected: 1
got: 0 (using ==)
当涉及异步工作人员并且结果取决于它们时,我该如何测试这种情况?