在我的Rails应用程序中,注册类(Signup Class)具有以下功能:
def register_email
# Something...
add_to_other_thread do
send_verification_email
end
end
def add_to_other_thread(&block)
Thread.new do
yield
ActiveRecord::Base.connection.close
end
end
我希望对这些进行三项测试。
- add_to_other_thread(&block)的测试:
在调用add_to_other_thread并传入某个块后,检查是否使用正确的块调用了Thread.new。 - register_email的测试:
在调用register_email后,检查add_to_other_thread(&block)是否获得了正确的块。 - 整体测试:
用户注册后,通过其他线程检查是否已发送正确的电子邮件(通过ActionMailer::Base.deliveries)。