2014-02-23 27 views
0

導軌用於指導測試郵件程序的示例代碼如下:Rails指南測試郵件程序的示例?

require 'test_helper' 

class UserMailerTest < ActionMailer::TestCase 
    tests UserMailer 
    test "invite" do 
    # Send the email, then test that it got queued 
    email = UserMailer.create_invite('[email protected]', 
            '[email protected]', Time.now).deliver 
    assert !ActionMailer::Base.deliveries.empty? 

    # Test the body of the sent email contains what we expect it to 
    assert_equal ['[email protected]'], email.from 
    assert_equal ['[email protected]'], email.to 
    assert_equal 'You have been invited by [email protected]', email.subject 
    assert_equal read_fixture('invite').join, email.body.to_s 
    end 
end 

什麼是此行的目的和我必須將它添加在我的測試? - > 測試UserMailer

回答

1

請檢查tests method implementation

這裏是carlosantoniodasilva說什麼tests

您可以使用郵寄/控制器/傭工試驗測試,以確定 的郵件程序/控制器/助手正在測試,以防萬一不能從測試名稱中自動猜出 。例如,UserMailerTest 會自動猜測UserMailer作爲測試主題,但您可以明確地說或者說它是與測試 方法不同的名稱。因此,有線並非完全錯誤,只是 明確了Rails自動執行的操作。

您可以閱讀Github

+0

在這個非常特殊的話題的整個討論你是印度人? :-)我也是:-) –

+0

@ArupRakshit不,我是墨西哥人。開玩笑。 :) –

+0

哈哈:-)在某個時間後趕上你..愛印度在SO –