Tom Rossi
Tom Rossi

Reputation: 12066

How do you stub an SMTP error for ActionMailer::DeliveryJob

What is the proper way to stub an SMTP error to test your discard_on or retry_on for your ActionMailer::DeliveryJob methods?

Upvotes: 1

Views: 231

Answers (1)

Tom Rossi
Tom Rossi

Reputation: 12066

I couldn't find any examples, but this is the best I could come up with:

  test 'capture an SMTP exception' do
    email = MyMailer.with(params).my_message
    Mail::Message.any_instance.stubs(:deliver).raises(Net::SMTPSyntaxError)
    job = email.deliver_later
    job.perform_now
    assert_equal 1, job.executions
  end

Upvotes: 2

Related Questions