2012-06-08 36 views
5

Bazı postalayıcıları rspec ile test etmeye çalışıyorum ancak teslimatlar her zaman boş.ActionMailer :: Base.deliveries her zaman Rspec içinde boş

Benim send_welcome_email fonksiyonu şöyle
1) AccountMailer should send welcome email to account email 
    Failure/Error: ActionMailer::Base.deliveries.empty?.should be_false 
     expected true to be false 

(bu benim model):

def send_welcome_email 
    AccountMailer.welcome self 
end 

Ve postasının:

require "spec_helper" 

describe "AccountMailer", :type => :helper do 
    before(:each) do 
    ActionMailer::Base.delivery_method = :test 
    ActionMailer::Base.perform_deliveries = true 
    ActionMailer::Base.deliveries = [] 
    end 

    it "should send welcome email to account email" do 
    account = FactoryGirl.create :account 
    account.send_welcome_email 

    ActionMailer::Base.deliveries.empty?.should be_false 
    ActionMailer::Base.deliveries.last.to.should == account.email 
    end 
end 

Bu başarısız: İşte benim RSpec testtir

class AccountMailer < ActionMailer::Base 
    default from: APP_CONFIG['email']['from'] 

    def welcome data 
    if data.locale == 'es' 
     template = 'welcome-es' 
    else 
     template = 'welcome-en' 
    end 

    mail(:to => data.email, :subject => I18n.t('welcome_email_subject'), :template_name => template) 
    end 
end 

Herhangi bir fikir? Nasıl devam edeceğime emin değilim.

cevap

14

Uygulamayı çalıştırırken çalıştığını test ettiniz mi? Belki de sınavınız başarısız olmakta doğrudur.

Posta oluşturduğunuzda hiçbir zaman deliver numaralı telefonu aradığınızı fark ettim, bu nedenle e-posta aslında gönderilmediğinden testin başarısız olduğunu tahmin ediyorum. Senin send_welcome_email yönteminin daha fazla bir zaman kaydedildi sadece

def send_welcome_email 
    AccountMailer.welcome(self).deliver 
end 
+0

gibi daha fazla görünmesini beklerim. Bunun için teşekkürler! – MilesStanfield