2012-03-15 30 views
1

我教的是,隨着像我config/environments/test.rbdelivery_method = :test的選項,同時運行我的Rspec的測試中,我應該不會收到任何郵件:爲什麼我的Rspec的測試實時發送郵件?

配置/環境/ test.rb:

config.action_mailer.delivery_method = :test 

但在我測試,當我使用FactoryGirl創建用戶並且用戶有發送註冊通知的回撥時,將發送此電子郵件:

myspec.rb:

user = FactoryGirl.create(:user, :login => 'johndoe') 

user_observer.rb:

class UserObserver < ActiveRecord::Observer 
    def after_create(user) 
    UserMailer.signup_notification(user).deliver 
    end 
end 

action_mailer.rb:

ActionMailer::Base.delivery_method = :smtp 

ActionMailer::Base.smtp_settings = { 
    :address => "...", 
    :port => "25", 
    :domain => "...", 
    :user_name => "...", 
    :password => "...", 
    :authentication => :plain 
} 

什麼可能是錯誤的?

我使用:

  • 的Rails 3.2.2
  • 的buildin的ActionMailer
  • RSpec的擺幅
  • FactoryGirl
  • 衛隊
+0

難道說,這'的ActionMailer :: Base.delivery_method =:smtp'口罩我在'環境/ test.rb'配置? – DiegoFrings 2012-03-15 15:43:29

回答

0

是的,你是對的。的ActionMailer :: Base.delivery_method =:SMTP口罩環境/ test.rb配置

我建議你下一個解決方案:創建爲每個範圍的具體數據夾具。
enter link description here
在我的情況是這樣的:

我config.yml

development: 
     support_mail: [email protected] 
     smtp_user_name: [email protected] 
     smtp_password: test 
     smtp_domain: test.test 
     smtp_address: test.test.test 
     smtp_port: => 999 

    test: 
     support_mail: [email protected] 
     smtp_user_name: [email protected] 
     smtp_password: test 
     smtp_domain: test.test 
     smtp_address: test.test.test 
     smtp_port: => 999 

    production: 
     support_mail: [email protected] 
     smtp_user_name: [email protected] 
     smtp_password: somth 
     smtp_domain: somth.com 
     smtp_address: smtp.somth.com 
     smtp_port: => 587 

我的environment.rb

# Load the rails application 
require File.expand_path('../application', __FILE__) 
#initialize custom config variables 
APP_CONFIG = YAML.load_file("#{Rails.root}/config/config.yml")[Rails.env] 
    ActionMailer::Base.smtp_settings = { 
     :user_name => APP_CONFIG["smtp_user_name"], #ENV['SENDGRID_USERNAME'], 
     :password => APP_CONFIG["smtp_password"], # ENV['SENDGRID_PASSWORD'], 
     :domain => APP_CONFIG["smtp_domain"], 
     :address => APP_CONFIG["smtp_address"], 
     :port => APP_CONFIG["smtp_port"], 
     :authentication => :plain, 
     :enable_starttls_auto => false 
    } 
ActionMailer::Base.delivery_method = :smtp 
+0

所以'的ActionMailer :: Base.delivery_method'是罪犯。我已經使用範圍特定的配置(通過SettingsLogic)。 – DiegoFrings 2012-03-16 08:06:37

相關問題