2014-02-23 24 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 –