我创建了一个自定义异常,当我达到Amazon SES的SimpleEmailService最大发送速率时,我想要引发它。什么都不需要知道API,但这里是试图执行正在发生的事情的代码:
测试文件:
mailer_test.rb
it 'should not resend an email when ses limit has been reached' do
assert_raise Reverificaton::Process::SesMaxSendLimit do
Reverification::Process.expects(:ses_limit_reached?).returns(true)
end
AWS::SimpleEmailService.any_instance.expects(:send_email).never
Reverification::Mailer.resend_soft_bounced_notifications
end
这是我的代码文件:
process.rb
module Reverification
class Process
class SesMaxSendLimit < Exception; end
class << self
def send_email
raise SesMaxSendLimit if ses_limit_reached?
end
end
end
end
我收到的错误是没有引发异常
Reverification::Process::SesMaxSendLimit expected but nothing was raised.
为什么不提出例外?我已经嘲笑ses_limit_reached?
返回true
,我确定我的范围是正确的。有什么问题?
答案 0 :(得分:0)
您需要让代码触发{strong> assert_raise
块中的异常。我假设这是你在阻止之后的两个陈述,所以不是你拥有的,(我认为)你应该拥有这个:
it 'should not resend an email when ses limit has been reached' do
assert_raise Reverificaton::Process::SesMaxSendLimit do
Reverification::Process.expects(:ses_limit_reached?).returns(true)
AWS::SimpleEmailService.any_instance.expects(:send_email).never
Reverification::Mailer.resend_soft_bounced_notifications
end
end