2011-09-22 106 views
3

如何在ActionMailer規範中測試這些行?在Rails中測試默認設置ActionMailer

default 'HEADER' => Proc.new { "information" }, 
    :cc => "[email protected]", 
    :from => "[email protected]", 
    :to => "[email protected]" 
+0

我不擔心測試默認標題和電子郵件字段,我會檢查actionmailer測試覆蓋這些。如果你正在添加頭文件,我認爲你可以在控制器測試中檢查頭文件哈希,或者你可以在'--head'中使用curl並檢查原始輸出。 –

回答

1

類似的東西:

# notifier_spec.rb 
require "spec_helper" 

describe Notifier do 
    describe "welcome" do 
    let(:user) { Factory :user } 
    let(:mail) { Notifier.welcome(user) } 

    it "renders the headers" do 
     mail.content_type.should eq('text/plain; charset=UTF-8') 
     mail.subject.should eq("Welcome") 
     mail.cc.should eq(["[email protected]"]) 
     mail.from.should eq(["[email protected]"]) 
     mail.to.should eq([user.email]) 
    end 

    it "renders the body" do 
     mail.body.encoded.should match("Hi") 
    end 
    end 
end 

這是Ryan Bates(=全buncha人)是如何做的。