2012-03-15 28 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

相关问题