2016-03-08 44 views
1

我創建了一個自定義異常,當我達到Amazon SES的SimpleEmailService的最大發送速率時,我想要引發該異常。需要有關API沒什麼已知的,但這裏是試圖執行所發生的事情代碼:如何獲取此assert_raise斷言才能通過?

測試文件:

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

你需要有那將觸發內部的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 
+1

這樣做的伎倆。謝謝! –

+0

不客氣。 – smathy