5

現在、私のローカル開発環境は、実際のメールを送信できるようにセットアップされています。このため、配達が行われており、ActionMailer::Base.deliveriesテーブルには何も保持されていません。cucumber テストでメール送信を無効にすることはできますか? もしそうなら、これを行うための構文は何ですか? または、送信されている電子メールをテストするより良い方法はありますか?

authentication_steps.rb:

Then /^I should receive a confirmation email$/ do
  email = ActionMailer::Base.deliveries.last
  email.subject.should == "Welcome to our website!"
end

app/config/development.rb

  ...
  # Don't care if the mailer can't send
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.perform_deliveries    = true

  # Setup for local testing of emails using gmail test account
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {  :address => 'smtp.sendgrid.net',
                                           :port => 587,
                                           :domain => ENV['MAIL_DOMAIN'],
                                           :authentication => 'plain',
                                           :enable_starttls_auto => true,
                                           :user_name => ENV['MAIL_USERNAME'],
                                           :password => ENV['MAIL_PASSWORD']
                                           }
  ...

ありがとう

4

1 に答える 1

10
 config.action_mailer.delivery_method = :test

また

テスト直前

ActionMailer::Base.delivery_method = :test
于 2012-05-15T21:44:57.703 に答える