Forum: Ruby on Rails testing to see if emails are sent out on exceptions

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
38a8230ed3d5c685558b4f0aad3fc74b?d=identicon&s=25 Joe Van Dyk (Guest)
on 2006-02-03 05:23
(Received via mailing list)
Hi,

I'm using ActionController::rescue_action_in_public() to send emails
when uncaught exceptions happen.

Is it possible to write tests for that?

Joe
3ccecc71b9fb0a3d7f00a0bef6f0a63a?d=identicon&s=25 Kent Sibilev (Guest)
on 2006-02-03 07:33
(Received via mailing list)
Something like:

file system_notifier_test.rb:

require File.dirname(__FILE__) + '/../test_helper'
require 'application'

class SystemNotifierTest < Test::Unit::TestCase
  class MyController < ApplicationController
    def anaction
      raise 'Action Exception'
    end

    def local_request?
      false
    end

    alias consider_all_requests_local local_request?
  end

  def setup
    @emails = ActionMailer::Base.deliveries
    @emails.clear

    @controller = MyController.new
    @request = ActionController::TestRequest.new
    @response = ActionController::TestResponse.new
  end

  def test_exception_notification
    get :anaction
    assert_match /^A RuntimeError occured in/, @emails.first.body
  end
end

Kent.
38a8230ed3d5c685558b4f0aad3fc74b?d=identicon&s=25 Joe Van Dyk (Guest)
on 2006-02-03 08:55
(Received via mailing list)
On 2/2/06, Kent Sibilev <ksruby@gmail.com> wrote:
>       raise 'Action Exception'
>     @emails = ActionMailer::Base.deliveries
>   end
> end

That's brilliant.  Thanks.

Joe
This topic is locked and can not be replied to.